@prisme.ai/sdk 1.0.0 → 1.0.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.
- package/Readme.md +3 -1
- package/dist/_virtual/_tslib.js +17 -8
- package/dist/lib/ImportProcessing.d.ts +19 -0
- package/dist/lib/WorkspacesEndpoint.d.ts +10 -0
- package/dist/lib/api.d.ts +88 -29
- package/dist/lib/endpoints/users.d.ts +13 -0
- package/dist/lib/endpoints/workspaces.d.ts +16 -0
- package/dist/lib/endpoints/workspacesVersions.d.ts +2 -2
- package/dist/lib/events.d.ts +5 -1
- package/dist/lib/fetch.d.ts +2 -0
- package/dist/lib/fetcher.d.ts +11 -3
- package/dist/lib/interpolate.d.ts +2 -0
- package/dist/lib/interpolate.test.d.ts +1 -0
- package/dist/lib/interpolateVars.d.ts +2 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/sdk/lib/ImportProcessing.js +17 -0
- package/dist/sdk/lib/WorkspacesEndpoint.js +19 -0
- package/dist/sdk/lib/api.js +248 -62
- package/dist/sdk/lib/endpoints/users.js +94 -0
- package/dist/sdk/lib/endpoints/workspaces.js +121 -0
- package/dist/sdk/lib/endpoints/workspacesVersions.js +4 -4
- package/dist/sdk/lib/events.js +51 -13
- package/dist/sdk/lib/fetch.js +12 -0
- package/dist/sdk/lib/fetcher.js +98 -42
- package/dist/sdk/lib/interpolate.js +26 -0
- package/dist/sdk/lib/interpolateVars.js +26 -0
- package/dist/sdk/lib/utils.js +48 -1
- package/lib/ImportProcessing.ts +22 -0
- package/lib/api.test.ts +90 -60
- package/lib/api.ts +318 -79
- package/lib/endpoints/users.ts +58 -0
- package/lib/endpoints/workspaces.ts +103 -0
- package/lib/endpoints/workspacesVersions.ts +13 -9
- package/lib/events.test.ts +2 -2
- package/lib/events.ts +60 -14
- package/lib/fetcher.ts +77 -12
- package/lib/utils.ts +39 -0
- package/package.json +3 -1
package/lib/api.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import api, { Api } from './api';
|
|
2
2
|
import ApiError from './ApiError';
|
|
3
|
+
import UsersEndpoint from './endpoints/users';
|
|
3
4
|
import WorkspacesEndpoint from './endpoints/workspaces';
|
|
4
5
|
import WorkspacesVersionsEndpoint from './endpoints/workspacesVersions';
|
|
5
6
|
|
|
@@ -30,7 +31,7 @@ it('should export an instance', () => {
|
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
it('should call /me', async () => {
|
|
33
|
-
const api = new Api('/fake/');
|
|
34
|
+
const api = new Api({ host: '/fake/' });
|
|
34
35
|
api.get = jest.fn(
|
|
35
36
|
async () =>
|
|
36
37
|
({
|
|
@@ -42,18 +43,8 @@ it('should call /me', async () => {
|
|
|
42
43
|
expect(api.user).toBe(me);
|
|
43
44
|
});
|
|
44
45
|
|
|
45
|
-
it('should call /signin', () => {
|
|
46
|
-
const api = new Api('/fake/');
|
|
47
|
-
api.post = jest.fn();
|
|
48
|
-
api.signin('user@fake.com', 'password');
|
|
49
|
-
expect(api.post).toHaveBeenCalledWith('/login', {
|
|
50
|
-
email: 'user@fake.com',
|
|
51
|
-
password: 'password',
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
46
|
it('should call /login/anonymous', async () => {
|
|
56
|
-
const api = new Api('/fake/');
|
|
47
|
+
const api = new Api({ host: '/fake/' });
|
|
57
48
|
api.post = jest.fn();
|
|
58
49
|
const user = await api.createAnonymousSession();
|
|
59
50
|
expect(api.post).toHaveBeenCalledWith('/login/anonymous');
|
|
@@ -61,7 +52,7 @@ it('should call /login/anonymous', async () => {
|
|
|
61
52
|
});
|
|
62
53
|
|
|
63
54
|
it('should call /signup', () => {
|
|
64
|
-
const api = new Api('/fake/');
|
|
55
|
+
const api = new Api({ host: '/fake/' });
|
|
65
56
|
api.post = jest.fn();
|
|
66
57
|
api.signup('user@fake.com', 'password', 'firstname', 'lastname', 'fr');
|
|
67
58
|
expect(api.post).toHaveBeenCalledWith('/signup', {
|
|
@@ -73,30 +64,22 @@ it('should call /signup', () => {
|
|
|
73
64
|
});
|
|
74
65
|
});
|
|
75
66
|
|
|
76
|
-
it('should call /signout', () => {
|
|
77
|
-
const api = new Api('/fake/');
|
|
78
|
-
api.post = jest.fn();
|
|
79
|
-
api.signout();
|
|
80
|
-
expect(api.post).toHaveBeenCalledWith('/logout');
|
|
81
|
-
expect(api.token).toBeNull();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
67
|
it('should call get /workspaces', () => {
|
|
85
|
-
const api = new Api('/fake/');
|
|
68
|
+
const api = new Api({ host: '/fake/' });
|
|
86
69
|
api.get = jest.fn();
|
|
87
70
|
api.getWorkspaces();
|
|
88
71
|
expect(api.get).toHaveBeenCalledWith('/workspaces?limit=600');
|
|
89
72
|
});
|
|
90
73
|
|
|
91
74
|
it('should call get /workspaces/42', () => {
|
|
92
|
-
const api = new Api('/fake/');
|
|
75
|
+
const api = new Api({ host: '/fake/' });
|
|
93
76
|
api.get = jest.fn();
|
|
94
77
|
api.getWorkspace('42');
|
|
95
78
|
expect(api.get).toHaveBeenCalledWith('/workspaces/42');
|
|
96
79
|
});
|
|
97
80
|
|
|
98
81
|
it('should call post /workspaces', () => {
|
|
99
|
-
const api = new Api('/fake/');
|
|
82
|
+
const api = new Api({ host: '/fake/' });
|
|
100
83
|
api.post = jest.fn();
|
|
101
84
|
api.createWorkspace('foo');
|
|
102
85
|
expect(api.post).toHaveBeenCalledWith('/workspaces', {
|
|
@@ -105,7 +88,7 @@ it('should call post /workspaces', () => {
|
|
|
105
88
|
});
|
|
106
89
|
|
|
107
90
|
it('should call patch /workspaces/42', async () => {
|
|
108
|
-
const api = new Api('/fake/');
|
|
91
|
+
const api = new Api({ host: '/fake/' });
|
|
109
92
|
api.patch = jest.fn();
|
|
110
93
|
await api.updateWorkspace({
|
|
111
94
|
id: '42',
|
|
@@ -124,14 +107,14 @@ it('should call patch /workspaces/42', async () => {
|
|
|
124
107
|
});
|
|
125
108
|
|
|
126
109
|
it('should call delete /workspaces/42', async () => {
|
|
127
|
-
const api = new Api('/fake/');
|
|
110
|
+
const api = new Api({ host: '/fake/' });
|
|
128
111
|
api.delete = jest.fn();
|
|
129
112
|
await api.deleteWorkspace('42');
|
|
130
113
|
expect(api.delete).toHaveBeenCalledWith('/workspaces/42');
|
|
131
114
|
});
|
|
132
115
|
|
|
133
116
|
it('should call post /workspaces/42/automations', () => {
|
|
134
|
-
const api = new Api('/fake/');
|
|
117
|
+
const api = new Api({ host: '/fake/' });
|
|
135
118
|
api.post = jest.fn();
|
|
136
119
|
api.createAutomation('42', {
|
|
137
120
|
name: 'foo',
|
|
@@ -144,7 +127,7 @@ it('should call post /workspaces/42/automations', () => {
|
|
|
144
127
|
});
|
|
145
128
|
|
|
146
129
|
it('should call patch /workspaces/42/automations', async () => {
|
|
147
|
-
const api = new Api('/fake/');
|
|
130
|
+
const api = new Api({ host: '/fake/' });
|
|
148
131
|
api.patch = jest.fn();
|
|
149
132
|
await api.updateAutomation('42', '42-1', {
|
|
150
133
|
name: 'foo',
|
|
@@ -157,14 +140,14 @@ it('should call patch /workspaces/42/automations', async () => {
|
|
|
157
140
|
});
|
|
158
141
|
|
|
159
142
|
it('should call delete /workspaces/42/automations/42-1', () => {
|
|
160
|
-
const api = new Api('/fake/');
|
|
143
|
+
const api = new Api({ host: '/fake/' });
|
|
161
144
|
api.delete = jest.fn();
|
|
162
145
|
api.deleteAutomation('42', '42-1');
|
|
163
146
|
expect(api.delete).toHaveBeenCalledWith('/workspaces/42/automations/42-1');
|
|
164
147
|
});
|
|
165
148
|
|
|
166
149
|
it('should call get /workspaces/42/events', async () => {
|
|
167
|
-
const api = new Api('/fake/');
|
|
150
|
+
const api = new Api({ host: '/fake/' });
|
|
168
151
|
api.get = jest.fn(
|
|
169
152
|
async (): Promise<any> => ({
|
|
170
153
|
result: {
|
|
@@ -186,7 +169,7 @@ it('should call get /workspaces/42/events', async () => {
|
|
|
186
169
|
});
|
|
187
170
|
|
|
188
171
|
it('should replace all images data', async () => {
|
|
189
|
-
const api = new Api('/fake/');
|
|
172
|
+
const api = new Api({ host: '/fake/' });
|
|
190
173
|
api.uploadFiles = jest.fn(async () => [
|
|
191
174
|
{ url: 'http://image1.jpg' } as any,
|
|
192
175
|
{ url: 'http://image2.jpg' } as any,
|
|
@@ -230,7 +213,7 @@ it('should replace all images data', async () => {
|
|
|
230
213
|
});
|
|
231
214
|
|
|
232
215
|
it('should upload file', async () => {
|
|
233
|
-
const api = new Api('/fake/');
|
|
216
|
+
const api = new Api({ host: '/fake/' });
|
|
234
217
|
// @ts-ignore
|
|
235
218
|
api._fetch = jest.fn(() => [{}]);
|
|
236
219
|
await api.uploadFiles(
|
|
@@ -250,7 +233,7 @@ it('should upload file', async () => {
|
|
|
250
233
|
});
|
|
251
234
|
|
|
252
235
|
it('should generate api key', async () => {
|
|
253
|
-
const api = new Api('/fake/');
|
|
236
|
+
const api = new Api({ host: '/fake/' });
|
|
254
237
|
api.post = jest.fn((): any => ({
|
|
255
238
|
apiKey: 'api-key',
|
|
256
239
|
}));
|
|
@@ -286,7 +269,7 @@ it('should generate api key', async () => {
|
|
|
286
269
|
});
|
|
287
270
|
|
|
288
271
|
it('should update api key', async () => {
|
|
289
|
-
const api = new Api('/fake/');
|
|
272
|
+
const api = new Api({ host: '/fake/' });
|
|
290
273
|
api.put = jest.fn((): any => ({
|
|
291
274
|
apiKey: 'api-key',
|
|
292
275
|
}));
|
|
@@ -327,7 +310,7 @@ it('should update api key', async () => {
|
|
|
327
310
|
});
|
|
328
311
|
|
|
329
312
|
it('should send validation mail', () => {
|
|
330
|
-
const api = new Api('/fake/');
|
|
313
|
+
const api = new Api({ host: '/fake/' });
|
|
331
314
|
api.post = jest.fn();
|
|
332
315
|
api.sendValidationMail('email', 'fr');
|
|
333
316
|
expect(api.post).toHaveBeenCalledWith('/user/validate', {
|
|
@@ -337,7 +320,7 @@ it('should send validation mail', () => {
|
|
|
337
320
|
});
|
|
338
321
|
|
|
339
322
|
it('should validate mail', () => {
|
|
340
|
-
const api = new Api('/fake/');
|
|
323
|
+
const api = new Api({ host: '/fake/' });
|
|
341
324
|
api.post = jest.fn();
|
|
342
325
|
api.validateMail('token');
|
|
343
326
|
expect(api.post).toHaveBeenCalledWith('/user/validate', {
|
|
@@ -346,7 +329,7 @@ it('should validate mail', () => {
|
|
|
346
329
|
});
|
|
347
330
|
|
|
348
331
|
it('should send password reset mail', () => {
|
|
349
|
-
const api = new Api('/fake/');
|
|
332
|
+
const api = new Api({ host: '/fake/' });
|
|
350
333
|
api.post = jest.fn();
|
|
351
334
|
api.sendPasswordResetMail('email', 'fr');
|
|
352
335
|
expect(api.post).toHaveBeenCalledWith('/user/password', {
|
|
@@ -356,7 +339,7 @@ it('should send password reset mail', () => {
|
|
|
356
339
|
});
|
|
357
340
|
|
|
358
341
|
it('should reset password', () => {
|
|
359
|
-
const api = new Api('/fake/');
|
|
342
|
+
const api = new Api({ host: '/fake/' });
|
|
360
343
|
api.post = jest.fn();
|
|
361
344
|
api.passwordReset('token', 'azerty');
|
|
362
345
|
expect(api.post).toHaveBeenCalledWith('/user/password', {
|
|
@@ -366,7 +349,7 @@ it('should reset password', () => {
|
|
|
366
349
|
});
|
|
367
350
|
|
|
368
351
|
it('should get pages', async () => {
|
|
369
|
-
const api = new Api('/fake/');
|
|
352
|
+
const api = new Api({ host: '/fake/' });
|
|
370
353
|
api.get = jest.fn((): any => [
|
|
371
354
|
{
|
|
372
355
|
id: '123',
|
|
@@ -388,28 +371,28 @@ it('should get pages', async () => {
|
|
|
388
371
|
});
|
|
389
372
|
|
|
390
373
|
it('should get page', () => {
|
|
391
|
-
const api = new Api('/fake/');
|
|
374
|
+
const api = new Api({ host: '/fake/' });
|
|
392
375
|
api.get = jest.fn((): any => ({}));
|
|
393
376
|
api.getPage('42', '123');
|
|
394
377
|
expect(api.get).toHaveBeenCalledWith('/workspaces/42/pages/123');
|
|
395
378
|
});
|
|
396
379
|
|
|
397
380
|
it('should get page by slug', () => {
|
|
398
|
-
const api = new Api('/fake/');
|
|
381
|
+
const api = new Api({ host: '/fake/' });
|
|
399
382
|
api.get = jest.fn((): any => ({}));
|
|
400
383
|
api.getPageBySlug('42', '123');
|
|
401
384
|
expect(api.get).toHaveBeenCalledWith('/pages/42/123');
|
|
402
385
|
});
|
|
403
386
|
|
|
404
387
|
it('should create page', () => {
|
|
405
|
-
const api = new Api('/fake/');
|
|
388
|
+
const api = new Api({ host: '/fake/' });
|
|
406
389
|
api.post = jest.fn((): any => ({}));
|
|
407
390
|
api.createPage('42', {} as Prismeai.Page);
|
|
408
391
|
expect(api.post).toHaveBeenCalledWith(`/workspaces/42/pages`, {});
|
|
409
392
|
});
|
|
410
393
|
|
|
411
394
|
it('should update page', async () => {
|
|
412
|
-
const api = new Api('/fake/');
|
|
395
|
+
const api = new Api({ host: '/fake/' });
|
|
413
396
|
api.patch = jest.fn((): any => ({ slug: 'my-page' }));
|
|
414
397
|
await api.updatePage('42', { id: '123', slug: 'my-page' } as Prismeai.Page);
|
|
415
398
|
expect(api.patch).toHaveBeenCalledWith(`/workspaces/42/pages/my-page`, {
|
|
@@ -419,14 +402,14 @@ it('should update page', async () => {
|
|
|
419
402
|
});
|
|
420
403
|
|
|
421
404
|
it('should delete page', () => {
|
|
422
|
-
const api = new Api('/fake/');
|
|
405
|
+
const api = new Api({ host: '/fake/' });
|
|
423
406
|
api.delete = jest.fn((): any => ({ id: '123' }));
|
|
424
407
|
api.deletePage('42', '123');
|
|
425
408
|
expect(api.delete).toHaveBeenCalledWith('/workspaces/42/pages/123');
|
|
426
409
|
});
|
|
427
410
|
|
|
428
411
|
it('should stream events', async () => {
|
|
429
|
-
const api = new Api('/fake/');
|
|
412
|
+
const api = new Api({ host: '/fake/' });
|
|
430
413
|
|
|
431
414
|
const events = await api.streamEvents('42');
|
|
432
415
|
expect((events.constructor as any).mockedConstructor).toHaveBeenCalledWith({
|
|
@@ -436,6 +419,7 @@ it('should stream events', async () => {
|
|
|
436
419
|
apiHost: '/fake/',
|
|
437
420
|
filters: undefined,
|
|
438
421
|
api,
|
|
422
|
+
legacyToken: '',
|
|
439
423
|
});
|
|
440
424
|
expect(events.once).toHaveBeenCalled();
|
|
441
425
|
(events.constructor as any).mockedConstructor.mockClear();
|
|
@@ -448,6 +432,7 @@ it('should stream events', async () => {
|
|
|
448
432
|
apiHost: '/fake/',
|
|
449
433
|
filters: {},
|
|
450
434
|
api,
|
|
435
|
+
legacyToken: '',
|
|
451
436
|
});
|
|
452
437
|
expect(events2.once).toHaveBeenCalled();
|
|
453
438
|
|
|
@@ -465,6 +450,7 @@ it('should stream events', async () => {
|
|
|
465
450
|
'source.sessionId': 'session id',
|
|
466
451
|
},
|
|
467
452
|
api,
|
|
453
|
+
legacyToken: '',
|
|
468
454
|
});
|
|
469
455
|
expect(events3.once).toHaveBeenCalled();
|
|
470
456
|
|
|
@@ -480,12 +466,13 @@ it('should stream events', async () => {
|
|
|
480
466
|
apiHost: '/fake/',
|
|
481
467
|
filters: undefined,
|
|
482
468
|
api,
|
|
469
|
+
legacyToken: '',
|
|
483
470
|
});
|
|
484
471
|
expect(events3.close).toHaveBeenCalled();
|
|
485
472
|
});
|
|
486
473
|
|
|
487
474
|
it('should get events', async () => {
|
|
488
|
-
const api = new Api('/fake/');
|
|
475
|
+
const api = new Api({ host: '/fake/' });
|
|
489
476
|
api.get = jest.fn((): any => ({
|
|
490
477
|
result: { events: [{ createdAt: '2022-01-01', id: '123' }] },
|
|
491
478
|
}));
|
|
@@ -504,7 +491,7 @@ it('should get events', async () => {
|
|
|
504
491
|
});
|
|
505
492
|
|
|
506
493
|
it('should post events', async () => {
|
|
507
|
-
const api = new Api('/fake/');
|
|
494
|
+
const api = new Api({ host: '/fake/' });
|
|
508
495
|
api.post = jest.fn((): any => {});
|
|
509
496
|
const res = await api.postEvents('42', [
|
|
510
497
|
{
|
|
@@ -535,7 +522,7 @@ it('should post events', async () => {
|
|
|
535
522
|
});
|
|
536
523
|
|
|
537
524
|
describe('permissions', () => {
|
|
538
|
-
const api = new Api('/fake/');
|
|
525
|
+
const api = new Api({ host: '/fake/' });
|
|
539
526
|
api.get = jest.fn((path: string): any => {
|
|
540
527
|
if (path === '/pages/id/permissions') {
|
|
541
528
|
return {
|
|
@@ -600,7 +587,7 @@ describe('permissions', () => {
|
|
|
600
587
|
});
|
|
601
588
|
|
|
602
589
|
it('should get apps', async () => {
|
|
603
|
-
const api = new Api('/fake/');
|
|
590
|
+
const api = new Api({ host: '/fake/' });
|
|
604
591
|
const get: jest.Mock = (api.get = jest.fn((): any => {}));
|
|
605
592
|
api.getApps({});
|
|
606
593
|
expect(api.get).toHaveBeenCalledWith('/apps?');
|
|
@@ -617,7 +604,7 @@ it('should get apps', async () => {
|
|
|
617
604
|
});
|
|
618
605
|
|
|
619
606
|
it('should install app', async () => {
|
|
620
|
-
const api = new Api('/fake/');
|
|
607
|
+
const api = new Api({ host: '/fake/' });
|
|
621
608
|
api.post = jest.fn((): any => {});
|
|
622
609
|
api.installApp('42', { appSlug: 'app' });
|
|
623
610
|
expect(api.post).toHaveBeenCalledWith('/workspaces/42/apps', {
|
|
@@ -626,7 +613,7 @@ it('should install app', async () => {
|
|
|
626
613
|
});
|
|
627
614
|
|
|
628
615
|
it('should update app', async () => {
|
|
629
|
-
const api = new Api('/fake/');
|
|
616
|
+
const api = new Api({ host: '/fake/' });
|
|
630
617
|
api.patch = jest.fn((): any => {});
|
|
631
618
|
api.updateApp('42', 'app', { appSlug: 'app' });
|
|
632
619
|
expect(api.patch).toHaveBeenCalledWith('/workspaces/42/apps/app', {
|
|
@@ -635,49 +622,49 @@ it('should update app', async () => {
|
|
|
635
622
|
});
|
|
636
623
|
|
|
637
624
|
it('should uninstall app', async () => {
|
|
638
|
-
const api = new Api('/fake/');
|
|
625
|
+
const api = new Api({ host: '/fake/' });
|
|
639
626
|
api.delete = jest.fn((): any => {});
|
|
640
627
|
api.uninstallApp('42', 'app');
|
|
641
628
|
expect(api.delete).toHaveBeenCalledWith('/workspaces/42/apps/app');
|
|
642
629
|
});
|
|
643
630
|
|
|
644
631
|
it('should publish app', async () => {
|
|
645
|
-
const api = new Api('/fake/');
|
|
632
|
+
const api = new Api({ host: '/fake/' });
|
|
646
633
|
api.post = jest.fn((): any => {});
|
|
647
634
|
api.publishApp({ workspaceId: '42' });
|
|
648
635
|
expect(api.post).toHaveBeenCalledWith('/apps', { workspaceId: '42' });
|
|
649
636
|
});
|
|
650
637
|
|
|
651
638
|
it('should list app instances', async () => {
|
|
652
|
-
const api = new Api('/fake/');
|
|
639
|
+
const api = new Api({ host: '/fake/' });
|
|
653
640
|
api.get = jest.fn((): any => {});
|
|
654
641
|
api.listAppInstances('42');
|
|
655
642
|
expect(api.get).toHaveBeenCalledWith('/workspaces/42/apps');
|
|
656
643
|
});
|
|
657
644
|
|
|
658
645
|
it('should get app config', async () => {
|
|
659
|
-
const api = new Api('/fake/');
|
|
646
|
+
const api = new Api({ host: '/fake/' });
|
|
660
647
|
api.get = jest.fn((): any => {});
|
|
661
648
|
api.getAppConfig('42', 'app');
|
|
662
649
|
expect(api.get).toHaveBeenCalledWith('/workspaces/42/apps/app/config');
|
|
663
650
|
});
|
|
664
651
|
|
|
665
652
|
it('should update app config', async () => {
|
|
666
|
-
const api = new Api('/fake/');
|
|
653
|
+
const api = new Api({ host: '/fake/' });
|
|
667
654
|
api.patch = jest.fn((): any => {});
|
|
668
655
|
api.updateAppConfig('42', 'app', {});
|
|
669
656
|
expect(api.patch).toHaveBeenCalledWith('/workspaces/42/apps/app/config', {});
|
|
670
657
|
});
|
|
671
658
|
|
|
672
659
|
it('should save app instance', async () => {
|
|
673
|
-
const api = new Api('/fake/');
|
|
660
|
+
const api = new Api({ host: '/fake/' });
|
|
674
661
|
api.patch = jest.fn((): any => {});
|
|
675
662
|
api.saveAppInstance('42', 'app', {});
|
|
676
663
|
expect(api.patch).toHaveBeenCalledWith('/workspaces/42/apps/app', {});
|
|
677
664
|
});
|
|
678
665
|
|
|
679
666
|
it('should upload files', async () => {
|
|
680
|
-
const api = new Api('/fake/');
|
|
667
|
+
const api = new Api({ host: '/fake/' });
|
|
681
668
|
// @ts-ignore
|
|
682
669
|
let fetch: jest.Mock = (api._fetch = jest.fn((): any => {}));
|
|
683
670
|
api.uploadFiles('data:text/plain;base64,SGVsbG8gV29ybGQ', '42');
|
|
@@ -706,7 +693,7 @@ it('should upload files', async () => {
|
|
|
706
693
|
});
|
|
707
694
|
|
|
708
695
|
it('should call automation', () => {
|
|
709
|
-
const api = new Api('/fake/');
|
|
696
|
+
const api = new Api({ host: '/fake/' });
|
|
710
697
|
api.post = jest.fn((): any => {});
|
|
711
698
|
api.callAutomation('42', 'automation');
|
|
712
699
|
expect(api.post).toHaveBeenCalledWith(
|
|
@@ -715,8 +702,27 @@ it('should call automation', () => {
|
|
|
715
702
|
);
|
|
716
703
|
});
|
|
717
704
|
|
|
705
|
+
it('should get automation from url', () => {
|
|
706
|
+
api.host = 'https://host.com';
|
|
707
|
+
expect(api.getAutomationFromUrl('13234', 'https://www.prisme.ai')).toBe(
|
|
708
|
+
false
|
|
709
|
+
);
|
|
710
|
+
expect(
|
|
711
|
+
api.getAutomationFromUrl(
|
|
712
|
+
'1234',
|
|
713
|
+
'https://host.com/workspaces/1234/webhooks/endpoint'
|
|
714
|
+
)
|
|
715
|
+
).toBe('endpoint');
|
|
716
|
+
expect(
|
|
717
|
+
api.getAutomationFromUrl(
|
|
718
|
+
'1235',
|
|
719
|
+
'https://host.com/workspaces/1234/webhooks/endpoint'
|
|
720
|
+
)
|
|
721
|
+
).toBe(false);
|
|
722
|
+
});
|
|
723
|
+
|
|
718
724
|
it('should get workspace usage', () => {
|
|
719
|
-
const api = new Api('/fake/');
|
|
725
|
+
const api = new Api({ host: '/fake/' });
|
|
720
726
|
const get: jest.Mock = (api.get = jest.fn((): any => {}));
|
|
721
727
|
api.getWorkspaceUsage('42');
|
|
722
728
|
expect(api.get).toHaveBeenCalledWith('/workspaces/42/usage?');
|
|
@@ -755,3 +761,27 @@ describe('Workspaces', () => {
|
|
|
755
761
|
});
|
|
756
762
|
});
|
|
757
763
|
});
|
|
764
|
+
|
|
765
|
+
describe('User', () => {
|
|
766
|
+
it('should access user methods', () => {
|
|
767
|
+
expect(api.users('42')).toBeInstanceOf(UsersEndpoint);
|
|
768
|
+
});
|
|
769
|
+
it('should access user methods with current user', () => {
|
|
770
|
+
// @ts-ignore
|
|
771
|
+
api._user = { id: '42' } as any;
|
|
772
|
+
expect(api.users()).toBeInstanceOf(UsersEndpoint);
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
it('should set meta data', () => {
|
|
776
|
+
api.post = jest.fn();
|
|
777
|
+
api.users().setMeta('foo', 'bar');
|
|
778
|
+
expect(api.post).toHaveBeenCalledWith('/user/meta', {
|
|
779
|
+
foo: 'bar',
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
it('should delete meta data', () => {
|
|
783
|
+
api.delete = jest.fn();
|
|
784
|
+
api.users().deleteMeta('foo');
|
|
785
|
+
expect(api.delete).toHaveBeenCalledWith('/user/meta/foo');
|
|
786
|
+
});
|
|
787
|
+
});
|