-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamplePlugin.test.ts
More file actions
66 lines (59 loc) · 2.28 KB
/
samplePlugin.test.ts
File metadata and controls
66 lines (59 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import boiler from '@pryv/boiler';
import { init as initTestServer, apiTest, partnerAuth, createOnboardedUser } from './helpers/testServer.ts';
import SampleBridge from './sample-bridge/index.ts';
import assert from 'node:assert/strict';
const { getConfig } = boiler;
describe('[PLTX] SampleBridge test', () => {
let mainStreamId: string | null = null;
before(async () => {
await initTestServer(new SampleBridge());
// get the main streamId for the userPermissionRequest servic
const config = await getConfig();
const firsStream = (config.get('service:userPermissionRequest') as any[])[0];
mainStreamId = firsStream.streamId;
});
it('[PLTP] Create data POST /data/test/{userId}', async function () {
this.timeout(3000);
const userInfos = await createOnboardedUser();
// -- Check OK on post data
const newData = [{
type: 'note/txt',
content: 'Hello world'
}];
const resultEvents = await apiTest()
.post(`/data/test/${userInfos.partnerUserId}`)
.set(partnerAuth())
.send(newData);
assert.equal(resultEvents.body.length, 1);
const event = resultEvents.body[0].event;
assert.ok(event);
assert.equal(event.type, 'note/txt');
assert.equal(event.content, 'Hello world');
assert.equal(event.streamId, mainStreamId);
// -- Wait for status to be updated
await new Promise((resolve) => setTimeout(resolve, 500));
// -- Check sync status
const statusRes = await apiTest()
.get(`/user/${userInfos.partnerUserId}/status`)
.set(partnerAuth());
const syncStatus = statusRes.body.syncStatus;
assert.equal(syncStatus.lastSync, event.modified);
assert.deepEqual(syncStatus.content, { createdEventId: event.id, pluginVersion: 0 });
});
it('[PLTA] Call the API POST /data/test/{userId}/api', async () => {
const userInfos = await createOnboardedUser();
// -- Check OK on simple api call
const apiCalls = [{
method: 'streams.get',
params: {}
}];
const resultEvents = await apiTest()
.post(`/data/test/${userInfos.partnerUserId}/api`)
.set(partnerAuth())
.send(apiCalls);
assert.equal(resultEvents.body.length, 1);
const streams = resultEvents.body[0].streams;
assert.ok(streams);
assert.equal(streams[0].id, mainStreamId);
});
});