Skip to content

Commit d968880

Browse files
authored
Update tests to check for search params (#973)
## Description While we check list parameters for being correctly serialized in user management and directory sync, we were missing some checks in the SSO and Events ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
1 parent 40ba433 commit d968880

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/events/events.spec.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'jest-fetch-mock';
2-
import { fetchOnce } from '../common/utils/test-utils';
2+
import { fetchOnce, fetchSearchParams } from '../common/utils/test-utils';
33
import { Event, EventResponse, ListResponse } from '../common/interfaces';
44
import { WorkOS } from '../workos';
55
import { ConnectionType } from '../sso/interfaces';
@@ -50,11 +50,43 @@ describe('Event', () => {
5050
data: [eventResponse],
5151
list_metadata: {},
5252
};
53+
describe('with options', () => {
54+
it('requests Events with query parameters', async () => {
55+
const eventsResponse: ListResponse<EventResponse> = {
56+
object: 'list',
57+
data: [eventResponse],
58+
list_metadata: {},
59+
};
60+
61+
fetchOnce(eventsResponse);
62+
63+
const list = await workos.events.listEvents({
64+
events: ['connection.activated'],
65+
rangeStart: '2020-05-04',
66+
rangeEnd: '2020-05-07',
67+
});
68+
69+
expect(fetchSearchParams()).toMatchObject({
70+
events: 'connection.activated',
71+
range_start: '2020-05-04',
72+
range_end: '2020-05-07',
73+
});
74+
75+
expect(list).toEqual({
76+
object: 'list',
77+
data: [event],
78+
listMetadata: {},
79+
});
80+
});
81+
});
5382

5483
it(`requests Events`, async () => {
5584
fetchOnce(eventsListResponse);
5685

57-
const subject = await workos.events.listEvents({});
86+
const subject = await workos.events.listEvents({
87+
rangeStart: '2020-05-05',
88+
rangeEnd: '2020-05-07',
89+
});
5890

5991
expect(subject).toEqual({
6092
object: 'list',

src/sso/sso.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import {
44
fetchURL,
55
fetchHeaders,
66
fetchBody,
7+
fetchSearchParams,
78
} from '../common/utils/test-utils';
89

910
import { WorkOS } from '../workos';
1011
import { ConnectionResponse, ConnectionType } from './interfaces';
12+
import { ListResponse } from '../common/interfaces';
1113

1214
describe('SSO', () => {
1315
beforeEach(() => fetch.resetMocks());
@@ -25,6 +27,29 @@ describe('SSO', () => {
2527
};
2628

2729
describe('SSO', () => {
30+
describe('with options', () => {
31+
it('requests Connections with query parameters', async () => {
32+
const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
33+
const listConnectionsResponse: ListResponse<ConnectionResponse> = {
34+
object: 'list',
35+
data: [connectionResponse],
36+
list_metadata: {},
37+
};
38+
39+
fetchOnce(listConnectionsResponse);
40+
41+
await workos.sso.listConnections({
42+
connectionType: ConnectionType.OktaSAML,
43+
organizationId: 'org_123',
44+
});
45+
46+
expect(fetchSearchParams()).toMatchObject({
47+
connection_type: ConnectionType.OktaSAML,
48+
organization_id: 'org_123',
49+
});
50+
});
51+
});
52+
2853
describe('getAuthorizationUrl', () => {
2954
describe('with no custom api hostname', () => {
3055
it('generates an authorize url with the default api hostname', () => {

0 commit comments

Comments
 (0)