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

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 (72) hide show
  1. package/dist/lib.cjs.js +5467 -0
  2. package/dist/lib.esm.js +5451 -0
  3. package/dist/types.d.ts +104 -0
  4. package/dist/v2-alpha2.js +105 -0
  5. package/package.json +6 -1
  6. package/.eslintrc +0 -23
  7. package/.github/actions/build/action.yml +0 -17
  8. package/.github/workflows/deploy.yml +0 -102
  9. package/.github/workflows/test.yml +0 -24
  10. package/.prettierignore +0 -7
  11. package/.prettierrc +0 -4
  12. package/.storybook/main.cjs +0 -16
  13. package/.storybook/preview.js +0 -9
  14. package/jest.config.js +0 -6
  15. package/rollup.config.js +0 -70
  16. package/src/lib/RoomConnection.ts +0 -516
  17. package/src/lib/RoomParticipant.ts +0 -77
  18. package/src/lib/__tests__/embed.unit.ts +0 -77
  19. package/src/lib/api/ApiClient.ts +0 -111
  20. package/src/lib/api/Credentials.ts +0 -45
  21. package/src/lib/api/HttpClient.ts +0 -95
  22. package/src/lib/api/MultipartHttpClient.ts +0 -53
  23. package/src/lib/api/OrganizationApiClient.ts +0 -64
  24. package/src/lib/api/Response.ts +0 -34
  25. package/src/lib/api/credentialsService/index.ts +0 -159
  26. package/src/lib/api/credentialsService/test/index.spec.ts +0 -181
  27. package/src/lib/api/deviceService/index.ts +0 -42
  28. package/src/lib/api/deviceService/tests/index.spec.ts +0 -74
  29. package/src/lib/api/extractUtils.ts +0 -160
  30. package/src/lib/api/index.ts +0 -8
  31. package/src/lib/api/localStorageWrapper/index.ts +0 -15
  32. package/src/lib/api/models/Account.ts +0 -48
  33. package/src/lib/api/models/Meeting.ts +0 -42
  34. package/src/lib/api/models/Organization.ts +0 -186
  35. package/src/lib/api/models/Room.ts +0 -44
  36. package/src/lib/api/models/account/EmbeddedFreeTierStatus.ts +0 -34
  37. package/src/lib/api/models/tests/Account.spec.ts +0 -128
  38. package/src/lib/api/models/tests/Organization.spec.ts +0 -161
  39. package/src/lib/api/models/tests/Room.spec.ts +0 -74
  40. package/src/lib/api/modules/AbstractStore.ts +0 -18
  41. package/src/lib/api/modules/ChromeStorageStore.ts +0 -44
  42. package/src/lib/api/modules/LocalStorageStore.ts +0 -57
  43. package/src/lib/api/modules/tests/ChromeStorageStore.spec.ts +0 -67
  44. package/src/lib/api/modules/tests/LocalStorageStore.spec.ts +0 -79
  45. package/src/lib/api/modules/tests/__mocks__/storage.ts +0 -24
  46. package/src/lib/api/organizationService/index.ts +0 -284
  47. package/src/lib/api/organizationService/tests/index.spec.ts +0 -781
  48. package/src/lib/api/organizationServiceCache/index.ts +0 -28
  49. package/src/lib/api/organizationServiceCache/tests/index.spec.ts +0 -101
  50. package/src/lib/api/parameterAssertUtils.ts +0 -166
  51. package/src/lib/api/roomService/index.ts +0 -310
  52. package/src/lib/api/roomService/tests/index.spec.ts +0 -668
  53. package/src/lib/api/test/ApiClient.spec.ts +0 -139
  54. package/src/lib/api/test/HttpClient.spec.ts +0 -120
  55. package/src/lib/api/test/MultipartHttpClient.spec.ts +0 -145
  56. package/src/lib/api/test/OrganizationApiClient.spec.ts +0 -132
  57. package/src/lib/api/test/extractUtils.spec.ts +0 -357
  58. package/src/lib/api/test/helpers.ts +0 -41
  59. package/src/lib/api/test/parameterAssertUtils.spec.ts +0 -265
  60. package/src/lib/api/types.ts +0 -6
  61. package/src/lib/embed.ts +0 -172
  62. package/src/lib/index.ts +0 -3
  63. package/src/lib/react/VideoElement.tsx +0 -16
  64. package/src/lib/react/index.ts +0 -3
  65. package/src/lib/react/useLocalMedia.ts +0 -25
  66. package/src/lib/react/useRoomConnection.ts +0 -92
  67. package/src/lib/reducer.ts +0 -142
  68. package/src/stories/custom-ui.stories.tsx +0 -133
  69. package/src/stories/prebuilt-ui.stories.tsx +0 -131
  70. package/src/stories/styles.css +0 -74
  71. package/src/types.d.ts +0 -175
  72. package/tsconfig.json +0 -30
