]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/plugin-unloading.ts
Fix server run
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / plugin-unloading.ts
CommitLineData
41137192
JL
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
41137192 4import { expect } from 'chai'
ae2abfd3 5import { HttpStatusCode } from '@shared/core-utils'
254d3579
C
6import {
7 cleanupTests,
8 createSingleServer,
9 makeGetRequest,
10 PeerTubeServer,
11 PluginsCommand,
12 setAccessTokensToServers
13} from '@shared/extra-utils'
41137192
JL
14
15describe('Test plugins module unloading', function () {
254d3579 16 let server: PeerTubeServer = null
41137192
JL
17 const requestPath = '/plugins/test-unloading/router/get'
18 let value: string = null
19
20 before(async function () {
21 this.timeout(30000)
22
254d3579 23 server = await createSingleServer(1)
41137192
JL
24 await setAccessTokensToServers([ server ])
25
89d241a7 26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
41137192
JL
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 () {
89d241a7 51 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-unloading' })
41137192
JL
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 () {
89d241a7 61 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
ae2abfd3 62
41137192
JL
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})