aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/plugin-helpers.ts
blob: dfe8ebe555d11c6addf2e2b10ebb3db915c1206c (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
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
import {
  checkVideoFilesWereRemoved,
  getPluginTestPath,
  getVideo,
  installPlugin,
  setAccessTokensToServers,
  uploadVideoAndGetId,
  viewVideo
} from '../../../shared/extra-utils'

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

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

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

    await installPlugin({
      url: server.url,
      accessToken: server.accessToken,
      path: getPluginTestPath('-four')
    })
  })

  it('Should have logged things', async function () {
    await waitUntilLog(server, 'localhost:' + server.port + ' peertube-plugin-test-four', 1, false)
    await waitUntilLog(server, 'Hello world from plugin four', 1)
  })

  it('Should have made a query', async function () {
    await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1)
  })

  it('Should remove a video after a view', async function () {
    this.timeout(20000)

    const videoUUID = (await uploadVideoAndGetId({ server: server, videoName: 'video1' })).uuid

    // Should not throw -> video exists
    await getVideo(server.url, videoUUID)
    // Should delete the video
    await viewVideo(server.url, videoUUID)

    await waitUntilLog(server, 'Video deleted by plugin four.', 1)

    try {
      // Should throw because the video should have been deleted
      await getVideo(server.url, videoUUID)
      throw new Error('Video exists')
    } catch (err) {
      if (err.message.includes('exists')) throw err
    }

    await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber)
  })

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