aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/plugin-unloading.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/plugins/plugin-unloading.ts')
-rw-r--r--server/tests/plugins/plugin-unloading.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts
new file mode 100644
index 000000000..74ca82e2f
--- /dev/null
+++ b/server/tests/plugins/plugin-unloading.ts
@@ -0,0 +1,89 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import {
5 cleanupTests,
6 flushAndRunServer,
7 getPluginTestPath,
8 makeGetRequest,
9 installPlugin,
10 uninstallPlugin,
11 ServerInfo,
12 setAccessTokensToServers
13} from '../../../shared/extra-utils'
14import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
15import { expect } from 'chai'
16
17describe('Test plugins module unloading', function () {
18 let server: ServerInfo = null
19 const requestPath = '/plugins/test-unloading/router/get'
20 let value: string = null
21
22 before(async function () {
23 this.timeout(30000)
24
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
27
28 await installPlugin({
29 url: server.url,
30 accessToken: server.accessToken,
31 path: getPluginTestPath('-unloading')
32 })
33 })
34
35 it('Should return a numeric value', async function () {
36 const res = await makeGetRequest({
37 url: server.url,
38 path: requestPath,
39 statusCodeExpected: HttpStatusCode.OK_200
40 })
41
42 expect(res.body.message).to.match(/^\d+$/)
43 value = res.body.message
44 })
45
46 it('Should return the same value the second time', async function () {
47 const res = await makeGetRequest({
48 url: server.url,
49 path: requestPath,
50 statusCodeExpected: HttpStatusCode.OK_200
51 })
52
53 expect(res.body.message).to.be.equal(value)
54 })
55
56 it('Should uninstall the plugin and free the route', async function () {
57 await uninstallPlugin({
58 url: server.url,
59 accessToken: server.accessToken,
60 npmName: 'peertube-plugin-test-unloading'
61 })
62
63 await makeGetRequest({
64 url: server.url,
65 path: requestPath,
66 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
67 })
68 })
69
70 it('Should return a different numeric value', async function () {
71 await installPlugin({
72 url: server.url,
73 accessToken: server.accessToken,
74 path: getPluginTestPath('-unloading')
75 })
76 const res = await makeGetRequest({
77 url: server.url,
78 path: requestPath,
79 statusCodeExpected: HttpStatusCode.OK_200
80 })
81
82 expect(res.body.message).to.match(/^\d+$/)
83 expect(res.body.message).to.be.not.equal(value)
84 })
85
86 after(async function () {
87 await cleanupTests([ server ])
88 })
89})