This repository was archived by the owner on Nov 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathplugin.test.js
More file actions
145 lines (114 loc) · 3.52 KB
/
plugin.test.js
File metadata and controls
145 lines (114 loc) · 3.52 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* eslint-env jest */
const path = require('path');
// mock config for testing
jest.mock('../src/config', () => require('./__mocks__/config'));
jest.mock('../src/util', () => require('./__mocks__/util'));
jest.mock('./fixtures/plugins/node_modules/testplugin', () => require('./__mocks__/testplugin'), {virtual: true});
const config = require('../src/config');
// switch config to plugins
config.__load('plugins');
// npm packages
const getPort = require('get-port');
// our packages
const authToken = require('./fixtures/authToken');
const {dbLoaded} = require('../src/db');
const {initPlugins, getPlugins} = require('../src/plugins');
const {initDocker} = require('../src/docker/init');
const {start, startFromParams} = require('../src/docker/start');
const {startServer} = require('../src');
// test project path
const testProjectPath = path.join(__dirname, 'fixtures', 'html-project');
// options base
const options = {
method: 'GET',
headers: {
Authorization: `Bearer ${authToken}`,
},
};
beforeAll(async done => {
await dbLoaded;
await initPlugins();
done();
});
test('Should init plugins', async done => {
const plugins = getPlugins();
expect(plugins.length).toEqual(1);
const testPlugin = plugins[0];
expect(testPlugin).toMatchSnapshot();
done();
});
test('init', async done => {
await initDocker();
const plugins = getPlugins();
const testPlugin = plugins[0];
expect(testPlugin.init).toBeCalled();
done();
});
test('start', async done => {
await start({image: 'test', username: 'admin', folder: testProjectPath, resultStream: {}});
const plugins = getPlugins();
const testPlugin = plugins[0];
expect(testPlugin.start).toBeCalled();
done();
});
test('startFromParams', async done => {
await startFromParams({
image: 'test',
deploymentName: 'test-deploy',
projectName: 'test-project',
username: 'admin',
backendName: 'back',
frontend: 'front',
hostname: 'host',
restartPolicy: 'always',
});
const plugins = getPlugins();
const testPlugin = plugins[0];
expect(testPlugin.startFromParams).toBeCalled();
done();
});
test('list', async done => {
// start server
const port = await getPort();
const fastify = await startServer(port);
const response = await fastify.inject({...options, url: '/list'});
const result = JSON.parse(response.payload);
// check response
expect(result).toBeDefined();
expect(response.statusCode).toEqual(200);
const plugins = getPlugins();
const testPlugin = plugins[0];
expect(testPlugin.list).toBeCalled();
await fastify.close();
done();
});
test('logs', async done => {
// start server
const port = await getPort();
const fastify = await startServer(port);
const response = await fastify.inject({...options, url: '/logs/test'});
const result = JSON.parse(response.payload);
// check response
expect(result).toBeDefined();
expect(response.statusCode).toEqual(200);
const plugins = getPlugins();
const testPlugin = plugins[0];
expect(testPlugin.logs).toBeCalled();
await fastify.close();
done();
});
test('remove', async done => {
// start server
const port = await getPort();
const fastify = await startServer(port);
const response = await fastify.inject({...options, method: 'POST', url: `/remove/test`});
const result = JSON.parse(response.payload);
// check response
expect(result).toBeDefined();
expect(response.statusCode).toEqual(200);
const plugins = getPlugins();
const testPlugin = plugins[0];
expect(testPlugin.remove).toBeCalled();
await fastify.close();
done();
});