Skip to content

Commit

Permalink
Add tests for authToken overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Tammo Ippen authored and tammoippen committed Feb 10, 2025
1 parent 10b9c84 commit 0b82e18
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions packages/api-graphql/__tests__/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ describe('Events client', () => {
expect.objectContaining({ authenticationType: authMode }),
);
});

test(`auth token override: ${authMode}`, async () => {
await events.connect('/', { authMode, authToken: 'TOKEN' });

expect(mockProvider.connect).toHaveBeenCalledWith(
expect.objectContaining({
authenticationType: authMode,
authToken: 'TOKEN',
}),
);
});
}
});
});
Expand Down Expand Up @@ -169,6 +180,63 @@ describe('Events client', () => {
expect.objectContaining({ authenticationType: authMode }),
);
});

test(`auth token override from connect: ${authMode}`, async () => {
const channel = await events.connect('/', { authToken: 'TOKEN' });

channel.subscribe(
{
next: data => void data,
error: error => void error,
},
{ authMode },
);

expect(mockSubscribeObservable).toHaveBeenCalledWith(
expect.objectContaining({
authenticationType: authMode,
authToken: 'TOKEN',
}),
);
});

test(`auth token override: ${authMode}`, async () => {
const channel = await events.connect('/');

channel.subscribe(
{
next: data => void data,
error: error => void error,
},
{ authMode, authToken: 'TOKEN' },
);

expect(mockSubscribeObservable).toHaveBeenCalledWith(
expect.objectContaining({
authenticationType: authMode,
authToken: 'TOKEN',
}),
);
});

test(`auth token override subscribe has precedence: ${authMode}`, async () => {
const channel = await events.connect('/', { authToken: 'TOKEN1' });

channel.subscribe(
{
next: data => void data,
error: error => void error,
},
{ authMode, authToken: 'TOKEN2' },
);

expect(mockSubscribeObservable).toHaveBeenCalledWith(
expect.objectContaining({
authenticationType: authMode,
authToken: 'TOKEN2',
}),
);
});
}
});
});
Expand Down

0 comments on commit 0b82e18

Please sign in to comment.