@@ -1,357 +0,0 @@
1
- import {
2
- extractArray,
3
- extractArrayOfJson,
4
- extractBoolean,
5
- extractDate,
6
- extractJson,
7
- extractJsonWithTransform,
8
- extractNullOrDate,
9
- extractNullOrString,
10
- extractNumber,
11
- Extractor,
12
- extractString,
13
- nullOrTransform,
14
- Transformer,
15
- } from "../extractUtils";
16
- import assert from "assert";
17
- import { Json } from "../Response";
18
- import { assertString } from "../parameterAssertUtils";
19
- type User = { name: string; eyeColor: string | null; age: number; dob: Date };
20
- function toUser(data: Json): User {
21
- return {
22
- name: extractString(data, "name"),
23
- eyeColor: extractNullOrString(data, "eyeColor"),
24
- age: extractNumber(data, "age"),
25
- dob: extractDate(data, "dob"),
26
- };
27
- }
28
-
29
- type InvalidValue = { desc: string; value?: Json; expectedError?: string | RegExp };
30
- type ValidValue = { desc: string; value?: Json; expected: unknown };
31
- function itShouldThrowForValues(extract: Extractor<unknown>, values: ReadonlyArray<InvalidValue>) {
32
- assert.ok(typeof extract === "function", "extract must be a function");
33
-
34
- values.forEach(({ desc, value, expectedError }) => {
35
- it(`should throw for ${desc}`, () => {
36
- expect(() => {
37
- extract({ ...(value !== undefined && { prop: value }) }, "prop");
38
- }).toThrowError(expectedError || /prop<.*> is required/);
39
- });
40
- });
41
- }
42
-
43
- function itShouldExtractForValues(extract: Extractor<unknown>, values: ReadonlyArray<ValidValue>) {
44
- values.forEach(({ desc, value, expected }) => {
45
- it(`should extract ${desc} correctly`, () => {
46
- const result = extract({ ...(value !== undefined && { prop: value }) }, "prop");
47
-
48
- expect(result).toEqual(expected);
49
- });
50
- });
51
- }
52
-
53
- function testExtract(
54
- extract: Extractor<unknown>,
55
- {
56
- invalidValues,
57
- validValues,
58
- }: { invalidValues: ReadonlyArray<InvalidValue>; validValues: ReadonlyArray<ValidValue> }
59
- ) {
60
- itShouldThrowForValues(extract, invalidValues);
61
- itShouldExtractForValues(extract, validValues);
62
- [null, undefined, "string", 12].forEach((value) => {
63
- it(`should throw for ${value}`, () => {
64
- expect(() => {
65
- //@ts-expect-error
66
- extract(value, "prop");
67
- }).toThrowError(/prop<.*> is required|data must be a record/);
68
- });
69
- });
70
- }
71
-
72
- describe("extractUtils", () => {
73
- const nullValues: Array<ValidValue> = [
74
- { desc: "null", value: null, expected: null },
75
- { desc: "null", value: undefined, expected: null },
76
- ];
77
- const invalidNullValues: Array<InvalidValue> = [
78
- { desc: "null", value: null },
79
- { desc: "null", value: undefined },
80
- ];
81
- const validStringValues: ReadonlyArray<ValidValue> = [
82
- { desc: "string", value: "some-string", expected: "some-string" },
83
- ];
84
- const invalidStringValues: ReadonlyArray<InvalidValue> = [
85
- { desc: "boolean", value: true },
86
- { desc: "number", value: 12 },
87
- { desc: "empty object", value: {} },
88
- { desc: "empty array", value: [] },
89
- ];
90
-
91
- describe("extractBoolean", () => {
92
- testExtract(extractBoolean, {
93
- validValues: [
94
- { desc: "boolean - true", value: true, expected: true },
95
- { desc: "boolean - false", value: false, expected: false },
96
- ],
97
- invalidValues: (
98
- [
99
- { desc: "number", value: 0 },
100
- { desc: "string", value: "some-string" },
101
- { desc: "string - true", value: "true" },
102
- { desc: "string - false", value: "false" },
103
- { desc: "empty object", value: {} },
104
- { desc: "empty array", value: [] },
105
- ] as Array<InvalidValue>
106
- ).concat(invalidNullValues),
107
- });
108
- });
109
-
110
- describe("extractString", () => {
111
- testExtract(extractString, {
112
- validValues: validStringValues,
113
- invalidValues: invalidStringValues.concat(nullValues),
114
- });
115
- });
116
-
117
- describe("extractNullOrString", () => {
118
- testExtract(extractNullOrString, {
119
- validValues: validStringValues.concat(nullValues),
120
- invalidValues: invalidStringValues,
121
- });
122
- });
123
-
124
- describe("extractNumber", () => {
125
- testExtract(extractNumber, {
126
- validValues: [{ desc: "number", value: 12, expected: 12 }],
127
- invalidValues: invalidNullValues.concat([
128
- { desc: "boolean", value: true },
129
- { desc: "string", value: "some-string" },
130
- { desc: "empty object", value: {} },
131
- { desc: "empty array", value: [] },
132
- ]),
133
- });
134
- });
135
-
136
- const validDate = new Date("2022-01-01");
137
- const validDateValues: Array<ValidValue> = [{ desc: "date", value: validDate.toISOString(), expected: validDate }];
138
- const invalidDateValues: Array<InvalidValue> = [
139
- { desc: "boolean", value: true },
140
- { desc: "number", value: 12 },
141
- { desc: "invalid date string", value: "some-string", expectedError: "Invalid date for some-string" },
142
- { desc: "empty object", value: {} },
143
- { desc: "empty array", value: [] },
144
- ];
145
- describe("extractDate", () => {
146
- testExtract(extractDate, {
147
- validValues: validDateValues,
148
- invalidValues: invalidNullValues.concat(invalidDateValues),
149
- });
150
- });
151
-
152
- describe("extractNullOrDate", () => {
153
- testExtract(extractNullOrDate, {
154
- validValues: validDateValues.concat(nullValues),
155
- invalidValues: invalidDateValues,
156
- });
157
- });
158
-
159
- const invalidArrayValues: ReadonlyArray<InvalidValue> = [
160
- { desc: "boolean", value: true },
161
- { desc: "number", value: 12 },
162
- { desc: "string", value: "some-string" },
163
- { desc: "empty object", value: {} },
164
- ];
165
-
166
- describe("extractArrayOfJson", () => {
167
- testExtract(extractArrayOfJson, {
168
- validValues: [
169
- { desc: "empty array", value: [], expected: [] },
170
- { desc: "array with multiple elements", value: ["1", 2, true, {}], expected: ["1", 2, true, {}] },
171
- ],
172
- invalidValues: invalidArrayValues.concat(nullValues),
173
- });
174
- });
175
-
176
- describe("extractArray", () => {
177
- const invalidArrayValuesWithNullValues: ReadonlyArray<InvalidValue> = invalidArrayValues.concat(nullValues);
178
- describe("with Identity transformer", () => {
179
- testExtract((data, propertyName) => extractArray(data, propertyName, (json) => json), {
180
- validValues: [
181
- { desc: "empty array", value: [], expected: [] },
182
- { desc: "array with multiple elements", value: ["1", 2, true, {}], expected: ["1", 2, true, {}] },
183
- ],
184
- invalidValues: invalidArrayValuesWithNullValues,
185
- });
186
- });
187
-
188
- describe("with string transformer", () => {
189
- const invalidArrayStringValues: ReadonlyArray<InvalidValue> = [
190
- {
191
- desc: "array with number",
192
- value: [12],
193
- expectedError: "json<string> is required",
194
- },
195
- {
196
- desc: "array with object",
197
- value: [{}],
198
- expectedError: "json<string> is required",
199
- },
200
- ];
201
- testExtract(
202
- (data, propertyName) => extractArray(data, propertyName, (json) => assertString(json, "json")),
203
- {
204
- validValues: [
205
- { desc: "empty array", value: [], expected: [] },
206
- { desc: "empty array", value: ["some-id"], expected: ["some-id"] },
207
- ],
208
- invalidValues: invalidArrayStringValues.concat(invalidArrayValuesWithNullValues),
209
- }
210
- );
211
- });
212
-
213
- describe("with complex object transformer", () => {
214
- const dob = new Date("1965-01-01");
215
- const invalidUserArray: ReadonlyArray<InvalidValue> = [
216
- {
217
- desc: "array with invalid user object",
218
- value: [{}],
219
- expectedError: "name<string> is required",
220
- },
221
- {
222
- desc: "array with string",
223
- value: ["string"] as Json,
224
- expectedError: "data must be a record.",
225
- },
226
- ];
227
- testExtract((data, propertyName) => extractArray(data, propertyName, toUser), {
228
- validValues: [
229
- {
230
- desc: "only required",
231
- value: [
232
- { name: "some-name", age: 13, dob: dob.toISOString() },
233
- { name: "some-other-name", eyeColor: "brown", age: 40, dob: dob.toISOString() },
234
- ],
235
- expected: [
236
- { name: "some-name", age: 13, dob, eyeColor: null },
237
- { name: "some-other-name", eyeColor: "brown", age: 40, dob },
238
- ],
239
- },
240
- {
241
- desc: "empty array",
242
- value: [],
243
- expected: [],
244
- },
245
- ],
246
- invalidValues: invalidUserArray.concat(invalidArrayValuesWithNullValues),
247
- });
248
- });
249
- });
250
-
251
- const validJsonValues = nullValues.concat([
252
- { desc: "empty object", value: {}, expected: {} },
253
- {
254
- desc: "object with multiple elements",
255
- value: { string: "1", number: 2, boolean: true, object: {}, array: [] },
256
- expected: { string: "1", number: 2, boolean: true, object: {}, array: [] },
257
- },
258
- { desc: "boolean", value: true, expected: true },
259
- { desc: "number", value: 12, expected: 12 },
260
- { desc: "string", value: "some-string", expected: "some-string" },
261
- { desc: "empty array", value: [], expected: [] },
262
- ]);
263
- const invalidJsonValues: Array<InvalidValue> = [];
264
- describe("extractJson", () => {
265
- testExtract(extractJson, {
266
- validValues: validJsonValues,
267
- invalidValues: invalidJsonValues,
268
- });
269
- });
270
-
271
- describe("extractJsonWithTransform", () => {
272
- describe("with Identity transformer", () => {
273
- testExtract((data, propertyName) => extractJsonWithTransform(data, propertyName, (json) => json), {
274
- validValues: validJsonValues,
275
- invalidValues: invalidJsonValues,
276
- });
277
- });
278
-
279
- describe("with string transformer", () => {
280
- testExtract(
281
- (data, propertyName) =>
282
- extractJsonWithTransform(data, propertyName, (json) => extractString(json, "field")),
283
- {
284
- validValues: [{ desc: "string field", value: { field: "some-field" }, expected: "some-field" }],
285
- invalidValues: [
286
- { desc: "boolean field", value: { field: true }, expectedError: "field<string> is required" },
287
- { desc: "null field", value: { field: null }, expectedError: "field<string> is required" },
288
- ],
289
- }
290
- );
291
- });
292
-
293
- describe("with complex object transformer", () => {
294
- const dob = new Date("1965-01-01");
295
- testExtract((data, propertyName) => extractJsonWithTransform(data, propertyName, toUser), {
296
- validValues: [
297
- {
298
- desc: "only required",
299
- value: { name: "some-name", age: 13, dob: dob.toISOString() },
300
- expected: { name: "some-name", age: 13, dob, eyeColor: null },
301
- },
302
- {
303
- desc: "all properties",
304
- value: { name: "some-name", eyeColor: "brown", age: 40, dob: dob.toISOString() },
305
- expected: { name: "some-name", eyeColor: "brown", age: 40, dob },
306
- },
307
- ],
308
- invalidValues: [
309
- {
310
- desc: "empty object",
311
- value: {} as Json,
312
- expectedError: "name<string> is required",
313
- },
314
- {
315
- desc: "object without all fields",
316
- value: { name: "some name" } as Json,
317
- expectedError: "age<number> is required",
318
- },
319
- ],
320
- });
321
- });
322
- });
323
-
324
- describe("nullOrTransform", () => {
325
- const intToString: Transformer<string> = (int: Json) => {
326
- if (typeof int !== "number") {
327
- throw new Error("unexpected type");
328
- }
329
-
330
- return int.toString();
331
- };
332
-
333
- const nullOrIntToString = nullOrTransform(intToString);
334
-
335
- it("should return null if value is null", () => {
336
- const value = nullOrIntToString(null);
337
-
338
- expect(value).toEqual(null);
339
- });
340
-
341
- it("should return null if value is undefined", () => {
342
- //@ts-expect-error
343
- const value = nullOrIntToString(undefined);
344
-
345
- expect(value).toEqual(null);
346
- });
347
-
348
- it(
349
- "should return whatever value returned by the transformer if not null",
350
- () => {
351
- const value = nullOrIntToString(12);
352
-
353
- expect(value).toEqual("12");
354
- }
355
- );
356
- });
357
- });
@@ -1,41 +0,0 @@
1
- // @ts-nocheck
2
-
3
- import { Json } from "../Response";
4
-
5
- export const itShouldThrowIfInvalid = (missingPropertyName: string, func: () => void, regexMatcher?: RegExp): void => {
6
- const testingNoArguments = !missingPropertyName;
7
- const isOrAre = missingPropertyName[missingPropertyName.length - 1] === "s" ? "are" : "is";
8
- const scenario = testingNoArguments ? "arguments are missing" : `${missingPropertyName} ${isOrAre} invalid`;
9
- const expectedException = testingNoArguments
10
- ? undefined
11
- : regexMatcher || new RegExp(`${missingPropertyName}(<[\\w|]+>)? (is|are) required`);
12
- it(`should throw if ${scenario}`, () => {
13
- expect(() => {
14
- func();
15
- }).toThrowError(expectedException);
16
- });
17
- };
18
-
19
- export const itShouldRejectIfApiClientRejects = (getApiClient: any, func: () => void): void => {
20
- it("should fail if the request failed", async () => {
21
- const error = new Error("some error");
22
- getApiClient().request.mockRejectedValue(error);
23
-
24
- await expect(func()).rejects.toThrow(error);
25
- });
26
- };
27
-
28
- export const itShouldRejectIfMultipartRequestRejects = (getApiClient: any, func: () => void) => {
29
- it("should fail if the requestMultipart failed", () => {
30
- const error = new Error("some error");
31
- getApiClient().requestMultipart.rejects(error);
32
-
33
- const promise = func();
34
-
35
- return expect(promise).to.eventually.be.rejected().toBe(error);
36
- });
37
- };
38
-
39
- export function toJson(value: unknown): Json {
40
- return JSON.parse(JSON.stringify(value));
41
- }
@@ -1,265 +0,0 @@
1
- import assert from "assert";
2
- import {
3
- assertBoolean,
4
- assertRoomName,
5
- assertNumber,
6
- assertString,
7
- assertInstanceOf,
8
- assertOneOf,
9
- assertRecord,
10
- } from "../parameterAssertUtils";
11
-
12
- function forEachObject(object: Record<string, unknown>, func: (value: unknown, key: string) => void) {
13
- Object.keys(object).forEach((key) => func(object[key], key));
14
- }
15
- describe("parameterAssertUtils", () => {
16
- function itShouldThrowForValues(testValues: Record<string, unknown>, test: (desc: string, value: unknown) => void) {
17
- assert.ok(typeof test === "function", "test must be a function");
18
-
19
- forEachObject(testValues, (value, descriptionOfValue) => {
20
- it(`should throw for ${descriptionOfValue}`, () => {
21
- test(descriptionOfValue, value);
22
- });
23
- });
24
- }
25
-
26
- describe("assertBoolean", () => {
27
- itShouldThrowForValues(
28
- {
29
- string: "aaa",
30
- "number as string": "12",
31
- "boolean as string": "true",
32
- null: null,
33
- undefined: undefined, // eslint-disable-line object-shorthand
34
- Object: {},
35
- },
36
- (description: string, value: unknown) => {
37
- expect(() => {
38
- assertBoolean(value, description);
39
- }).toThrowError(`${description}<boolean> is required`);
40
- }
41
- );
42
-
43
- it("should return provided value if false", () => {
44
- const value = assertBoolean(false, "false value");
45
-
46
- expect(value).toBe(false);
47
- });
48
-
49
- it("should return provided value if true", () => {
50
- const value = assertBoolean(true, "true value");
51
-
52
- expect(value).toBe(true);
53
- });
54
- });
55
-
56
- describe("assertNumber", () => {
57
- itShouldThrowForValues(
58
- {
59
- string: "aaa",
60
- "number as string": "12",
61
- boolean: true,
62
- null: null,
63
- undefined: undefined, // eslint-disable-line object-shorthand
64
- Object: {},
65
- },
66
- (description, value) => {
67
- expect(() => {
68
- assertNumber(value, description);
69
- }).toThrowError(`${description}<number> is required`);
70
- }
71
- );
72
-
73
- it("should return provided number", () => {
74
- const someNumber = 12;
75
-
76
- const actualValue = assertNumber(12, "some number");
77
-
78
- expect(actualValue).toBe(someNumber);
79
- });
80
- });
81
-
82
- describe("assertString", () => {
83
- itShouldThrowForValues(
84
- {
85
- number: 1,
86
- boolean: true,
87
- null: null,
88
- undefined: undefined, // eslint-disable-line object-shorthand
89
- Object: {},
90
- },
91
- (description, value) => {
92
- expect(() => {
93
- assertString(value, description);
94
- }).toThrowError(`${description}<string> is required`);
95
- }
96
- );
97
-
98
- it("should return provided value if string", () => {
99
- const someString = "some-string";
100
-
101
- const actualValue = assertString(someString, "parameter name");
102
-
103
- expect(actualValue).toBe(someString);
104
- });
105
- });
106
-
107
- describe("assertRoomName", () => {
108
- itShouldThrowForValues(
109
- {
110
- number: 1,
111
- boolean: true,
112
- null: null,
113
- undefined: undefined, // eslint-disable-line object-shorthand
114
- Object: {},
115
- },
116
- (description, value) => {
117
- expect(() => {
118
- assertRoomName(value, description);
119
- }).toThrowError(`${description}<string> is required`);
120
- }
121
- );
122
-
123
- it("should throw error if roomName is not prefixed with slash", () => {
124
- expect(() => assertRoomName("not-prefixed")).toThrowError("roomName must begin with a '/'");
125
- });
126
-
127
- it("should return roomName if roomName is prefixed with slash", () => {
128
- const prefixedRoomName = "/some-prefix";
129
-
130
- const actualValue = assertRoomName(prefixedRoomName);
131
-
132
- expect(actualValue).toBe(prefixedRoomName);
133
- });
134
- });
135
-
136
- describe("assertInstanceOf", () => {
137
- class SomeOtherClass {
138
- _param: number;
139
- constructor(param: number) {
140
- this._param = param;
141
- }
142
- }
143
-
144
- class SomeClass {
145
- _param: string;
146
- constructor(param: string) {
147
- this._param = param;
148
- }
149
- }
150
-
151
- class SubSomeClass extends SomeClass {}
152
-
153
- forEachObject(
154
- {
155
- number: 1,
156
- boolean: true,
157
- null: null,
158
- undefined: undefined, // eslint-disable-line object-shorthand
159
- Object: {},
160
- someOtherClass: new SomeOtherClass(1212),
161
- },
162
- (value, description) => {
163
- it(`should throw if ${description} is not instanceof SomeClass`, () => {
164
- expect(() => {
165
- assertInstanceOf(value, SomeClass, "someClass");
166
- }).toThrowError("someClass<SomeClass> is required");
167
- });
168
- }
169
- );
170
-
171
- it("should throw with provided parameterName", () => {
172
- expect(() => {
173
- assertInstanceOf(null, SomeClass, "someParameterName");
174
- }).toThrowError("someParameterName<SomeClass> is required");
175
- });
176
-
177
- it(
178
- "should throw with parameterName = type (except that first character is lower-case) if none is provided",
179
- () => {
180
- expect(() => {
181
- assertInstanceOf(null, SomeClass);
182
- }).toThrowError("someClass<SomeClass> is required");
183
- }
184
- );
185
-
186
- it("should return value if instance of class", () => {
187
- const instance = new SomeClass("some value");
188
-
189
- const actualValue = assertInstanceOf(instance, SomeClass);
190
-
191
- expect(actualValue).toBe(instance);
192
- });
193
-
194
- it("should return value if instance of subclass", () => {
195
- const instance = new SubSomeClass("some value");
196
-
197
- const actualValue = assertInstanceOf(instance, SomeClass);
198
-
199
- expect(actualValue).toBe(instance);
200
- });
201
- });
202
-
203
- describe("assertOneOf", () => {
204
- const description = "testValue";
205
- const allowedValues = ["hi", "welcome"];
206
-
207
- it("should throw if no value is provided", () => {
208
- expect(() => {
209
- assertOneOf(undefined, allowedValues, description);
210
- }).toThrowError(`value is required`);
211
- });
212
-
213
- it("should throw if allowed values is not an array", () => {
214
- expect(() => {
215
- // @ts-expect-error
216
- assertOneOf("hi", true, description);
217
- }).toThrowError(`allowedValues<array> is required`);
218
- });
219
-
220
- it("should throw if provided value is not allowed value", () => {
221
- expect(() => {
222
- assertOneOf("hello", allowedValues, description);
223
- }).toThrowError(
224
- `${description}<string> must be one of the following: ${allowedValues.join(", ")}`
225
- );
226
- });
227
-
228
- it("should return value if it is allowed", () => {
229
- const value = allowedValues[0];
230
-
231
- expect(assertOneOf(value, allowedValues, description)).toBe(value);
232
- });
233
- });
234
-
235
- describe("assertRecord", () => {
236
- itShouldThrowForValues(
237
- {
238
- string: "aaa",
239
- "number as string": "12",
240
- "boolean as string": "true",
241
- null: null,
242
- undefined: undefined, // eslint-disable-line object-shorthand
243
- Array: [],
244
- },
245
- (description, value) => {
246
- expect(() => {
247
- assertRecord(value, description);
248
- }).toThrowError(`${description} must be a record`);
249
- }
250
- );
251
-
252
- it("should return provided value if {}", () => {
253
- const value = assertRecord({}, "emptyValue");
254
-
255
- expect(value).toEqual({});
256
- });
257
-
258
- it("should return provided value if contains some fields", () => {
259
- const o = { field: 1 };
260
- const value = assertRecord(o, "emptyValue");
261
-
262
- expect(value).toEqual(o);
263
- });
264
- });
265
- });
@@ -1,6 +0,0 @@
1
- export type UserConsentAction = "accepted" | "rejected" | null;
2
- export type ConsentGrantRequest = {
3
- readonly consentRevisionId: string;
4
- readonly action: UserConsentAction;
5
- };
6
-