@workos-inc/node 5.2.0 → 6.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,12 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
15
+ const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
16
+ const test_utils_1 = require("../common/utils/test-utils");
17
17
  const exceptions_1 = require("../common/exceptions");
18
18
  const workos_1 = require("../workos");
19
- const mock = new axios_mock_adapter_1.default(axios_1.default);
20
19
  describe('MFA', () => {
20
+ beforeEach(() => jest_fetch_mock_1.default.resetMocks());
21
21
  describe('getFactor', () => {
22
22
  it('returns the requested factor', () => __awaiter(void 0, void 0, void 0, function* () {
23
23
  const factor = {
@@ -42,7 +42,7 @@ describe('MFA', () => {
42
42
  user: 'some_user',
43
43
  },
44
44
  };
45
- mock.onGet().reply(200, factorResponse);
45
+ (0, test_utils_1.fetchOnce)(factorResponse);
46
46
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
47
47
  const subject = yield workos.mfa.getFactor('test_123');
48
48
  expect(subject).toEqual(factor);
@@ -50,10 +50,10 @@ describe('MFA', () => {
50
50
  });
51
51
  describe('deleteFactor', () => {
52
52
  it('sends request to delete a Factor', () => __awaiter(void 0, void 0, void 0, function* () {
53
- mock.onDelete().reply(200, {});
53
+ (0, test_utils_1.fetchOnce)();
54
54
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
55
55
  yield workos.mfa.deleteFactor('conn_123');
56
- expect(mock.history.delete[0].url).toEqual('/auth/factors/conn_123');
56
+ expect((0, test_utils_1.fetchURL)()).toContain('/auth/factors/conn_123');
57
57
  }));
58
58
  });
59
59
  describe('enrollFactor', () => {
@@ -73,7 +73,7 @@ describe('MFA', () => {
73
73
  updated_at: '2022-03-15T20:39:19.892Z',
74
74
  type: 'generic_otp',
75
75
  };
76
- mock.onPost('/auth/factors/enroll').reply(200, factorResponse);
76
+ (0, test_utils_1.fetchOnce)(factorResponse);
77
77
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
78
78
  apiHostname: 'api.workos.dev',
79
79
  });
@@ -113,7 +113,7 @@ describe('MFA', () => {
113
113
  user: 'some_user',
114
114
  },
115
115
  };
116
- mock.onPost('/auth/factors/enroll').reply(200, factorResponse);
116
+ (0, test_utils_1.fetchOnce)(factorResponse);
117
117
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
118
118
  apiHostname: 'api.workos.dev',
119
119
  });
@@ -147,7 +147,7 @@ describe('MFA', () => {
147
147
  phone_number: '+15555555555',
148
148
  },
149
149
  };
150
- mock.onPost('/auth/factors/enroll').reply(200, factorResponse);
150
+ (0, test_utils_1.fetchOnce)(factorResponse);
151
151
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
152
152
  apiHostname: 'api.workos.dev',
153
153
  });
@@ -159,11 +159,12 @@ describe('MFA', () => {
159
159
  }));
160
160
  describe('when phone number is invalid', () => {
161
161
  it('throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
162
- mock.onPost('/auth/factors/enroll').reply(422, {
162
+ (0, test_utils_1.fetchOnce)({
163
163
  message: `Phone number is invalid: 'foo'`,
164
164
  code: 'invalid_phone_number',
165
165
  }, {
166
- 'X-Request-ID': 'req_123',
166
+ status: 422,
167
+ headers: { 'X-Request-ID': 'req_123' },
167
168
  });
168
169
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
169
170
  apiHostname: 'api.workos.dev',
@@ -197,9 +198,7 @@ describe('MFA', () => {
197
198
  code: '12345',
198
199
  authentication_factor_id: 'auth_factor_1234',
199
200
  };
200
- mock
201
- .onPost('/auth/factors/auth_factor_1234/challenge')
202
- .reply(200, challengeResponse);
201
+ (0, test_utils_1.fetchOnce)(challengeResponse);
203
202
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
204
203
  apiHostname: 'api.workos.dev',
205
204
  });
@@ -229,11 +228,7 @@ describe('MFA', () => {
229
228
  code: '12345',
230
229
  authentication_factor_id: 'auth_factor_1234',
231
230
  };
232
- mock
233
- .onPost('/auth/factors/auth_factor_1234/challenge', {
234
- sms_template: 'This is your code: 12345',
235
- })
236
- .reply(200, challengeResponse);
231
+ (0, test_utils_1.fetchOnce)(challengeResponse);
237
232
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
238
233
  apiHostname: 'api.workos.dev',
239
234
  });
@@ -241,6 +236,9 @@ describe('MFA', () => {
241
236
  authenticationFactorId: 'auth_factor_1234',
242
237
  smsTemplate: 'This is your code: 12345',
243
238
  });
239
+ expect((0, test_utils_1.fetchBody)()).toEqual({
240
+ sms_template: 'This is your code: 12345',
241
+ });
244
242
  expect(subject).toEqual(challenge);
245
243
  }));
246
244
  });
@@ -272,11 +270,7 @@ describe('MFA', () => {
272
270
  },
273
271
  valid: true,
274
272
  };
275
- mock
276
- .onPost('/auth/challenges/auth_challenge_1234/verify', {
277
- code: '12345',
278
- })
279
- .reply(200, verifyResponseResponse);
273
+ (0, test_utils_1.fetchOnce)(verifyResponseResponse);
280
274
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
281
275
  apiHostname: 'api.workos.dev',
282
276
  });
