2021-04-08 10:19:12 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import { expect } from 'chai'
|
2021-07-16 02:47:51 -05:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createSingleServer,
|
|
|
|
makeGetRequest,
|
|
|
|
PeerTubeServer,
|
|
|
|
PluginsCommand,
|
|
|
|
setAccessTokensToServers
|
2021-12-17 02:29:23 -06:00
|
|
|
} from '@shared/server-commands'
|
2021-07-16 07:27:30 -05:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2021-04-08 10:19:12 -05:00
|
|
|
|
|
|
|
describe('Test plugins module unloading', function () {
|
2021-07-16 02:47:51 -05:00
|
|
|
let server: PeerTubeServer = null
|
2021-04-08 10:19:12 -05:00
|
|
|
const requestPath = '/plugins/test-unloading/router/get'
|
|
|
|
let value: string = null
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 02:47:51 -05:00
|
|
|
server = await createSingleServer(1)
|
2021-04-08 10:19:12 -05:00
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
|
2021-04-08 10:19:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should return a numeric value', async function () {
|
|
|
|
const res = await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: requestPath,
|
2021-07-16 03:42:24 -05:00
|
|
|
expectedStatus: HttpStatusCode.OK_200
|
2021-04-08 10:19:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(res.body.message).to.match(/^\d+$/)
|
|
|
|
value = res.body.message
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should return the same value the second time', async function () {
|
|
|
|
const res = await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: requestPath,
|
2021-07-16 03:42:24 -05:00
|
|
|
expectedStatus: HttpStatusCode.OK_200
|
2021-04-08 10:19:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(res.body.message).to.be.equal(value)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should uninstall the plugin and free the route', async function () {
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.plugins.uninstall({ npmName: 'peertube-plugin-test-unloading' })
|
2021-04-08 10:19:12 -05:00
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: requestPath,
|
2021-07-16 03:42:24 -05:00
|
|
|
expectedStatus: HttpStatusCode.NOT_FOUND_404
|
2021-04-08 10:19:12 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should return a different numeric value', async function () {
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
|
2021-07-07 03:33:49 -05:00
|
|
|
|
2021-04-08 10:19:12 -05:00
|
|
|
const res = await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: requestPath,
|
2021-07-16 03:42:24 -05:00
|
|
|
expectedStatus: HttpStatusCode.OK_200
|
2021-04-08 10:19:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(res.body.message).to.match(/^\d+$/)
|
|
|
|
expect(res.body.message).to.be.not.equal(value)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|