]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/plugin-helpers.ts
dfe8ebe555d11c6addf2e2b10ebb3db915c1206c
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / plugin-helpers.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
5 import {
6 checkVideoFilesWereRemoved,
7 getPluginTestPath,
8 getVideo,
9 installPlugin,
10 setAccessTokensToServers,
11 uploadVideoAndGetId,
12 viewVideo
13 } from '../../../shared/extra-utils'
14
15 describe('Test plugin helpers', function () {
16 let server: ServerInfo
17
18 before(async function () {
19 this.timeout(30000)
20
21 server = await flushAndRunServer(1)
22 await setAccessTokensToServers([ server ])
23
24 await installPlugin({
25 url: server.url,
26 accessToken: server.accessToken,
27 path: getPluginTestPath('-four')
28 })
29 })
30
31 it('Should have logged things', async function () {
32 await waitUntilLog(server, 'localhost:' + server.port + ' peertube-plugin-test-four', 1, false)
33 await waitUntilLog(server, 'Hello world from plugin four', 1)
34 })
35
36 it('Should have made a query', async function () {
37 await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1)
38 })
39
40 it('Should remove a video after a view', async function () {
41 this.timeout(20000)
42
43 const videoUUID = (await uploadVideoAndGetId({ server: server, videoName: 'video1' })).uuid
44
45 // Should not throw -> video exists
46 await getVideo(server.url, videoUUID)
47 // Should delete the video
48 await viewVideo(server.url, videoUUID)
49
50 await waitUntilLog(server, 'Video deleted by plugin four.', 1)
51
52 try {
53 // Should throw because the video should have been deleted
54 await getVideo(server.url, videoUUID)
55 throw new Error('Video exists')
56 } catch (err) {
57 if (err.message.includes('exists')) throw err
58 }
59
60 await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber)
61 })
62
63 after(async function () {
64 await cleanupTests([ server ])
65 })
66 })