@@ -284,20 +278,20 @@ describe('MFA', () => {
284
278
  authenticationChallengeId: 'auth_challenge_1234',
285
279
  code: '12345',
286
280
  });
281
+ expect((0, test_utils_1.fetchBody)()).toEqual({
282
+ code: '12345',
283
+ });
287
284
  expect(subject).toEqual(verifyResponse);
288
285
  }));
289
286
  });
290
287
  describe('when the challenge has been previously verified', () => {
291
288
  it('throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
292
- mock
293
- .onPost('/auth/challenges/auth_challenge_1234/verify', {
294
- code: '12345',
295
- })
296
- .reply(422, {
289
+ (0, test_utils_1.fetchOnce)({
297
290
  message: `The authentication challenge '12345' has already been verified.`,
298
291
  code: 'authentication_challenge_previously_verified',
299
292
  }, {
300
- 'X-Request-ID': 'req_123',
293
+ status: 422,
294
+ headers: { 'X-Request-ID': 'req_123' },
301
295
  });
302
296
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
303
297
  apiHostname: 'api.workos.dev',
@@ -306,19 +300,19 @@ describe('MFA', () => {
306
300
  authenticationChallengeId: 'auth_challenge_1234',
307
301
  code: '12345',
308
302
  })).rejects.toThrow(exceptions_1.UnprocessableEntityException);
303
+ expect((0, test_utils_1.fetchBody)()).toEqual({
304
+ code: '12345',
305
+ });
309
306
  }));
310
307
  });
311
308
  describe('when the challenge has expired', () => {
312
309
  it('throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
313
- mock
314
- .onPost('/auth/challenges/auth_challenge_1234/verify', {
315
- code: '12345',
316
- })
317
- .reply(422, {
310
+ (0, test_utils_1.fetchOnce)({
318
311
  message: `The authentication challenge '12345' has expired.`,
319
312
  code: 'authentication_challenge_expired',
320
313
  }, {
321
- 'X-Request-ID': 'req_123',
314
+ status: 422,
315
+ headers: { 'X-Request-ID': 'req_123' },
322
316
  });
323
317
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
324
318
  apiHostname: 'api.workos.dev',
@@ -327,17 +321,17 @@ describe('MFA', () => {
327
321
  authenticationChallengeId: 'auth_challenge_1234',
328
322
  code: '12345',
329
323
  })).rejects.toThrow(exceptions_1.UnprocessableEntityException);
324
+ expect((0, test_utils_1.fetchBody)()).toEqual({
325
+ code: '12345',
326
+ });
330
327
  }));
331
328
  it('exception has code', () => __awaiter(void 0, void 0, void 0, function* () {
332
- mock
333
- .onPost('/auth/challenges/auth_challenge_1234/verify', {
334
- code: '12345',
335
- })
336
- .reply(422, {
329
+ (0, test_utils_1.fetchOnce)({
337
330
  message: `The authentication challenge '12345' has expired.`,
338
331
  code: 'authentication_challenge_expired',
339
332
  }, {
340
- 'X-Request-ID': 'req_123',
333
+ status: 422,
334
+ headers: { 'X-Request-ID': 'req_123' },
341
335
  });
342
336
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
343
337
  apiHostname: 'api.workos.dev',
@@ -353,6 +347,9 @@ describe('MFA', () => {
353
347
  code: 'authentication_challenge_expired',
354
348
  });
355
349
  }
350
+ expect((0, test_utils_1.fetchBody)()).toEqual({
351
+ code: '12345',
352
+ });
356
353
  }));
357
354
  });
