@whereby.com/browser-sdk 2.0.0-alpha → 2.0.0-alpha10

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.
Files changed (73) hide show
  1. package/README.md +39 -2
  2. package/dist/lib.cjs +5868 -0
  3. package/dist/lib.esm.js +5850 -0
  4. package/dist/types.d.ts +308 -0
  5. package/dist/v2-alpha10.js +43 -0
  6. package/package.json +12 -6
  7. package/.eslintrc +0 -23
  8. package/.github/actions/build/action.yml +0 -17
  9. package/.github/workflows/deploy.yml +0 -102
  10. package/.github/workflows/test.yml +0 -24
  11. package/.prettierignore +0 -7
  12. package/.prettierrc +0 -4
  13. package/.storybook/main.cjs +0 -16
  14. package/.storybook/preview.js +0 -9
  15. package/jest.config.js +0 -6
  16. package/rollup.config.js +0 -70
  17. package/src/lib/RoomConnection.ts +0 -516
  18. package/src/lib/RoomParticipant.ts +0 -77
  19. package/src/lib/__tests__/embed.unit.ts +0 -77
  20. package/src/lib/api/ApiClient.ts +0 -111
  21. package/src/lib/api/Credentials.ts +0 -45
  22. package/src/lib/api/HttpClient.ts +0 -95
  23. package/src/lib/api/MultipartHttpClient.ts +0 -53
  24. package/src/lib/api/OrganizationApiClient.ts +0 -64
  25. package/src/lib/api/Response.ts +0 -34
  26. package/src/lib/api/credentialsService/index.ts +0 -159
  27. package/src/lib/api/credentialsService/test/index.spec.ts +0 -181
  28. package/src/lib/api/deviceService/index.ts +0 -42
  29. package/src/lib/api/deviceService/tests/index.spec.ts +0 -74
  30. package/src/lib/api/extractUtils.ts +0 -160
  31. package/src/lib/api/index.ts +0 -8
  32. package/src/lib/api/localStorageWrapper/index.ts +0 -15
  33. package/src/lib/api/models/Account.ts +0 -48
  34. package/src/lib/api/models/Meeting.ts +0 -42
  35. package/src/lib/api/models/Organization.ts +0 -186
  36. package/src/lib/api/models/Room.ts +0 -44
  37. package/src/lib/api/models/account/EmbeddedFreeTierStatus.ts +0 -34
  38. package/src/lib/api/models/tests/Account.spec.ts +0 -128
  39. package/src/lib/api/models/tests/Organization.spec.ts +0 -161
  40. package/src/lib/api/models/tests/Room.spec.ts +0 -74
  41. package/src/lib/api/modules/AbstractStore.ts +0 -18
  42. package/src/lib/api/modules/ChromeStorageStore.ts +0 -44
  43. package/src/lib/api/modules/LocalStorageStore.ts +0 -57
  44. package/src/lib/api/modules/tests/ChromeStorageStore.spec.ts +0 -67
  45. package/src/lib/api/modules/tests/LocalStorageStore.spec.ts +0 -79
  46. package/src/lib/api/modules/tests/__mocks__/storage.ts +0 -24
  47. package/src/lib/api/organizationService/index.ts +0 -284
  48. package/src/lib/api/organizationService/tests/index.spec.ts +0 -781
  49. package/src/lib/api/organizationServiceCache/index.ts +0 -28
  50. package/src/lib/api/organizationServiceCache/tests/index.spec.ts +0 -101
  51. package/src/lib/api/parameterAssertUtils.ts +0 -166
  52. package/src/lib/api/roomService/index.ts +0 -310
  53. package/src/lib/api/roomService/tests/index.spec.ts +0 -668
  54. package/src/lib/api/test/ApiClient.spec.ts +0 -139
  55. package/src/lib/api/test/HttpClient.spec.ts +0 -120
  56. package/src/lib/api/test/MultipartHttpClient.spec.ts +0 -145
  57. package/src/lib/api/test/OrganizationApiClient.spec.ts +0 -132
  58. package/src/lib/api/test/extractUtils.spec.ts +0 -357
  59. package/src/lib/api/test/helpers.ts +0 -41
  60. package/src/lib/api/test/parameterAssertUtils.spec.ts +0 -265
  61. package/src/lib/api/types.ts +0 -6
  62. package/src/lib/embed.ts +0 -172
  63. package/src/lib/index.ts +0 -3
  64. package/src/lib/react/VideoElement.tsx +0 -16
  65. package/src/lib/react/index.ts +0 -3
  66. package/src/lib/react/useLocalMedia.ts +0 -25
  67. package/src/lib/react/useRoomConnection.ts +0 -92
  68. package/src/lib/reducer.ts +0 -142
  69. package/src/stories/custom-ui.stories.tsx +0 -133
  70. package/src/stories/prebuilt-ui.stories.tsx +0 -131
  71. package/src/stories/styles.css +0 -74
  72. package/src/types.d.ts +0 -175
  73. package/tsconfig.json +0 -30
