From 3cabf3532b9118a19311f14ca3e171d12d554a2f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 6 Nov 2020 13:59:50 +0100 Subject: Add live server hooks --- server/tests/fixtures/peertube-plugin-test/main.js | 25 +++++++++---- server/tests/plugins/action-hooks.ts | 43 +++++++++++++++++----- server/tests/plugins/filter-hooks.ts | 23 ++++++++++++ 3 files changed, 73 insertions(+), 18 deletions(-) (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index a45e98fb5..322c0610c 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js @@ -7,6 +7,8 @@ async function register ({ registerHook, registerSetting, settingsManager, stora 'action:api.video.uploaded', 'action:api.video.viewed', + 'action:api.live-video.created', + 'action:api.video-thread.created', 'action:api.video-comment-reply.created', 'action:api.video-comment.deleted', @@ -46,15 +48,22 @@ async function register ({ registerHook, registerSetting, settingsManager, stora } }) - registerHook({ - target: 'filter:api.video.upload.accept.result', - handler: ({ accepted }, { videoBody }) => { - if (!accepted) return { accepted: false } - if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' } + for (const hook of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) { + registerHook({ + target: hook, + handler: ({ accepted }, { videoBody, liveVideoBody }) => { + if (!accepted) return { accepted: false } - return { accepted: true } - } - }) + const name = videoBody + ? videoBody.name + : liveVideoBody.name + + if (name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' } + + return { accepted: true } + } + }) + } registerHook({ target: 'filter:api.video.pre-import-url.accept.result', diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index ca57a4b51..ac9f2cea5 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -1,18 +1,12 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { - cleanupTests, - flushAndRunMultipleServers, - killallServers, - reRunServer, - ServerInfo, - waitUntilLog -} from '../../../shared/extra-utils/server/servers' +import { ServerHookName, VideoPrivacy } from '@shared/models' import { addVideoCommentReply, addVideoCommentThread, blockUser, + createLive, createUser, deleteVideoComment, getPluginTestPath, @@ -20,6 +14,7 @@ import { registerUser, removeUser, setAccessTokensToServers, + setDefaultVideoChannel, unblockUser, updateUser, updateVideo, @@ -27,13 +22,21 @@ import { userLogin, viewVideo } from '../../../shared/extra-utils' +import { + cleanupTests, + flushAndRunMultipleServers, + killallServers, + reRunServer, + ServerInfo, + waitUntilLog +} from '../../../shared/extra-utils/server/servers' describe('Test plugin action hooks', function () { let servers: ServerInfo[] let videoUUID: string let threadId: number - function checkHook (hook: string) { + function checkHook (hook: ServerHookName) { return waitUntilLog(servers[0], 'Run hook ' + hook) } @@ -42,6 +45,7 @@ describe('Test plugin action hooks', function () { servers = await flushAndRunMultipleServers(2) await setAccessTokensToServers(servers) + await setDefaultVideoChannel(servers) await installPlugin({ url: servers[0].url, @@ -51,7 +55,11 @@ describe('Test plugin action hooks', function () { killallServers([ servers[0] ]) - await reRunServer(servers[0]) + await reRunServer(servers[0], { + live: { + enabled: true + } + }) }) describe('Application hooks', function () { @@ -81,6 +89,21 @@ describe('Test plugin action hooks', function () { }) }) + describe('Live hooks', function () { + + it('Should run action:api.live-video.created', async function () { + const attributes = { + name: 'live', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].videoChannel.id + } + + await createLive(servers[0].url, servers[0].accessToken, attributes) + + await checkHook('action:api.live-video.created') + }) + }) + describe('Comments hooks', function () { it('Should run action:api.video-thread.created', async function () { const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 4d354b68e..9939b8e6e 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -6,6 +6,7 @@ import { ServerConfig } from '@shared/models' import { addVideoCommentReply, addVideoCommentThread, + createLive, doubleFollow, getConfig, getPluginTestPath, @@ -19,6 +20,7 @@ import { registerUser, setAccessTokensToServers, setDefaultVideoChannel, + updateCustomSubConfig, updateVideo, uploadVideo, waitJobs @@ -61,6 +63,17 @@ describe('Test plugin filter hooks', function () { const res = await getVideosList(servers[0].url) videoUUID = res.body.data[0].uuid + + await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { + live: { enabled: true }, + signup: { enabled: true }, + import: { + videos: { + http: { enabled: true }, + torrent: { enabled: true } + } + } + }) }) it('Should run filter:api.videos.list.params', async function () { @@ -87,6 +100,16 @@ describe('Test plugin filter hooks', function () { await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403) }) + it('Should run filter:api.live-video.create.accept.result', async function () { + const attributes = { + name: 'video with bad word', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].videoChannel.id + } + + await createLive(servers[0].url, servers[0].accessToken, attributes, 403) + }) + it('Should run filter:api.video.pre-import-url.accept.result', async function () { const baseAttributes = { name: 'normal title', -- cgit v1.2.3