]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/plugin-unloading.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / plugin-unloading.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { expect } from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
6 import {
7 cleanupTests,
8 createSingleServer,
9 makeGetRequest,
10 PeerTubeServer,
11 PluginsCommand,
12 setAccessTokensToServers
13 } from '@shared/extra-utils'
14
15 describe('Test plugins module unloading', function () {
16 let server: PeerTubeServer = null
17 const requestPath = '/plugins/test-unloading/router/get'
18 let value: string = null
19
20 before(async function () {
21 this.timeout(30000)
22
23 server = await createSingleServer(1)
24 await setAccessTokensToServers([ server ])
25
26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
27 })
28
29 it('Should return a numeric value', async function () {
30 const res = await makeGetRequest({
31 url: server.url,
32 path: requestPath,
33 statusCodeExpected: HttpStatusCode.OK_200
34 })
35
36 expect(res.body.message).to.match(/^\d+$/)
37 value = res.body.message
38 })
39
40 it('Should return the same value the second time', async function () {
41 const res = await makeGetRequest({
42 url: server.url,
43 path: requestPath,
44 statusCodeExpected: HttpStatusCode.OK_200
45 })
46
47 expect(res.body.message).to.be.equal(value)
48 })
49
50 it('Should uninstall the plugin and free the route', async function () {
51 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-unloading' })
52
53 await makeGetRequest({
54 url: server.url,
55 path: requestPath,
56 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
57 })
58 })
59
60 it('Should return a different numeric value', async function () {
61 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
62
63 const res = await makeGetRequest({
64 url: server.url,
65 path: requestPath,
66 statusCodeExpected: HttpStatusCode.OK_200
67 })
68
69 expect(res.body.message).to.match(/^\d+$/)
70 expect(res.body.message).to.be.not.equal(value)
71 })
72
73 after(async function () {
74 await cleanupTests([ server ])
75 })
76 })