@@ -1,781 +0,0 @@
1
- import ApiClient from "../../ApiClient";
2
- import _omit from "lodash/omit";
3
- import OrganizationService from "../index";
4
- import Organization from "../../models/Organization";
5
- import Response from "../../Response";
6
- import { itShouldThrowIfInvalid, itShouldRejectIfApiClientRejects } from "../../test/helpers";
7
- import { ConsentGrantRequest } from "../../types";
8
-
9
- jest.mock("../../ApiClient");
10
-
11
- function createOrganizationResponseObjectFromId(organizationId: string) {
12
- return {
13
- organizationId,
14
- organizationName: "orgName-" + organizationId,
15
- subdomain: "subdomain-" + organizationId,
16
- permissions: {},
17
- limits: {},
18
- };
19
- }
20
-
21
- function createOrganizationFromResponseObject(responseObject: Record<string, unknown>) {
22
- return Organization.fromJson({
23
- permissions: {},
24
- limits: {},
25
- ...responseObject,
26
- });
27
- }
28
-
29
- describe("organizationService", () => {
30
- let apiClient: jest.Mocked<ApiClient>;
31
- let organizationService: OrganizationService;
32
- const organizationId = "1";
33
- const organizationName = "some-name";
34
- const subdomain = "someOrganization";
35
- const verificationCode = "someVerificationCode";
36
- const permissions = {
37
- images: {
38
- logoImageUrl: {
39
- set: {
40
- isAllowed: true,
41
- isSupported: true,
42
- },
43
- reset: {
44
- isAllowed: true,
45
- isSupported: true,
46
- },
47
- },
48
- roomBackgroundImageUrl: {
49
- set: {
50
- isAllowed: true,
51
- isSupported: true,
52
- },
53
- reset: {
54
- isAllowed: true,
55
- isSupported: true,
56
- },
57
- },
58
- roomKnockPageBackgroundImageUrl: {
59
- set: {
60
- isAllowed: true,
61
- isSupported: true,
62
- },
63
- reset: {
64
- isAllowed: true,
65
- isSupported: true,
66
- },
67
- },
68
- },
69
- invitations: {
70
- add: {
71
- isAllowed: true,
72
- isSupported: true,
73
- },
74
- delete: {
75
- isAllowed: true,
76
- isSupported: true,
77
- },
78
- list: {
79
- isAllowed: true,
80
- isSupported: true,
81
- },
82
- },
83
- roles: {
84
- set: {
85
- isAllowed: true,
86
- isSupported: true,
87
- },
88
- remove: {
89
- isAllowed: true,
90
- isSupported: true,
91
- },
92
- removeSelf: {
93
- isAllowed: true,
94
- isSupported: true,
95
- },
96
- list: {
97
- isAllowed: true,
98
- isSupported: true,
99
- },
100
- },
101
- users: {
102
- signUpWithoutInvitation: {
103
- isAllowed: true,
104
- isSupported: true,
105
- },
106
- },
107
- rooms: {
108
- customize: {
109
- isAllowed: true,
110
- isSupported: true,
111
- },
112
- customizeSelf: {
113
- isAllowed: true,
114
- isSupported: true,
115
- },
116
- list: {
117
- isAllowed: true,
118
- isSupported: true,
119
- },
120
- lock: {
121
- isAllowed: true,
122
- isSupported: true,
123
- },
124
- unclaim: {
125
- isAllowed: true,
126
- isSupported: true,
127
- },
128
- unclaimSelf: {
129
- isAllowed: true,
130
- isSupported: true,
131
- },
132
- },
133
- subscriptions: {
134
- add: {
135
- isAllowed: true,
136
- isSupported: true,
137
- },
138
- list: {
139
- isAllowed: true,
140
- isSupported: true,
141
- },
142
- payLatestInvoice: {
143
- isAllowed: true,
144
- isSupported: true,
145
- },
146
- updatePlan: {
147
- isAllowed: true,
148
- isSupported: true,
149
- },
150
- },
151
- browserExtension: {
152
- install: {
153
- isAllowed: true,
154
- isSupported: true,
155
- },
156
- },
157
- };
158
- const limits = {
159
- maxNumberOfInvitationsAndUsers: null,
160
- maxNumberOfClaimedRooms: null,
161
- maxRoomLimitPerOrganization: null,
162
- };
163
-
164
- beforeEach(() => {
165
- apiClient = new ApiClient() as jest.Mocked<ApiClient>;
166
-
167
- organizationService = new OrganizationService({ apiClient });
168
- });
169
-
170
- describe("constructor", () => {
171
- itShouldThrowIfInvalid(
172
- "apiClient",
173
- () =>
174
- new OrganizationService({
175
- //@ts-expect-error
176
- apiClient: undefined,
177
- })
178
- );
179
- });
180
-
181
- describe("createOrganization", () => {
182
- const consents: Array<ConsentGrantRequest> = [
183
- {
184
- consentRevisionId: "Test consentRevisionId",
185
- action: "rejected",
186
- },
187
- ];
188
- const emailOwner = {
189
- email: "owner-email@example.com",
190
- verificationCode,
191
- displayName: "owner-displayName",
192
- consents,
193
- };
194
- const idTokenOwner = {
195
- idToken: "mockIdToken",
196
- displayName: "owner-displayName",
197
- };
198
- const createOrganizationArgs = {
199
- subdomain,
200
- organizationName,
201
- };
202
- const createOrganizationWithEmailArgs = {
203
- ...createOrganizationArgs,
204
- owner: emailOwner,
205
- };
206
- const createOrganizationWithIdTokenArgs = {
207
- ...createOrganizationArgs,
208
- owner: idTokenOwner,
209
- };
210
-
211
- const createdOrganization = {
212
- organizationId,
213
- permissions: {},
214
- limits: {},
215
- };
216
-
217
- describe("when missing arguments", () => {
218
- itShouldThrowIfInvalid("subdomain", () => {
219
- // @ts-expect-error
220
- organizationService.createOrganization(_omit(createOrganizationWithEmailArgs, "subdomain"));
221
- });
222
-
223
- itShouldThrowIfInvalid("organizationName", () => {
224
- // @ts-expect-error
225
- organizationService.createOrganization(_omit(createOrganizationWithEmailArgs, "organizationName"));
226
- });
227
-
228
- itShouldThrowIfInvalid("owner.email or owner.idToken", () => {
229
- organizationService.createOrganization({
230
- ...createOrganizationArgs,
231
- //@ts-expect-error
232
- owner: { displayName: idTokenOwner.displayName },
233
- });
234
- });
235
-
236
- describe("owner.email", () => {
237
- itShouldThrowIfInvalid("owner.verificationCode", () => {
238
- organizationService.createOrganization({
239
- ...createOrganizationWithEmailArgs,
240
- //@ts-expect-error
241
- owner: _omit(createOrganizationWithEmailArgs.owner, "verificationCode"),
242
- });
243
- });
244
- });
245
-
246
- describe("owner.idToken", () => {
247
- itShouldThrowIfInvalid("owner.idToken", () => {
248
- organizationService.createOrganization({
249
- ...createOrganizationWithIdTokenArgs,
250
- //@ts-expect-error
251
- owner: {
252
- ..._omit(createOrganizationWithIdTokenArgs.owner, "idToken"),
253
- },
254
- });
255
- });
256
- });
257
-
258
- itShouldThrowIfInvalid("owner.displayName", () => {
259
- organizationService.createOrganization({
260
- ...createOrganizationWithEmailArgs,
261
- //@ts-expect-error
262
- owner: _omit(createOrganizationWithEmailArgs.owner, "displayName"),
263
- });
264
- });
265
-
266
- itShouldThrowIfInvalid("consents", () => {
267
- organizationService.createOrganization({
268
- ...createOrganizationWithIdTokenArgs,
269
- owner: {
270
- ...createOrganizationWithIdTokenArgs.owner,
271
- //@ts-expect-error
272
- consents: "invalid",
273
- },
274
- });
275
- });
276
- });
277
-
278
- describe("when using email", () => {
279
- it("should resolve with the organizationId of the created organization", async () => {
280
- apiClient.request.mockResolvedValue(
281
- new Response({
282
- status: 200,
283
- data: {
284
- ...createdOrganization,
285
- ...createOrganizationWithEmailArgs,
286
- },
287
- })
288
- );
289
-
290
- const result = await organizationService.createOrganization(createOrganizationWithEmailArgs);
291
-
292
- expect(result).toEqual(createdOrganization.organizationId);
293
- });
294
-
295
- it("should correctly format the API request", () => {
296
- const expectedUrl = `/organizations`;
297
- apiClient.request.mockResolvedValue(
298
- new Response({
299
- status: 200,
300
- data: {
301
- ...createdOrganization,
302
- ...createOrganizationWithEmailArgs,
303
- },
304
- })
305
- );
306
-
307
- const promise = organizationService.createOrganization(createOrganizationWithEmailArgs);
308
-
309
- return promise.then(() => {
310
- expect(apiClient.request).toBeCalledWith(expectedUrl, {
311
- method: "POST",
312
- data: {
313
- owner: {
314
- displayName: createOrganizationWithEmailArgs.owner.displayName,
315
- email: {
316
- value: createOrganizationWithEmailArgs.owner.email,
317
- verificationCode: createOrganizationWithEmailArgs.owner.verificationCode,
318
- },
319
- consents: createOrganizationWithEmailArgs.owner.consents,
320
- },
321
- organizationName: createOrganizationWithEmailArgs.organizationName,
322
- subdomain: createOrganizationWithEmailArgs.subdomain,
323
- type: "private",
324
- },
325
- });
326
- });
327
- });
328
- });
329
-
330
- describe("when using idToken", () => {
331
- it("should resolve with the organizationId of the created organization", async () => {
332
- apiClient.request.mockResolvedValue(
333
- new Response({
334
- status: 200,
335
- data: {
336
- ...createdOrganization,
337
- ...createOrganizationWithIdTokenArgs,
338
- },
339
- })
340
- );
341
-
342
- const result = await organizationService.createOrganization(createOrganizationWithIdTokenArgs);
343
-
344
- expect(result).toEqual(createdOrganization.organizationId);
345
- });
346
-
347
- it("should correctly format the API request", () => {
348
- const expectedUrl = `/organizations`;
349
- apiClient.request.mockResolvedValue(
350
- new Response({
351
- status: 200,
352
- data: {
353
- ...createdOrganization,
354
- ...createOrganizationWithIdTokenArgs,
355
- },
356
- })
357
- );
358
-
359
- const promise = organizationService.createOrganization(createOrganizationWithIdTokenArgs);
360
-
361
- return promise.then(() => {
362
- expect(apiClient.request).toBeCalledWith(expectedUrl, {
363
- method: "POST",
364
- data: {
365
- owner: {
366
- displayName: createOrganizationWithIdTokenArgs.owner.displayName,
367
- idToken: createOrganizationWithIdTokenArgs.owner.idToken,
368
- },
369
- organizationName: createOrganizationWithIdTokenArgs.organizationName,
370
- subdomain: createOrganizationWithIdTokenArgs.subdomain,
371
- type: "private",
372
- },
373
- });
374
- });
375
- });
376
- });
377
- });
378
-
379
- describe("getOrganizationBySubdomain", () => {
380
- beforeEach(() => {
381
- apiClient.request.mockRejectedValue(new Error("Called request method with unexpected parameters"));
382
- });
383
-
384
- itShouldThrowIfInvalid("subdomain", () => {
385
- //@ts-expect-error
386
- organizationService.getOrganizationBySubdomain(null);
387
- });
388
-
389
- itShouldRejectIfApiClientRejects(
390
- () => apiClient,
391
- () => organizationService.getOrganizationBySubdomain(subdomain)
392
- );
393
-
394
- it("should return null if no matching organization was found", async () => {
395
- apiClient.request.mockRejectedValue(
396
- new Response({
397
- status: 404,
398
- })
399
- );
400
-
401
- const result = await organizationService.getOrganizationBySubdomain(subdomain);
402
-
403
- expect(result).toEqual(null);
404
- });
405
-
406
- it("should return the matching organization", async () => {
407
- const data = {
408
- organizationId,
409
- organizationName,
410
- subdomain,
411
- permissions,
412
- limits,
413
- };
414
- apiClient.request.mockResolvedValue(
415
- new Response({
416
- status: 200,
417
- data,
418
- })
419
- );
420
-
421
- const result = await organizationService.getOrganizationBySubdomain(subdomain);
422
-
423
- expect(result).toEqual(Organization.fromJson(data));
424
- });
425
-
426
- it("should support retrieving organization with empty subdomain", async () => {
427
- apiClient.request.mockResolvedValue(
428
- new Response({
429
- status: 200,
430
- data: {
431
- organizationId,
432
- organizationName,
433
- subdomain,
434
- permissions,
435
- limits,
436
- },
437
- })
438
- );
439
-
440
- const result = await organizationService.getOrganizationBySubdomain("");
441
-
442
- expect(result).toEqual(
443
- Organization.fromJson({
444
- organizationId,
445
- organizationName,
446
- subdomain,
447
- permissions,
448
- limits,
449
- })
450
- );
451
- });
452
- });
453
-
454
- describe("getOrganizationByOrganizationId", () => {
455
- beforeEach(() => {
456
- const response = new Response({ status: 200, data: {} });
457
- apiClient.request.mockResolvedValue(response);
458
- });
459
-
460
- itShouldThrowIfInvalid("organizationId", () => {
461
- //@ts-expect-error
462
- organizationService.getOrganizationByOrganizationId(null);
463
- });
464
-
465
- itShouldRejectIfApiClientRejects(
466
- () => apiClient,
467
- () => organizationService.getOrganizationByOrganizationId(organizationId)
468
- );
469
-
470
- it("should return null if no matching organization was found", async () => {
471
- apiClient.request.mockRejectedValue(
472
- new Response({
473
- status: 404,
474
- })
475
- );
476
-
477
- const result = await organizationService.getOrganizationByOrganizationId(organizationId);
478
-
479
- expect(result).toEqual(null);
480
- });
481
-
482
- it("should return the matching organization", async () => {
483
- apiClient.request.mockResolvedValue(
484
- new Response({
485
- status: 200,
486
- data: {
487
- organizationId,
488
- organizationName,
489
- subdomain,
490
- permissions,
491
- limits,
492
- },
493
- })
494
- );
495
-
496
- const result = await organizationService.getOrganizationByOrganizationId(organizationId);
497
-
498
- expect(result).toEqual(
499
- Organization.fromJson({
500
- organizationId,
501
- organizationName,
502
- subdomain,
503
- permissions,
504
- limits,
505
- })
506
- );
507
- });
508
- });
509
-
510
- describe("getOrganizationsByContactPoint", () => {
511
- let email: string;
512
- let phoneNumber: string;
513
- let code: string;
514
-
515
- beforeEach(() => {
516
- email = "some-email@example.com";
517
- phoneNumber = "+111";
518
- code = "some code";
519
-
520
- const response = new Response({
521
- status: 200,
522
- data: {
523
- organizations: [],
524
- },
525
- });
526
- apiClient.request.mockResolvedValue(response);
527
- });
528
-
529
- itShouldThrowIfInvalid("code", () => {
530
- // @ts-expect-error
531
- organizationService.getOrganizationsByContactPoint({ email });
532
- });
533
-
534
- it("should throw if both email and phoneNumber are missing", () => {
535
- expect(() => {
536
- // @ts-expect-error
537
- organizationService.getOrganizationsByContactPoint({ code });
538
- }).toThrowError("email or phoneNumber is required");
539
- });
540
-
541
- it("should throw if both email and phoneNumber are provided", () => {
542
- expect(() => {
543
- organizationService.getOrganizationsByContactPoint({ email, phoneNumber, code });
544
- }).toThrowError("email or phoneNumber is required");
545
- });
546
-
547
- itShouldRejectIfApiClientRejects(
548
- () => apiClient,
549
- () => organizationService.getOrganizationsByContactPoint({ email, code })
550
- );
551
-
552
- describe("when phoneNumber is provided", () => {
553
- it("should return empty array if no matching organizations were found", async () => {
554
- apiClient.request.mockResolvedValue(
555
- new Response({
556
- status: 200,
557
- data: { organizations: [] },
558
- })
559
- );
560
-
561
- const result = await organizationService.getOrganizationsByContactPoint({ phoneNumber, code });
562
-
563
- expect(result).toEqual([]);
564
- });
565
-
566
- it("should return the matching organizations", async () => {
567
- const organizationsPayload = ["1", "2", "3"].map(createOrganizationResponseObjectFromId);
568
- const expectedOrganizations = organizationsPayload.map(createOrganizationFromResponseObject);
569
- apiClient.request.mockResolvedValue(
570
- new Response({
571
- status: 200,
572
- data: { organizations: organizationsPayload },
573
- })
574
- );
575
-
576
- const result = await organizationService.getOrganizationsByContactPoint({ phoneNumber, code });
577
-
578
- expect(result).toEqual(expectedOrganizations);
579
- });
580
- });
581
-
582
- describe("when email is provided", () => {
583
- it("should return empty array if no matching organizations were found", async () => {
584
- apiClient.request.mockResolvedValue(
585
- new Response({
586
- status: 200,
587
- data: {
588
- organizations: [],
589
- },
590
- })
591
- );
592
-
593
- const result = await organizationService.getOrganizationsByContactPoint({ email, code });
594
-
595
- expect(result).toEqual([]);
596
- });
597
-
598
- it("should return the matching organizations", async () => {
599
- const organizationsPayload = ["1", "2", "3"].map(createOrganizationResponseObjectFromId);
600
- const expectedOrganizations = organizationsPayload.map(createOrganizationFromResponseObject);
601
- apiClient.request.mockResolvedValue(
602
- new Response({
603
- status: 200,
604
- data: { organizations: organizationsPayload },
605
- })
606
- );
607
-
608
- const result = await organizationService.getOrganizationsByContactPoint({ email, code });
609
-
610
- expect(result).toEqual(expectedOrganizations);
611
- });
612
- });
613
- });
614
-
615
- describe("getOrganizationsByIdToken", () => {
616
- let idToken: string;
617
-
618
- beforeEach(() => {
619
- idToken = "some-id-token";
620
-
621
- const response = new Response({
622
- status: 200,
623
- data: {
624
- organizations: [],
625
- },
626
- });
627
- apiClient.request.mockResolvedValue(response);
628
- });
629
-
630
- itShouldThrowIfInvalid("idToken", () => {
631
- // @ts-expect-error
632
- organizationService.getOrganizationsByIdToken({});
633
- });
634
-
635
- itShouldRejectIfApiClientRejects(
636
- () => apiClient,
637
- () => organizationService.getOrganizationsByIdToken({ idToken })
638
- );
639
-
640
- describe("when idToken is provided", () => {
641
- it("should return empty array if no matching organizations were found", async () => {
642
- apiClient.request.mockResolvedValue(
643
- new Response({
644
- status: 200,
645
- data: { organizations: [] },
646
- })
647
- );
648
-
649
- const result = await organizationService.getOrganizationsByIdToken({ idToken });
650
-
651
- expect(result).toEqual([]);
652
- });
653
-
654
- it("should return the matching organizations", async () => {
655
- const organizationsPayload = ["1", "2", "3"].map(createOrganizationResponseObjectFromId);
656
- const expectedOrganizations = organizationsPayload.map(createOrganizationFromResponseObject);
657
- apiClient.request.mockResolvedValue(
658
- new Response({
659
- status: 200,
660
- data: { organizations: organizationsPayload },
661
- })
662
- );
663
-
664
- const result = await organizationService.getOrganizationsByIdToken({ idToken });
665
-
666
- expect(result).toEqual(expectedOrganizations);
667
- });
668
- });
669
- });
670
-
671
- describe("getOrganizationsByLoggedInUser", () => {
672
- beforeEach(() => {
673
- const response = new Response({
674
- status: 200,
675
- data: {
676
- organizations: [],
677
- },
678
- });
679
- apiClient.request.mockResolvedValue(response);
680
- });
681
-
682
- itShouldRejectIfApiClientRejects(
683
- () => apiClient,
684
- () => organizationService.getOrganizationsByLoggedInUser()
685
- );
686
-
687
- it("should return empty array if no matching organizations were found", async () => {
688
- apiClient.request.mockResolvedValue(
689
- new Response({
690
- status: 200,
691
- data: { organizations: [] },
692
- })
693
- );
694
-
695
- const result = await organizationService.getOrganizationsByLoggedInUser();
696
-
697
- return expect(result).toEqual([]);
698
- });
699
-
700
- it("should return the matching organizations", async () => {
701
- const organizationsPayload = ["1", "2", "3"].map(createOrganizationResponseObjectFromId);
702
- const expectedOrganizations = organizationsPayload.map(createOrganizationFromResponseObject);
703
- apiClient.request.mockResolvedValue(
704
- new Response({
705
- status: 200,
706
- data: { organizations: organizationsPayload },
707
- })
708
- );
709
-
710
- const result = await organizationService.getOrganizationsByLoggedInUser();
711
-
712
- expect(result).toEqual(expectedOrganizations);
713
- });
714
- });
715
-
716
- describe("getSubdomainAvailability", () => {
717
- itShouldThrowIfInvalid("subdomain", () => {
718
- //@ts-expect-error
719
- organizationService.getSubdomainAvailability(null);
720
- });
721
-
722
- itShouldRejectIfApiClientRejects(
723
- () => apiClient,
724
- () => organizationService.getSubdomainAvailability(subdomain)
725
- );
726
-
727
- it("should return the data provided by the server", async () => {
728
- const data = {
729
- status: "available",
730
- };
731
- apiClient.request.mockResolvedValue(
732
- new Response({
733
- status: 200,
734
- data,
735
- })
736
- );
737
-
738
- const result = await organizationService.getSubdomainAvailability(subdomain);
739
-
740
- expect(result).toEqual(data);
741
- });
742
- });
743
-
744
- describe("updatePreferences", () => {
745
- itShouldRejectIfApiClientRejects(
746
- () => apiClient,
747
- () => organizationService.updatePreferences({ organizationId: "2", preferences: {} })
748
- );
749
-
750
- it("should update preferences", async () => {
751
- const expectedUrl = `/organizations/${organizationId}/preferences`;
752
- const preferences = { someKey: "some value" };
753
- apiClient.request.mockResolvedValue(new Response({ status: 204, data: null }));
754
-
755
- await organizationService.updatePreferences({ organizationId, preferences });
756
-
757
- expect(apiClient.request).toBeCalledWith(expectedUrl, {
758
- method: "PATCH",
759
- data: preferences,
760
- });
761
- });
762
- });
763
-
764
- describe("deleteOrganization", () => {
765
- itShouldRejectIfApiClientRejects(
766
- () => apiClient,
767
- () => organizationService.deleteOrganization({ organizationId: "2" })
768
- );
769
-
770
- it("should delete organization", async () => {
771
- const expectedUrl = `/organizations/${organizationId}`;
772
- apiClient.request.mockResolvedValue(new Response({ status: 204, data: null }));
773
-
774
- await organizationService.deleteOrganization({ organizationId });
775
-
776
- expect(apiClient.request).toBeCalledWith(expectedUrl, {
777
- method: "DELETE",
778
- });
779
- });
780
- });
781
- });