aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-09 11:35:29 +0200
committerChocobozzz <me@florianbigard.com>2020-04-09 11:37:44 +0200
commitab3ead3a6f080e6768b898e699c8de92703d93c6 (patch)
treed335ad83d47341b43ca842c319f21eaefdcc78e4 /server/tests
parent1b05d82d861f42c27766e9f24d8d55e68b0cf098 (diff)
downloadPeerTube-ab3ead3a6f080e6768b898e699c8de92703d93c6.tar.gz
PeerTube-ab3ead3a6f080e6768b898e699c8de92703d93c6.tar.zst
PeerTube-ab3ead3a6f080e6768b898e699c8de92703d93c6.zip
Add ability to remove a video from a plugin
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/peertube-plugin-test-four/main.js18
-rw-r--r--server/tests/plugins/plugin-helpers.ts36
2 files changed, 47 insertions, 7 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js
index 9abb73646..2e81550c1 100644
--- a/server/tests/fixtures/peertube-plugin-test-four/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-four/main.js
@@ -1,7 +1,10 @@
1async function register ({ 1async function register ({
2 peertubeHelpers 2 peertubeHelpers,
3 registerHook
3}) { 4}) {
4 peertubeHelpers.logger.info('Hello world from plugin four') 5 const logger = peertubeHelpers.logger
6
7 logger.info('Hello world from plugin four')
5 8
6 const username = 'root' 9 const username = 'root'
7 const results = await peertubeHelpers.database.query( 10 const results = await peertubeHelpers.database.query(
@@ -12,7 +15,16 @@ async function register ({
12 } 15 }
13 ) 16 )
14 17
15 peertubeHelpers.logger.info('root email is ' + results[0]['email']) 18 logger.info('root email is ' + results[0]['email'])
19
20 registerHook({
21 target: 'action:api.video.viewed',
22 handler: async ({ video }) => {
23 await peertubeHelpers.videos.removeVideo(video.id)
24
25 logger.info('Video deleted by plugin four.')
26 }
27 })
16} 28}
17 29
18async function unregister () { 30async function unregister () {
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index 05928273f..dfe8ebe55 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -1,11 +1,16 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 4import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
6import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils' 5import {
7 6 checkVideoFilesWereRemoved,
8const expect = chai.expect 7 getPluginTestPath,
8 getVideo,
9 installPlugin,
10 setAccessTokensToServers,
11 uploadVideoAndGetId,
12 viewVideo
13} from '../../../shared/extra-utils'
9 14
10describe('Test plugin helpers', function () { 15describe('Test plugin helpers', function () {
11 let server: ServerInfo 16 let server: ServerInfo
@@ -32,6 +37,29 @@ describe('Test plugin helpers', function () {
32 await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1) 37 await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1)
33 }) 38 })
34 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
35 after(async function () { 63 after(async function () {
36 await cleanupTests([ server ]) 64 await cleanupTests([ server ])
37 }) 65 })