-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy.spec.js
85 lines (73 loc) · 2.07 KB
/
dummy.spec.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* @jest-environment node
*/
import http from 'http';
import util from 'util';
import request from 'supertest';
import appPromise from '~/server/app';
import dummyAppPromise from '~/dummyService/app';
let dummyServer, appServer, pluginUuid;
beforeAll(async () => {
// start dummy service
dummyServer = http.createServer(await dummyAppPromise);
await util.promisify(dummyServer.listen).call(dummyServer, 0);
const dummyApiUrl = `http://localhost:${dummyServer.address().port}/api`;
// start DYD service
appServer = http.createServer(await appPromise);
await util.promisify(appServer.listen).call(appServer, 0);
// register dummy plugin
const res = await request(appServer)
.post('/api/plugin')
.send({
name: 'dummy_test_plugin',
type: 'Dummy',
config: { apiUrl: dummyApiUrl },
});
expect(res.statusCode).toEqual(200);
pluginUuid = res.body.uuid;
});
afterAll(async () => {
// unregister dummy plugin
const res = await request(appServer)
.delete(`/api/plugin/${pluginUuid}`)
.send();
// stop DYD service
await util.promisify(appServer.close).call(appServer);
// stop dummy service
await util.promisify(dummyServer.close).call(dummyServer);
});
describe('Using the Dummy service', () => {
test('it works', async () => {
let accountUuid;
// create a user in the dummy service...
{
const res = await request(dummyServer)
.post('/api/account')
.send({
username: 'dummy_test_user',
});
expect(res.statusCode).toEqual(200);
}
// ...and register it in DYD
{
const res = await request(appServer)
.post('/api/account')
.send({
pluginUuid,
nativeId: 'dummy_test_user',
});
expect(res.statusCode).toEqual(200);
accountUuid = res.body.uuid;
}
// delete the user via DYD
{
const res = await request(appServer)
.post(`/api/account/redact`)
.send({
accounts: [accountUuid],
mode: 'DELETE',
});
expect(res.statusCode).toEqual(200);
}
});
});