]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/plugin-unloading.ts
We don't need to import mocha
[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
41137192 3import { expect } from 'chai'
254d3579
C
4import {
5 cleanupTests,
6 createSingleServer,
7 makeGetRequest,
8 PeerTubeServer,
9 PluginsCommand,
10 setAccessTokensToServers
bf54587a 11} from '@shared/server-commands'
4c7e60bc 12import { HttpStatusCode } from '@shared/models'
41137192
JL
13
14describe('Test plugins module unloading', function () {
254d3579 15 let server: PeerTubeServer = null
41137192
JL
16 const requestPath = '/plugins/test-unloading/router/get'
17 let value: string = null
18
19 before(async function () {
20 this.timeout(30000)
21
254d3579 22 server = await createSingleServer(1)
41137192
JL
23 await setAccessTokensToServers([ server ])
24
89d241a7 25 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
41137192
JL
26 })
27
28 it('Should return a numeric value', async function () {
29 const res = await makeGetRequest({
30 url: server.url,
31 path: requestPath,
c0e8b12e 32 expectedStatus: HttpStatusCode.OK_200
41137192
JL
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,
c0e8b12e 43 expectedStatus: HttpStatusCode.OK_200
41137192
JL
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 () {
89d241a7 50 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-unloading' })
41137192
JL
51
52 await makeGetRequest({
53 url: server.url,
54 path: requestPath,
c0e8b12e 55 expectedStatus: HttpStatusCode.NOT_FOUND_404
41137192
JL
56 })
57 })
58
59 it('Should return a different numeric value', async function () {
89d241a7 60 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
ae2abfd3 61
41137192
JL
62 const res = await makeGetRequest({
63 url: server.url,
64 path: requestPath,
c0e8b12e 65 expectedStatus: HttpStatusCode.OK_200
41137192
JL
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})