aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/plugin-unloading.ts
blob: f430f82b82f8f79c372c1604d77a5c76f04f8f2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'

describe('Test plugins module unloading', function () {
  let server: ServerInfo = null
  const requestPath = '/plugins/test-unloading/router/get'
  let value: string = null

  before(async function () {
    this.timeout(30000)

    server = await flushAndRunServer(1)
    await setAccessTokensToServers([ server ])

    await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
  })

  it('Should return a numeric value', async function () {
    const res = await makeGetRequest({
      url: server.url,
      path: requestPath,
      statusCodeExpected: HttpStatusCode.OK_200
    })

    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,
      statusCodeExpected: HttpStatusCode.OK_200
    })

    expect(res.body.message).to.be.equal(value)
  })

  it('Should uninstall the plugin and free the route', async function () {
    await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-unloading' })

    await makeGetRequest({
      url: server.url,
      path: requestPath,
      statusCodeExpected: HttpStatusCode.NOT_FOUND_404
    })
  })

  it('Should return a different numeric value', async function () {
    await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') })

    const res = await makeGetRequest({
      url: server.url,
      path: requestPath,
      statusCodeExpected: HttpStatusCode.OK_200
    })

    expect(res.body.message).to.match(/^\d+$/)
    expect(res.body.message).to.be.not.equal(value)
  })

  after(async function () {
    await cleanupTests([ server ])
  })
})