@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.
- package/README.md +39 -2
- package/dist/lib.cjs +5868 -0
- package/dist/lib.esm.js +5850 -0
- package/dist/types.d.ts +308 -0
- package/dist/v2-alpha10.js +43 -0
- package/package.json +12 -6
- package/.eslintrc +0 -23
- package/.github/actions/build/action.yml +0 -17
- package/.github/workflows/deploy.yml +0 -102
- package/.github/workflows/test.yml +0 -24
- package/.prettierignore +0 -7
- package/.prettierrc +0 -4
- package/.storybook/main.cjs +0 -16
- package/.storybook/preview.js +0 -9
- package/jest.config.js +0 -6
- package/rollup.config.js +0 -70
- package/src/lib/RoomConnection.ts +0 -516
- package/src/lib/RoomParticipant.ts +0 -77
- package/src/lib/__tests__/embed.unit.ts +0 -77
- package/src/lib/api/ApiClient.ts +0 -111
- package/src/lib/api/Credentials.ts +0 -45
- package/src/lib/api/HttpClient.ts +0 -95
- package/src/lib/api/MultipartHttpClient.ts +0 -53
- package/src/lib/api/OrganizationApiClient.ts +0 -64
- package/src/lib/api/Response.ts +0 -34
- package/src/lib/api/credentialsService/index.ts +0 -159
- package/src/lib/api/credentialsService/test/index.spec.ts +0 -181
- package/src/lib/api/deviceService/index.ts +0 -42
- package/src/lib/api/deviceService/tests/index.spec.ts +0 -74
- package/src/lib/api/extractUtils.ts +0 -160
- package/src/lib/api/index.ts +0 -8
- package/src/lib/api/localStorageWrapper/index.ts +0 -15
- package/src/lib/api/models/Account.ts +0 -48
- package/src/lib/api/models/Meeting.ts +0 -42
- package/src/lib/api/models/Organization.ts +0 -186
- package/src/lib/api/models/Room.ts +0 -44
- package/src/lib/api/models/account/EmbeddedFreeTierStatus.ts +0 -34
- package/src/lib/api/models/tests/Account.spec.ts +0 -128
- package/src/lib/api/models/tests/Organization.spec.ts +0 -161
- package/src/lib/api/models/tests/Room.spec.ts +0 -74
- package/src/lib/api/modules/AbstractStore.ts +0 -18
- package/src/lib/api/modules/ChromeStorageStore.ts +0 -44
- package/src/lib/api/modules/LocalStorageStore.ts +0 -57
- package/src/lib/api/modules/tests/ChromeStorageStore.spec.ts +0 -67
- package/src/lib/api/modules/tests/LocalStorageStore.spec.ts +0 -79
- package/src/lib/api/modules/tests/__mocks__/storage.ts +0 -24
- package/src/lib/api/organizationService/index.ts +0 -284
- package/src/lib/api/organizationService/tests/index.spec.ts +0 -781
- package/src/lib/api/organizationServiceCache/index.ts +0 -28
- package/src/lib/api/organizationServiceCache/tests/index.spec.ts +0 -101
- package/src/lib/api/parameterAssertUtils.ts +0 -166
- package/src/lib/api/roomService/index.ts +0 -310
- package/src/lib/api/roomService/tests/index.spec.ts +0 -668
- package/src/lib/api/test/ApiClient.spec.ts +0 -139
- package/src/lib/api/test/HttpClient.spec.ts +0 -120
- package/src/lib/api/test/MultipartHttpClient.spec.ts +0 -145
- package/src/lib/api/test/OrganizationApiClient.spec.ts +0 -132
- package/src/lib/api/test/extractUtils.spec.ts +0 -357
- package/src/lib/api/test/helpers.ts +0 -41
- package/src/lib/api/test/parameterAssertUtils.spec.ts +0 -265
- package/src/lib/api/types.ts +0 -6
- package/src/lib/embed.ts +0 -172
- package/src/lib/index.ts +0 -3
- package/src/lib/react/VideoElement.tsx +0 -16
- package/src/lib/react/index.ts +0 -3
- package/src/lib/react/useLocalMedia.ts +0 -25
- package/src/lib/react/useRoomConnection.ts +0 -92
- package/src/lib/reducer.ts +0 -142
- package/src/stories/custom-ui.stories.tsx +0 -133
- package/src/stories/prebuilt-ui.stories.tsx +0 -131
- package/src/stories/styles.css +0 -74
- package/src/types.d.ts +0 -175
- package/tsconfig.json +0 -30
|
@@ -1,668 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import OrganizationApiClient from "../../OrganizationApiClient";
|
|
3
|
-
import Response from "../../Response";
|
|
4
|
-
import RoomService from "../index";
|
|
5
|
-
import Room from "../../models/Room";
|
|
6
|
-
import Meeting from "../../models/Meeting";
|
|
7
|
-
import { itShouldThrowIfInvalid, itShouldRejectIfApiClientRejects, toJson } from "../../test/helpers";
|
|
8
|
-
|
|
9
|
-
jest.mock("../../OrganizationApiClient");
|
|
10
|
-
|
|
11
|
-
describe("RoomService", () => {
|
|
12
|
-
let organizationApiClient;
|
|
13
|
-
let roomService;
|
|
14
|
-
const defaultParams = { includeOnlyLegacyRoomType: "false" };
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
organizationApiClient = new OrganizationApiClient();
|
|
18
|
-
roomService = new RoomService({
|
|
19
|
-
organizationApiClient,
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe("constructor", () => {
|
|
24
|
-
itShouldThrowIfInvalid(
|
|
25
|
-
"organizationApiClient",
|
|
26
|
-
() =>
|
|
27
|
-
new RoomService({
|
|
28
|
-
organizationApiClient: undefined,
|
|
29
|
-
})
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe("getRooms", () => {
|
|
34
|
-
const url = "/room";
|
|
35
|
-
const method = "GET";
|
|
36
|
-
const data = {
|
|
37
|
-
rooms: [{ roomName: "/first-room" }, { roomName: "/second-room" }],
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
organizationApiClient.request.mockResolvedValueOnce(new Response({ data }));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
itShouldThrowIfInvalid("types", () => roomService.getRooms());
|
|
45
|
-
|
|
46
|
-
function testGetRooms({ args, expectedTypes }) {
|
|
47
|
-
it(`should call request with types = [${expectedTypes}]`, () => {
|
|
48
|
-
roomService.getRooms(args);
|
|
49
|
-
|
|
50
|
-
expect(organizationApiClient.request).toBeCalledWith(url, {
|
|
51
|
-
method,
|
|
52
|
-
params: { types: expectedTypes, fields: "", ...defaultParams },
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("should transform data correctly", async () => {
|
|
57
|
-
const expectedResult = [new Room({ roomName: "/first-room" }), new Room({ roomName: "/second-room" })];
|
|
58
|
-
|
|
59
|
-
const result = await roomService.getRooms(args);
|
|
60
|
-
|
|
61
|
-
expect(result).toEqual(expectedResult);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
describe("when types are provided", () => {
|
|
66
|
-
testGetRooms({ args: { types: ["team", "personal"], fields: [] }, expectedTypes: "team,personal" });
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe("getRoom", () => {
|
|
71
|
-
const roomName = "/some-random-name";
|
|
72
|
-
const uri = `/rooms${roomName}`;
|
|
73
|
-
const method = "GET";
|
|
74
|
-
|
|
75
|
-
itShouldThrowIfInvalid("roomName", () => roomService.getRoom({}));
|
|
76
|
-
// roomName must be a string
|
|
77
|
-
itShouldThrowIfInvalid("roomName", () => roomService.getRoom({ roomName: 23 }));
|
|
78
|
-
|
|
79
|
-
// roomName must begin with slash
|
|
80
|
-
it("should throw if `roomName` doesn't begin with a forward slash", () => {
|
|
81
|
-
const expectedException = "roomName must begin with a '/'";
|
|
82
|
-
|
|
83
|
-
expect(() => {
|
|
84
|
-
roomService.getRoom({ roomName: "room-should-begin-with-slash" });
|
|
85
|
-
}).toThrowError(expectedException);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("should add the room name to the response body if response code is 2xx", async () => {
|
|
89
|
-
const data = {
|
|
90
|
-
test: "data",
|
|
91
|
-
};
|
|
92
|
-
const expectedObj = new Room(Object.assign({}, data, { roomName }));
|
|
93
|
-
organizationApiClient.request.mockResolvedValue(new Response({ data }));
|
|
94
|
-
|
|
95
|
-
const result = await roomService.getRoom({ roomName });
|
|
96
|
-
|
|
97
|
-
expect(result).toEqual(expectedObj);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should call request with correct params when called with fields", async () => {
|
|
101
|
-
const fields = ["some-field"];
|
|
102
|
-
organizationApiClient.request.mockResolvedValue({ data: {} });
|
|
103
|
-
|
|
104
|
-
await roomService.getRoom({ roomName, fields });
|
|
105
|
-
|
|
106
|
-
expect(organizationApiClient.request).toBeCalledWith(uri, {
|
|
107
|
-
method,
|
|
108
|
-
params: { fields: fields[0], ...defaultParams },
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("should set meeting if meeting is returned", async () => {
|
|
113
|
-
const mockMeeting = {
|
|
114
|
-
meetingId: "10",
|
|
115
|
-
roomName: "/some-room-name",
|
|
116
|
-
roomUrl: "some-room-url",
|
|
117
|
-
startDate: new Date(),
|
|
118
|
-
endDate: new Date(),
|
|
119
|
-
hostRoomUrl: "some-host-room-url",
|
|
120
|
-
viewerRoomUrl: null,
|
|
121
|
-
};
|
|
122
|
-
const data = {
|
|
123
|
-
meeting: toJson(mockMeeting),
|
|
124
|
-
};
|
|
125
|
-
const expectedObj = new Room({ roomName, meeting: new Meeting(mockMeeting) });
|
|
126
|
-
organizationApiClient.request.mockResolvedValue(new Response({ data }));
|
|
127
|
-
|
|
128
|
-
const result = await roomService.getRoom({ roomName });
|
|
129
|
-
|
|
130
|
-
expect(result).toEqual(expectedObj);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should set isBanned to true if response code is 400 with error Banned room", async () => {
|
|
134
|
-
const expectedObj = new Room({
|
|
135
|
-
roomName,
|
|
136
|
-
isBanned: true,
|
|
137
|
-
});
|
|
138
|
-
organizationApiClient.request.mockRejectedValue(
|
|
139
|
-
new Response({
|
|
140
|
-
status: 400,
|
|
141
|
-
data: {
|
|
142
|
-
error: "Banned room",
|
|
143
|
-
},
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const result = await roomService.getRoom({ roomName });
|
|
148
|
-
|
|
149
|
-
expect(result).toEqual(expectedObj);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("should return deduced room object if response code is 404", async () => {
|
|
153
|
-
organizationApiClient.request.mockRejectedValue(new Response({ status: 404 }));
|
|
154
|
-
|
|
155
|
-
const result = await roomService.getRoom({ roomName });
|
|
156
|
-
|
|
157
|
-
expect(result).toEqual(
|
|
158
|
-
new Room({
|
|
159
|
-
roomName,
|
|
160
|
-
isClaimed: false,
|
|
161
|
-
legacyRoomType: "free",
|
|
162
|
-
mode: "normal",
|
|
163
|
-
product: {
|
|
164
|
-
categoryName: "personal_free",
|
|
165
|
-
},
|
|
166
|
-
type: "personal",
|
|
167
|
-
})
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("should return error message if response code is not 2xx, 403 or 404 and data.error exists", async () => {
|
|
172
|
-
const data = {
|
|
173
|
-
error: "Some error message",
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
organizationApiClient.request.mockRejectedValue(new Response({ status: 405, data }));
|
|
177
|
-
|
|
178
|
-
await expect(roomService.getRoom({ roomName })).rejects.toThrow(data.error);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("should return error message if response code is not 2xx, 403 or 404 and data.error does not exist", async () => {
|
|
182
|
-
const errorMessage = "Could not fetch room information";
|
|
183
|
-
|
|
184
|
-
organizationApiClient.request.mockRejectedValue(new Response({ status: 505, data: null }));
|
|
185
|
-
|
|
186
|
-
await expect(roomService.getRoom({ roomName })).rejects.toThrow(errorMessage);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe("claimRoom", () => {
|
|
191
|
-
const url = "/room/claim";
|
|
192
|
-
const method = "POST";
|
|
193
|
-
const type = "personal";
|
|
194
|
-
const roomName = "/some-random-name";
|
|
195
|
-
|
|
196
|
-
beforeEach(() => {
|
|
197
|
-
organizationApiClient.request.mockResolvedValue(new Response({}));
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
itShouldThrowIfInvalid("roomName", () => roomService.claimRoom({ type }));
|
|
201
|
-
itShouldThrowIfInvalid("type", () => roomService.claimRoom({ roomName }));
|
|
202
|
-
|
|
203
|
-
it("should reject with error containing the error message if available", async () => {
|
|
204
|
-
const expectedError = "some error";
|
|
205
|
-
organizationApiClient.request.mockRejectedValue(
|
|
206
|
-
new Response({
|
|
207
|
-
status: 500,
|
|
208
|
-
data: {
|
|
209
|
-
error: expectedError,
|
|
210
|
-
},
|
|
211
|
-
})
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
await expect(roomService.claimRoom({ roomName, type })).rejects.toThrow(expectedError);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("should reject with error 'Failed to claim room' if none is provided by the server", async () => {
|
|
218
|
-
organizationApiClient.request.mockRejectedValue(
|
|
219
|
-
new Response({
|
|
220
|
-
status: 500,
|
|
221
|
-
data: {},
|
|
222
|
-
})
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
await expect(roomService.claimRoom({ roomName, type })).rejects.toThrow("Failed to claim room");
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("should call request with correct params if all arguments have been provided", () => {
|
|
229
|
-
const isLocked = true;
|
|
230
|
-
|
|
231
|
-
roomService.claimRoom({ roomName, type, isLocked });
|
|
232
|
-
|
|
233
|
-
expect(organizationApiClient.request).toBeCalledWith(url, {
|
|
234
|
-
method,
|
|
235
|
-
data: { roomName, type, isLocked },
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("should call request with correct params if isLock is not provided", () => {
|
|
240
|
-
roomService.claimRoom({ roomName, type });
|
|
241
|
-
|
|
242
|
-
expect(organizationApiClient.request).toBeCalledWith(url, {
|
|
243
|
-
method,
|
|
244
|
-
data: { roomName, type },
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
describe("unclaimRoom", () => {
|
|
250
|
-
const roomName = "/some-room-name";
|
|
251
|
-
|
|
252
|
-
itShouldThrowIfInvalid("roomName", () => {
|
|
253
|
-
roomService.unclaimRoom(undefined);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
itShouldRejectIfApiClientRejects(
|
|
257
|
-
() => organizationApiClient,
|
|
258
|
-
() => {
|
|
259
|
-
return roomService.unclaimRoom(roomName);
|
|
260
|
-
}
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
it("should call request the expected parameters", async () => {
|
|
264
|
-
organizationApiClient.request.mockResolvedValue(new Response({ status: 204 }));
|
|
265
|
-
|
|
266
|
-
await roomService.unclaimRoom(roomName);
|
|
267
|
-
|
|
268
|
-
expect(organizationApiClient.request).toBeCalledWith(`/room/${encodeURIComponent(roomName.substring(1))}`, {
|
|
269
|
-
method: "DELETE",
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it("should resolve with undefined on success", async () => {
|
|
274
|
-
organizationApiClient.request.mockResolvedValue(new Response({ status: 204 }));
|
|
275
|
-
|
|
276
|
-
const result = await roomService.unclaimRoom(roomName);
|
|
277
|
-
|
|
278
|
-
expect(result).toBeUndefined();
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
describe("renameRoom", () => {
|
|
283
|
-
const roomName = "/foo";
|
|
284
|
-
const encodedRoomName = encodeURIComponent(roomName.substring(1));
|
|
285
|
-
const url = `/room/${encodedRoomName}/roomName`;
|
|
286
|
-
const newRoomName = "/bar";
|
|
287
|
-
const data = { newRoomName };
|
|
288
|
-
|
|
289
|
-
beforeEach(() => {
|
|
290
|
-
organizationApiClient.request.mockResolvedValue(new Response({}));
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it("should call apiClient.request with the expected parameters", async () => {
|
|
294
|
-
await roomService.renameRoom({ roomName, newRoomName });
|
|
295
|
-
|
|
296
|
-
expect(organizationApiClient.request).toBeCalledWith(url, { method: "PUT", data });
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it("should be resolved if apiClient.request resolves", async () => {
|
|
300
|
-
const result = await roomService.renameRoom({ roomName, newRoomName });
|
|
301
|
-
|
|
302
|
-
expect(result).toBeUndefined();
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
itShouldRejectIfApiClientRejects(
|
|
306
|
-
() => organizationApiClient,
|
|
307
|
-
() => {
|
|
308
|
-
return roomService.renameRoom({ roomName, newRoomName });
|
|
309
|
-
}
|
|
310
|
-
);
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
describe("changeMode", () => {
|
|
314
|
-
const roomName = "/foo";
|
|
315
|
-
const encodedDisplayName = encodeURIComponent(roomName.substring(1));
|
|
316
|
-
const url = `/room/${encodedDisplayName}/mode`;
|
|
317
|
-
const method = "PUT";
|
|
318
|
-
const mode = "group";
|
|
319
|
-
const data = { mode };
|
|
320
|
-
|
|
321
|
-
beforeEach(() => {
|
|
322
|
-
organizationApiClient.request.mockResolvedValue(new Response({}));
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
it("should call apiClient.request with the expected parameters", async () => {
|
|
326
|
-
await roomService.changeMode({ roomName, mode });
|
|
327
|
-
|
|
328
|
-
expect(organizationApiClient.request).toBeCalledWith(url, { method, data });
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("should be resolved if apiClient.request resolves", async () => {
|
|
332
|
-
const result = await roomService.changeMode({ roomName, mode });
|
|
333
|
-
|
|
334
|
-
expect(result).toBeUndefined();
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
itShouldRejectIfApiClientRejects(
|
|
338
|
-
() => organizationApiClient,
|
|
339
|
-
() => {
|
|
340
|
-
return roomService.changeMode({ roomName, mode });
|
|
341
|
-
}
|
|
342
|
-
);
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
describe("getRoomPermissions", () => {
|
|
346
|
-
const roomName = "/some-room-name";
|
|
347
|
-
const permissions = {};
|
|
348
|
-
const limits = {
|
|
349
|
-
maxNumberOfClaimedRooms: null,
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
const roomPermissionsPayload = {
|
|
353
|
-
permissions,
|
|
354
|
-
limits,
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
itShouldThrowIfInvalid("roomName", () => {
|
|
358
|
-
roomService.getRoomPermissions();
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
itShouldRejectIfApiClientRejects(
|
|
362
|
-
() => organizationApiClient,
|
|
363
|
-
() => {
|
|
364
|
-
return roomService.getRoomPermissions(roomName);
|
|
365
|
-
}
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
describe("when roomKey is not provided", () => {
|
|
369
|
-
it("should call request the expected parameters", async () => {
|
|
370
|
-
organizationApiClient.request.mockResolvedValue(
|
|
371
|
-
new Response({
|
|
372
|
-
status: 200,
|
|
373
|
-
data: roomPermissionsPayload,
|
|
374
|
-
})
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
await roomService.getRoomPermissions(roomName);
|
|
378
|
-
|
|
379
|
-
expect(organizationApiClient.request).toBeCalledWith(
|
|
380
|
-
`/room/${encodeURIComponent(roomName.substring(1))}/permissions`,
|
|
381
|
-
{
|
|
382
|
-
method: "GET",
|
|
383
|
-
}
|
|
384
|
-
);
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it("should resolve with undefined on success", async () => {
|
|
388
|
-
organizationApiClient.request.mockResolvedValue(
|
|
389
|
-
new Response({
|
|
390
|
-
status: 200,
|
|
391
|
-
data: roomPermissionsPayload,
|
|
392
|
-
})
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
const result = await roomService.getRoomPermissions(roomName);
|
|
396
|
-
|
|
397
|
-
expect(result).toEqual(roomPermissionsPayload);
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
describe("when roomKey is provided", () => {
|
|
402
|
-
let roomKey;
|
|
403
|
-
|
|
404
|
-
beforeEach(() => {
|
|
405
|
-
roomKey = "some room key";
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
it("should call request the expected parameters", async () => {
|
|
409
|
-
organizationApiClient.request.mockResolvedValue(
|
|
410
|
-
new Response({
|
|
411
|
-
status: 200,
|
|
412
|
-
data: roomPermissionsPayload,
|
|
413
|
-
})
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
await roomService.getRoomPermissions(roomName, { roomKey });
|
|
417
|
-
|
|
418
|
-
expect(organizationApiClient.request).toBeCalledWith(
|
|
419
|
-
`/room/${encodeURIComponent(roomName.substring(1))}/permissions`,
|
|
420
|
-
{
|
|
421
|
-
method: "GET",
|
|
422
|
-
headers: {
|
|
423
|
-
"X-Whereby-Room-Key": roomKey,
|
|
424
|
-
},
|
|
425
|
-
}
|
|
426
|
-
);
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
it("should resolve with undefined on success", async () => {
|
|
430
|
-
organizationApiClient.request.mockResolvedValue(
|
|
431
|
-
new Response({
|
|
432
|
-
status: 200,
|
|
433
|
-
data: roomPermissionsPayload,
|
|
434
|
-
})
|
|
435
|
-
);
|
|
436
|
-
|
|
437
|
-
const result = await roomService.getRoomPermissions(roomName, { roomKey });
|
|
438
|
-
|
|
439
|
-
expect(result).toEqual(roomPermissionsPayload);
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
describe("getRoomMetrics", () => {
|
|
445
|
-
const roomName = "/some-room-name";
|
|
446
|
-
const metrics = "totalMeetings";
|
|
447
|
-
const roomMetricsPayload = { roomName, metrics };
|
|
448
|
-
|
|
449
|
-
itShouldThrowIfInvalid("roomName", () => {
|
|
450
|
-
roomService.getRoomMetrics({});
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
itShouldThrowIfInvalid("metrics", () => {
|
|
454
|
-
roomService.getRoomMetrics({ roomName });
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
itShouldRejectIfApiClientRejects(
|
|
458
|
-
() => organizationApiClient,
|
|
459
|
-
() => {
|
|
460
|
-
return roomService.getRoomMetrics(roomMetricsPayload);
|
|
461
|
-
}
|
|
462
|
-
);
|
|
463
|
-
|
|
464
|
-
describe("when valid payload provided", () => {
|
|
465
|
-
it("should call request the expected parameters", async () => {
|
|
466
|
-
organizationApiClient.request.mockResolvedValue(
|
|
467
|
-
new Response({
|
|
468
|
-
status: 200,
|
|
469
|
-
data: {},
|
|
470
|
-
})
|
|
471
|
-
);
|
|
472
|
-
|
|
473
|
-
await roomService.getRoomMetrics(roomMetricsPayload);
|
|
474
|
-
|
|
475
|
-
expect(organizationApiClient.request).toBeCalledWith(
|
|
476
|
-
`/room/${encodeURIComponent(roomName.substring(1))}/metrics`,
|
|
477
|
-
{
|
|
478
|
-
method: "GET",
|
|
479
|
-
params: { metrics, from: undefined, to: undefined },
|
|
480
|
-
}
|
|
481
|
-
);
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
it("should call request the expected parameters when including from and to", async () => {
|
|
485
|
-
organizationApiClient.request.mockResolvedValue(
|
|
486
|
-
new Response({
|
|
487
|
-
status: 200,
|
|
488
|
-
data: {},
|
|
489
|
-
})
|
|
490
|
-
);
|
|
491
|
-
const from = new Date().toISOString();
|
|
492
|
-
const to = new Date().toISOString();
|
|
493
|
-
|
|
494
|
-
await roomService.getRoomMetrics({ ...roomMetricsPayload, from, to });
|
|
495
|
-
|
|
496
|
-
expect(organizationApiClient.request).toBeCalledWith(
|
|
497
|
-
`/room/${encodeURIComponent(roomName.substring(1))}/metrics`,
|
|
498
|
-
{
|
|
499
|
-
method: "GET",
|
|
500
|
-
params: { metrics, from, to },
|
|
501
|
-
}
|
|
502
|
-
);
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
it("should resolve with response data on success", async () => {
|
|
506
|
-
const responseData = Symbol();
|
|
507
|
-
organizationApiClient.request.mockResolvedValue(
|
|
508
|
-
new Response({
|
|
509
|
-
status: 200,
|
|
510
|
-
data: responseData,
|
|
511
|
-
})
|
|
512
|
-
);
|
|
513
|
-
|
|
514
|
-
const result = await roomService.getRoomMetrics(roomMetricsPayload);
|
|
515
|
-
|
|
516
|
-
expect(result).toEqual(responseData);
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
describe("updatePreferences", () => {
|
|
522
|
-
const roomName = "/foo";
|
|
523
|
-
let preferences;
|
|
524
|
-
|
|
525
|
-
beforeEach(() => {
|
|
526
|
-
preferences = { bar: Symbol() };
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
itShouldThrowIfInvalid("roomName", () => roomService.updatePreferences({ preferences }));
|
|
530
|
-
itShouldThrowIfInvalid("preferences", () => roomService.updatePreferences({ roomName }));
|
|
531
|
-
|
|
532
|
-
it("should call apiClient.request with the expected parameters", async () => {
|
|
533
|
-
const encodedDisplayName = encodeURIComponent(roomName.substring(1));
|
|
534
|
-
const url = `/room/${encodedDisplayName}/preferences`;
|
|
535
|
-
organizationApiClient.request.mockResolvedValue();
|
|
536
|
-
|
|
537
|
-
await roomService.updatePreferences({ roomName, preferences });
|
|
538
|
-
|
|
539
|
-
expect(organizationApiClient.request).toBeCalledWith(url, {
|
|
540
|
-
method: "PATCH",
|
|
541
|
-
data: preferences,
|
|
542
|
-
});
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
it("should be resolved if apiClient.request resolves", async () => {
|
|
546
|
-
organizationApiClient.request.mockResolvedValue();
|
|
547
|
-
|
|
548
|
-
const result = await roomService.updatePreferences({ roomName, preferences });
|
|
549
|
-
|
|
550
|
-
expect(result).toBeUndefined();
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
itShouldRejectIfApiClientRejects(
|
|
554
|
-
() => organizationApiClient,
|
|
555
|
-
() => {
|
|
556
|
-
return roomService.updatePreferences({ roomName, preferences });
|
|
557
|
-
}
|
|
558
|
-
);
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
describe("updateProtectedPreferences", () => {
|
|
562
|
-
const roomName = "/foo";
|
|
563
|
-
let preferences;
|
|
564
|
-
|
|
565
|
-
beforeEach(() => {
|
|
566
|
-
preferences = { bar: Symbol() };
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
itShouldThrowIfInvalid("roomName", () => roomService.updateProtectedPreferences({ preferences }));
|
|
570
|
-
itShouldThrowIfInvalid("preferences", () => roomService.updateProtectedPreferences({ roomName }));
|
|
571
|
-
|
|
572
|
-
it("should call apiClient.request with the expected parameters", async () => {
|
|
573
|
-
const encodedDisplayName = encodeURIComponent(roomName.substring(1));
|
|
574
|
-
const url = `/room/${encodedDisplayName}/protected-preferences`;
|
|
575
|
-
organizationApiClient.request.mockResolvedValue();
|
|
576
|
-
|
|
577
|
-
await roomService.updateProtectedPreferences({ roomName, preferences });
|
|
578
|
-
|
|
579
|
-
expect(organizationApiClient.request).toBeCalledWith(url, {
|
|
580
|
-
method: "PATCH",
|
|
581
|
-
data: preferences,
|
|
582
|
-
});
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
it("should be resolved if apiClient.request resolves", async () => {
|
|
586
|
-
organizationApiClient.request.mockResolvedValue();
|
|
587
|
-
|
|
588
|
-
const result = await roomService.updateProtectedPreferences({ roomName, preferences });
|
|
589
|
-
|
|
590
|
-
expect(result).toBeUndefined();
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
itShouldRejectIfApiClientRejects(
|
|
594
|
-
() => organizationApiClient,
|
|
595
|
-
() => {
|
|
596
|
-
return roomService.updateProtectedPreferences({ roomName, preferences });
|
|
597
|
-
}
|
|
598
|
-
);
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
describe("changeType", () => {
|
|
602
|
-
const roomName = "/foo";
|
|
603
|
-
const encodedDisplayName = encodeURIComponent(roomName.substring(1));
|
|
604
|
-
const url = `/room/${encodedDisplayName}/type`;
|
|
605
|
-
const method = "PUT";
|
|
606
|
-
const type = "personal";
|
|
607
|
-
const data = { type };
|
|
608
|
-
|
|
609
|
-
it("should call apiClient.request with the expected parameters", async () => {
|
|
610
|
-
organizationApiClient.request.mockResolvedValue();
|
|
611
|
-
|
|
612
|
-
await roomService.changeType({ roomName, type });
|
|
613
|
-
|
|
614
|
-
expect(organizationApiClient.request).toBeCalledWith(url, { method, data });
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
it("should be resolved if apiClient.request resolves", async () => {
|
|
618
|
-
organizationApiClient.request.mockResolvedValue();
|
|
619
|
-
|
|
620
|
-
const result = await roomService.changeType({ roomName, type });
|
|
621
|
-
|
|
622
|
-
expect(result).toBeUndefined();
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
itShouldRejectIfApiClientRejects(
|
|
626
|
-
() => organizationApiClient,
|
|
627
|
-
() => {
|
|
628
|
-
return roomService.changeType({ roomName, type });
|
|
629
|
-
}
|
|
630
|
-
);
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
describe("getForestSocialImage", () => {
|
|
634
|
-
const roomName = "/foo";
|
|
635
|
-
const count = 24;
|
|
636
|
-
const imageUrl = Symbol();
|
|
637
|
-
|
|
638
|
-
itShouldThrowIfInvalid("roomName", () => roomService.getForestSocialImage({ count }));
|
|
639
|
-
itShouldThrowIfInvalid("count", () => roomService.getForestSocialImage({ roomName }));
|
|
640
|
-
|
|
641
|
-
it("should call apiClient.request with the expected parameters", async () => {
|
|
642
|
-
const encodedDisplayName = encodeURIComponent(roomName.substring(1));
|
|
643
|
-
const url = `/room/${encodedDisplayName}/forest-social-image/${count}`;
|
|
644
|
-
organizationApiClient.request.mockResolvedValue({ data: { imageUrl } });
|
|
645
|
-
|
|
646
|
-
await roomService.getForestSocialImage({ roomName, count });
|
|
647
|
-
|
|
648
|
-
expect(organizationApiClient.request).toBeCalledWith(url, {
|
|
649
|
-
method: "GET",
|
|
650
|
-
});
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
it("should resolve with imageUrl if apiClient.request resolves", async () => {
|
|
654
|
-
organizationApiClient.request.mockResolvedValue({ data: { imageUrl } });
|
|
655
|
-
|
|
656
|
-
const result = await roomService.getForestSocialImage({ roomName, count });
|
|
657
|
-
|
|
658
|
-
expect(result).toEqual(imageUrl);
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
itShouldRejectIfApiClientRejects(
|
|
662
|
-
() => organizationApiClient,
|
|
663
|
-
() => {
|
|
664
|
-
return roomService.getForestSocialImage({ roomName, count });
|
|
665
|
-
}
|
|
666
|
-
);
|
|
667
|
-
});
|
|
668
|
-
});
|