358
355
  });
@@ -12,23 +12,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
15
+ const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
16
+ const test_utils_1 = require("../common/utils/test-utils");
17
17
  const workos_1 = require("../workos");
18
18
  const get_organization_domain_pending_json_1 = __importDefault(require("./fixtures/get-organization-domain-pending.json"));
19
19
  const get_organization_domain_verified_json_1 = __importDefault(require("./fixtures/get-organization-domain-verified.json"));
20
20
  const interfaces_1 = require("./interfaces");
21
- const mock = new axios_mock_adapter_1.default(axios_1.default);
22
21
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
23
22
  describe('OrganizationDomains', () => {
24
- afterEach(() => mock.resetHistory());
23
+ beforeEach(() => jest_fetch_mock_1.default.resetMocks());
25
24
  describe('get', () => {
26
25
  it('requests an Organization Domain', () => __awaiter(void 0, void 0, void 0, function* () {
27
- mock
28
- .onGet('/organization_domains/org_domain_01HCZRAP3TPQ0X0DKJHR32TATG')
29
- .replyOnce(200, get_organization_domain_verified_json_1.default);
26
+ (0, test_utils_1.fetchOnce)(get_organization_domain_verified_json_1.default);
30
27
  const subject = yield workos.organizationDomains.get('org_domain_01HCZRAP3TPQ0X0DKJHR32TATG');
31
- expect(mock.history.get[0].url).toEqual('/organization_domains/org_domain_01HCZRAP3TPQ0X0DKJHR32TATG');
28
+ expect((0, test_utils_1.fetchURL)()).toContain('/organization_domains/org_domain_01HCZRAP3TPQ0X0DKJHR32TATG');
32
29
  expect(subject.id).toEqual('org_domain_01HCZRAP3TPQ0X0DKJHR32TATG');
33
30
  expect(subject.domain).toEqual('workos.com');
34
31
  expect(subject.state).toEqual(interfaces_1.OrganizationDomainState.Verified);
@@ -36,11 +33,9 @@ describe('OrganizationDomains', () => {
36
33
  expect(subject.verificationStrategy).toEqual('manual');
37
34
  }));
38
35
  it('requests an Organization Domain', () => __awaiter(void 0, void 0, void 0, function* () {
39
- mock
40
- .onGet('/organization_domains/org_domain_01HD50K7EPWCMNPGMKXKKE14XT')
41
- .replyOnce(200, get_organization_domain_pending_json_1.default);
36
+ (0, test_utils_1.fetchOnce)(get_organization_domain_pending_json_1.default);
42
37
  const subject = yield workos.organizationDomains.get('org_domain_01HD50K7EPWCMNPGMKXKKE14XT');
43
- expect(mock.history.get[0].url).toEqual('/organization_domains/org_domain_01HD50K7EPWCMNPGMKXKKE14XT');
38
+ expect((0, test_utils_1.fetchURL)()).toContain('/organization_domains/org_domain_01HD50K7EPWCMNPGMKXKKE14XT');
44
39
  expect(subject.id).toEqual('org_domain_01HD50K7EPWCMNPGMKXKKE14XT');
45
40
  expect(subject.domain).toEqual('workos.com');
46
41
  expect(subject.state).toEqual(interfaces_1.OrganizationDomainState.Pending);
@@ -50,11 +45,9 @@ describe('OrganizationDomains', () => {
50
45
  });
51
46
  describe('verify', () => {
52
47
  it('start Organization Domain verification flow', () => __awaiter(void 0, void 0, void 0, function* () {
53
- mock
54
- .onPost('/organization_domains/org_domain_01HD50K7EPWCMNPGMKXKKE14XT/verify')
55
- .replyOnce(200, get_organization_domain_pending_json_1.default);
48
+ (0, test_utils_1.fetchOnce)(get_organization_domain_pending_json_1.default);
56
49
  const subject = yield workos.organizationDomains.verify('org_domain_01HD50K7EPWCMNPGMKXKKE14XT');
57
- expect(mock.history.post[0].url).toEqual('/organization_domains/org_domain_01HD50K7EPWCMNPGMKXKKE14XT/verify');
50
+ expect((0, test_utils_1.fetchURL)()).toContain('/organization_domains/org_domain_01HD50K7EPWCMNPGMKXKKE14XT/verify');
58
51
  expect(subject.id).toEqual('org_domain_01HD50K7EPWCMNPGMKXKKE14XT');
59
52
  expect(subject.domain).toEqual('workos.com');
60
53
  expect(subject.state).toEqual(interfaces_1.OrganizationDomainState.Pending);
@@ -64,18 +57,13 @@ describe('OrganizationDomains', () => {
64
57
  });
65
58
  describe('create', () => {
66
59
  it('creates an Organization Domain', () => __awaiter(void 0, void 0, void 0, function* () {
67
- mock
68
- .onPost('/organization_domains', {
69
- domain: 'workos.com',
70
- organization_id: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
71
- })
72
- .replyOnce(200, get_organization_domain_pending_json_1.default);
60
+ (0, test_utils_1.fetchOnce)(get_organization_domain_pending_json_1.default);
73
61
  const subject = yield workos.organizationDomains.create({
74
62
  organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
75
63
  domain: 'workos.com',
76
64
  });
77
- expect(mock.history.post[0].url).toEqual('/organization_domains');
78
- expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
65
+ expect((0, test_utils_1.fetchURL)()).toContain('/organization_domains');
66
+ expect((0, test_utils_1.fetchBody)()).toEqual({
79
67
  domain: 'workos.com',
80
68
  organization_id: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
81
69
  });
@@ -12,27 +12,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
15
+ const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
16
+ const test_utils_1 = require("../common/utils/test-utils");
17
17
  const workos_1 = require("../workos");
18
18
  const create_organization_invalid_json_1 = __importDefault(require("./fixtures/create-organization-invalid.json"));
19
19
  const create_organization_json_1 = __importDefault(require("./fixtures/create-organization.json"));
20
20
  const get_organization_json_1 = __importDefault(require("./fixtures/get-organization.json"));
21
21
  const list_organizations_json_1 = __importDefault(require("./fixtures/list-organizations.json"));
22
22
  const update_organization_json_1 = __importDefault(require("./fixtures/update-organization.json"));
23
- const mock = new axios_mock_adapter_1.default(axios_1.default);
24
23
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
25
24
  describe('Organizations', () => {
26
- afterEach(() => mock.resetHistory());
25
+ beforeEach(() => jest_fetch_mock_1.default.resetMocks());
27
26
  describe('listOrganizations', () => {
28
27
  describe('without any options', () => {
29
28
  it('returns organizations and metadata', () => __awaiter(void 0, void 0, void 0, function* () {
30
- mock.onGet('/organizations').replyOnce(200, list_organizations_json_1.default);
29
+ (0, test_utils_1.fetchOnce)(list_organizations_json_1.default);
31
30
  const { data, listMetadata } = yield workos.organizations.listOrganizations();
32
- expect(mock.history.get[0].params).toEqual({
31
+ expect((0, test_utils_1.fetchSearchParams)()).toEqual({
33
32
  order: 'desc',
34
33
  });
35
- expect(mock.history.get[0].url).toEqual('/organizations');
34
+ expect((0, test_utils_1.fetchURL)()).toContain('/organizations');
36
35
  expect(data).toHaveLength(7);
37
36
  expect(listMetadata).toEqual({
38
37
  after: null,
@@ -42,73 +41,57 @@ describe('Organizations', () => {
42
41
  });
43
42
  describe('with the domain option', () => {
44
43
  it('forms the proper request to the API', () => __awaiter(void 0, void 0, void 0, function* () {
45
- mock
46
- .onGet('/organizations', {
47
- domains: ['example.com'],
48
- })
49
- .replyOnce(200, list_organizations_json_1.default);
44
+ (0, test_utils_1.fetchOnce)(list_organizations_json_1.default);
50
45
  const { data } = yield workos.organizations.listOrganizations({
51
- domains: ['example.com'],
46
+ domains: ['example.com', 'example2.com'],
52
47
  });
53
- expect(mock.history.get[0].params).toEqual({
54
- domains: ['example.com'],
48
+ expect((0, test_utils_1.fetchSearchParams)()).toEqual({
49
+ domains: 'example.com,example2.com',
55
50
  order: 'desc',
56
51
  });
57
- expect(mock.history.get[0].url).toEqual('/organizations');
52
+ expect((0, test_utils_1.fetchURL)()).toContain('/organizations');
58
53
  expect(data).toHaveLength(7);
59
54
  }));
60
55
  });
61
56
  describe('with the before option', () => {
62
57
  it('forms the proper request to the API', () => __awaiter(void 0, void 0, void 0, function* () {
63
- mock
64
- .onGet('/organizations', {
65
- before: 'before-id',
66
- })
67
- .replyOnce(200, list_organizations_json_1.default);
58
+ (0, test_utils_1.fetchOnce)(list_organizations_json_1.default);
68
59
  const { data } = yield workos.organizations.listOrganizations({
69
60
  before: 'before-id',
70
61
  });
71
- expect(mock.history.get[0].params).toEqual({
62
+ expect((0, test_utils_1.fetchSearchParams)()).toEqual({
72
63
  before: 'before-id',
73
64
  order: 'desc',
74
65
  });
75
- expect(mock.history.get[0].url).toEqual('/organizations');
66
+ expect((0, test_utils_1.fetchURL)()).toContain('/organizations');
76
67
  expect(data).toHaveLength(7);
77
68
  }));
78
69
  });
79
70
  describe('with the after option', () => {
80
71
  it('forms the proper request to the API', () => __awaiter(void 0, void 0, void 0, function* () {
81
- mock
82
- .onGet('/organizations', {
83
- after: 'after-id',
84
- })
85
- .replyOnce(200, list_organizations_json_1.default);
72
+ (0, test_utils_1.fetchOnce)(list_organizations_json_1.default);
86
73
  const { data } = yield workos.organizations.listOrganizations({
87
74
  after: 'after-id',
88
75
  });
89
- expect(mock.history.get[0].params).toEqual({
76
+ expect((0, test_utils_1.fetchSearchParams)()).toEqual({
90
77
  after: 'after-id',
91
78
  order: 'desc',
92
79
  });
93
- expect(mock.history.get[0].url).toEqual('/organizations');
80
+ expect((0, test_utils_1.fetchURL)()).toContain('/organizations');
94
81
  expect(data).toHaveLength(7);
95
82
  }));
96
83
  });
97
84
  describe('with the limit option', () => {
98
85
  it('forms the proper request to the API', () => __awaiter(void 0, void 0, void 0, function* () {
99
- mock
100
- .onGet('/organizations', {
101
- limit: 10,
102
- })
103
- .replyOnce(200, list_organizations_json_1.default);
86
+ (0, test_utils_1.fetchOnce)(list_organizations_json_1.default);
104
87
  const { data } = yield workos.organizations.listOrganizations({
105
88
  limit: 10,
106
89
  });
107
- expect(mock.history.get[0].params).toEqual({
108
- limit: 10,
90
+ expect((0, test_utils_1.fetchSearchParams)()).toEqual({
91
+ limit: '10',
109
92
  order: 'desc',
110
93
  });
111
- expect(mock.history.get[0].url).toEqual('/organizations');
94
+ expect((0, test_utils_1.fetchURL)()).toContain('/organizations');
112
95
  expect(data).toHaveLength(7);
113
96
  }));
114
97
  });
@@ -116,31 +99,30 @@ describe('Organizations', () => {
116
99
  describe('createOrganization', () => {
117
100
  describe('with an idempotency key', () => {
118
101
  it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
119
- var _a;
120
- mock
121
- .onPost('/organizations', {
122
- domains: ['example.com'],
123
- name: 'Test Organization',
124
- })
125
- .replyOnce(201, create_organization_json_1.default);
102
+ (0, test_utils_1.fetchOnce)(create_organization_json_1.default, { status: 201 });
126
103
  yield workos.organizations.createOrganization({
127
104
  domains: ['example.com'],
128
105
  name: 'Test Organization',
129
106
  }, {
130
107
  idempotencyKey: 'the-idempotency-key',
131
108
  });
132
- expect((_a = mock.history.post[0].headers) === null || _a === void 0 ? void 0 : _a['Idempotency-Key']).toEqual('the-idempotency-key');
109
+ expect((0, test_utils_1.fetchHeaders)()).toMatchObject({
110
+ 'Idempotency-Key': 'the-idempotency-key',
111
+ });
112
+ expect((0, test_utils_1.fetchBody)()).toEqual({
113
+ domains: ['example.com'],
114
+ name: 'Test Organization',
115
+ });
133
116
  }));
134
117
  });
135
118
  describe('with a valid payload', () => {
136
119
  it('creates an organization', () => __awaiter(void 0, void 0, void 0, function* () {
137
- mock
138
- .onPost('/organizations', {
120
+ (0, test_utils_1.fetchOnce)(create_organization_json_1.default, { status: 201 });
121
+ const subject = yield workos.organizations.createOrganization({
139
122
  domains: ['example.com'],
140
123
  name: 'Test Organization',
141
- })
142
- .replyOnce(201, create_organization_json_1.default);
143
- const subject = yield workos.organizations.createOrganization({
124
+ });
125
+ expect((0, test_utils_1.fetchBody)()).toEqual({
144
126
  domains: ['example.com'],
145
127
  name: 'Test Organization',
146
128
  });
@@ -151,30 +133,27 @@ describe('Organizations', () => {
151
133
  });
152
134
  describe('with an invalid payload', () => {
153
135
  it('returns an error', () => __awaiter(void 0, void 0, void 0, function* () {
154
- mock
155
- .onPost('/organizations', {
156
- domains: ['example.com'],
157
- name: 'Test Organization',
158
- })
159
- .replyOnce(409, create_organization_invalid_json_1.default, {
160
- 'X-Request-ID': 'a-request-id',
136
+ (0, test_utils_1.fetchOnce)(create_organization_invalid_json_1.default, {
137
+ status: 409,
138
+ headers: { 'X-Request-ID': 'a-request-id' },
161
139
  });
162
140
  yield expect(workos.organizations.createOrganization({
163
141
  domains: ['example.com'],
164
142
  name: 'Test Organization',
165
143
  })).rejects.toThrowError('An Organization with the domain example.com already exists.');
144
+ expect((0, test_utils_1.fetchBody)()).toEqual({
145
+ domains: ['example.com'],
146
+ name: 'Test Organization',
147
+ });
166
148
  }));
167
149
  });
168
150
  });
169
151
  describe('getOrganization', () => {
170
152
  it(`requests an Organization`, () => __awaiter(void 0, void 0, void 0, function* () {
171
- const mock = new axios_mock_adapter_1.default(axios_1.default);
172
- mock
173
- .onGet('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T')
174
- .replyOnce(200, get_organization_json_1.default);
153
+ (0, test_utils_1.fetchOnce)(get_organization_json_1.default);
175
154
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
176
155
  const subject = yield workos.organizations.getOrganization('org_01EHT88Z8J8795GZNQ4ZP1J81T');
177
- expect(mock.history.get[0].url).toEqual('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T');
156
+ expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T');
178
157
  expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
179
158
  expect(subject.name).toEqual('Test Organization 3');
180
159
  expect(subject.allowProfilesOutsideOrganization).toEqual(false);
@@ -183,29 +162,25 @@ describe('Organizations', () => {
183
162
  });
184
163
  describe('deleteOrganization', () => {
185
164
  it('sends request to delete an Organization', () => __awaiter(void 0, void 0, void 0, function* () {
186
- const mock = new axios_mock_adapter_1.default(axios_1.default);
187
- mock
188
- .onDelete('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T')
189
- .replyOnce(200, {});
165
+ (0, test_utils_1.fetchOnce)();
190
166
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
191
167
  yield workos.organizations.deleteOrganization('org_01EHT88Z8J8795GZNQ4ZP1J81T');
192
- expect(mock.history.delete[0].url).toEqual('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T');
168
+ expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T');
193
169
  }));
194
170
  });
195
171
  describe('updateOrganization', () => {
196
172
  describe('with a valid payload', () => {
197
173
  it('updates an organization', () => __awaiter(void 0, void 0, void 0, function* () {
198
- mock
199
- .onPut('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T', {
200
- domains: ['example.com'],
201
- name: 'Test Organization 2',
202
- })
203
- .replyOnce(201, update_organization_json_1.default);
174
+ (0, test_utils_1.fetchOnce)(update_organization_json_1.default, { status: 201 });
204
175
  const subject = yield workos.organizations.updateOrganization({
205
176
  organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
206
177
  domains: ['example.com'],
207
178
  name: 'Test Organization 2',
208
179
  });
180
+ expect((0, test_utils_1.fetchBody)()).toEqual({
181
+ domains: ['example.com'],
182
+ name: 'Test Organization 2',
183
+ });
209
184
  expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
210
185
  expect(subject.name).toEqual('Test Organization 2');
211
186
  expect(subject.domains).toHaveLength(1);
@@ -12,25 +12,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
15
+ const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
16
+ const test_utils_1 = require("../common/utils/test-utils");
17
17
  const create_session_json_1 = __importDefault(require("./fixtures/create-session.json"));
18
18
  const workos_1 = require("../workos");
19
- const mock = new axios_mock_adapter_1.default(axios_1.default);
20
19
  describe('Passwordless', () => {
21
- afterEach(() => mock.resetHistory());
20
+ beforeEach(() => jest_fetch_mock_1.default.resetMocks());
22
21
  describe('createSession', () => {
23
22
  describe('with valid options', () => {
24
23
  it('creates a passwordless session', () => __awaiter(void 0, void 0, void 0, function* () {
25
24
  const email = 'passwordless-session-email@workos.com';
26
25
  const redirectURI = 'https://example.com/passwordless/callback';
27
- mock
28
- .onPost('/passwordless/sessions', {
29
- type: 'MagicLink',
30
- email,
31
- redirect_uri: redirectURI,
32
- })
33
- .replyOnce(201, create_session_json_1.default);
26
+ (0, test_utils_1.fetchOnce)(create_session_json_1.default, { status: 201 });
34
27
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
35
28
  const session = yield workos.passwordless.createSession({
36
29
  type: 'MagicLink',
@@ -39,20 +32,20 @@ describe('Passwordless', () => {
39
32
  });
40
33
  expect(session.email).toEqual(email);
41
34
  expect(session.object).toEqual('passwordless_session');
42
- expect(JSON.parse(mock.history.post[0].data).email).toEqual(email);
43
- expect(JSON.parse(mock.history.post[0].data).redirect_uri).toEqual(redirectURI);
44
- expect(mock.history.post[0].url).toEqual('/passwordless/sessions');
35
+ expect((0, test_utils_1.fetchBody)().email).toEqual(email);
36
+ expect((0, test_utils_1.fetchBody)().redirect_uri).toEqual(redirectURI);
37
+ expect((0, test_utils_1.fetchURL)()).toContain('/passwordless/sessions');
45
38
  }));
46
39
  });
47
40
  });
48
41
  describe('sendEmail', () => {
49
42
  describe('with a valid session id', () => {
50
43
  it(`sends a request to send a magic link email`, () => __awaiter(void 0, void 0, void 0, function* () {
51
- mock.onPost('/passwordless/sessions/session_123/send').replyOnce(200);
44
+ (0, test_utils_1.fetchOnce)();
52
45
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
53
46
  const sessionId = 'session_123';
54
47
  yield workos.passwordless.sendSession(sessionId);
55
- expect(mock.history.post[0].url).toEqual(`/passwordless/sessions/${sessionId}/send`);
48
+ expect((0, test_utils_1.fetchURL)()).toContain(`/passwordless/sessions/${sessionId}/send`);
56
49
  }));
57
50
  });
58
51
  });