diff options
Diffstat (limited to 'packages/tests/src/plugins/plugin-unloading.ts')
-rw-r--r-- | packages/tests/src/plugins/plugin-unloading.ts | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/packages/tests/src/plugins/plugin-unloading.ts b/packages/tests/src/plugins/plugin-unloading.ts new file mode 100644 index 000000000..70310bc8c --- /dev/null +++ b/packages/tests/src/plugins/plugin-unloading.ts | |||
@@ -0,0 +1,75 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { | ||
5 | cleanupTests, | ||
6 | createSingleServer, | ||
7 | makeGetRequest, | ||
8 | PeerTubeServer, | ||
9 | PluginsCommand, | ||
10 | setAccessTokensToServers | ||
11 | } from '@peertube/peertube-server-commands' | ||
12 | import { HttpStatusCode } from '@peertube/peertube-models' | ||
13 | |||
14 | describe('Test plugins module unloading', function () { | ||
15 | let server: PeerTubeServer = null | ||
16 | const requestPath = '/plugins/test-unloading/router/get' | ||
17 | let value: string = null | ||
18 | |||
19 | before(async function () { | ||
20 | this.timeout(30000) | ||
21 | |||
22 | server = await createSingleServer(1) | ||
23 | await setAccessTokensToServers([ server ]) | ||
24 | |||
25 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) | ||
26 | }) | ||
27 | |||
28 | it('Should return a numeric value', async function () { | ||
29 | const res = await makeGetRequest({ | ||
30 | url: server.url, | ||
31 | path: requestPath, | ||
32 | expectedStatus: HttpStatusCode.OK_200 | ||
33 | }) | ||
34 | |||
35 | expect(res.body.message).to.match(/^\d+$/) | ||
36 | value = res.body.message | ||
37 | }) | ||
38 | |||
39 | it('Should return the same value the second time', async function () { | ||
40 | const res = await makeGetRequest({ | ||
41 | url: server.url, | ||
42 | path: requestPath, | ||
43 | expectedStatus: HttpStatusCode.OK_200 | ||
44 | }) | ||
45 | |||
46 | expect(res.body.message).to.be.equal(value) | ||
47 | }) | ||
48 | |||
49 | it('Should uninstall the plugin and free the route', async function () { | ||
50 | await server.plugins.uninstall({ npmName: 'peertube-plugin-test-unloading' }) | ||
51 | |||
52 | await makeGetRequest({ | ||
53 | url: server.url, | ||
54 | path: requestPath, | ||
55 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | ||
56 | }) | ||
57 | }) | ||
58 | |||
59 | it('Should return a different numeric value', async function () { | ||
60 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) | ||
61 | |||
62 | const res = await makeGetRequest({ | ||
63 | url: server.url, | ||
64 | path: requestPath, | ||
65 | expectedStatus: HttpStatusCode.OK_200 | ||
66 | }) | ||
67 | |||
68 | expect(res.body.message).to.match(/^\d+$/) | ||
69 | expect(res.body.message).to.be.not.equal(value) | ||
70 | }) | ||
71 | |||
72 | after(async function () { | ||
73 | await cleanupTests([ server ]) | ||
74 | }) | ||
75 | }) | ||