aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli/plugins.ts
blob: efdc20748232f559cf1307f96b8ea5c9c3f4f7a3 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import { expect } from 'chai'
import {
  cleanupTests,
  flushAndRunServer,
  getConfig,
  getPluginTestPath,
  killallServers,
  reRunServer,
  ServerInfo,
  setAccessTokensToServers
} from '../../../shared/extra-utils'
import { ServerConfig } from '../../../shared/models/server'

describe('Test plugin scripts', function () {
  let server: ServerInfo

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

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

  it('Should install a plugin from stateless CLI', async function () {
    this.timeout(60000)

    const packagePath = getPluginTestPath()

    await server.cliCommand.execWithEnv(`npm run plugin:install -- --plugin-path ${packagePath}`)
  })

  it('Should install a theme from stateless CLI', async function () {
    this.timeout(60000)

    await server.cliCommand.execWithEnv(`npm run plugin:install -- --npm-name peertube-theme-background-red`)
  })

  it('Should have the theme and the plugin registered when we restart peertube', async function () {
    this.timeout(30000)

    killallServers([ server ])
    await reRunServer(server)

    const res = await getConfig(server.url)
    const config: ServerConfig = res.body

    const plugin = config.plugin.registered
                         .find(p => p.name === 'test')
    expect(plugin).to.not.be.undefined

    const theme = config.theme.registered
                        .find(t => t.name === 'background-red')
    expect(theme).to.not.be.undefined
  })

  it('Should uninstall a plugin from stateless CLI', async function () {
    this.timeout(60000)

    await server.cliCommand.execWithEnv(`npm run plugin:uninstall -- --npm-name peertube-plugin-test`)
  })

  it('Should have removed the plugin on another peertube restart', async function () {
    this.timeout(30000)

    killallServers([ server ])
    await reRunServer(server)

    const res = await getConfig(server.url)
    const config: ServerConfig = res.body

    const plugin = config.plugin.registered
                         .find(p => p.name === 'test')
    expect(plugin).to.be.undefined
  })

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