diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-06 13:59:50 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | 3cabf3532b9118a19311f14ca3e171d12d554a2f (patch) | |
tree | 46072616df4623d91c87f648e4033b3f1d05d404 /server/tests | |
parent | c8f3cfeba7acc2ab9c5f03161d22856202a49326 (diff) | |
download | PeerTube-3cabf3532b9118a19311f14ca3e171d12d554a2f.tar.gz PeerTube-3cabf3532b9118a19311f14ca3e171d12d554a2f.tar.zst PeerTube-3cabf3532b9118a19311f14ca3e171d12d554a2f.zip |
Add live server hooks
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test/main.js | 25 | ||||
-rw-r--r-- | server/tests/plugins/action-hooks.ts | 43 | ||||
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 23 |
3 files changed, 73 insertions, 18 deletions
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 | |||
7 | 'action:api.video.uploaded', | 7 | 'action:api.video.uploaded', |
8 | 'action:api.video.viewed', | 8 | 'action:api.video.viewed', |
9 | 9 | ||
10 | 'action:api.live-video.created', | ||
11 | |||
10 | 'action:api.video-thread.created', | 12 | 'action:api.video-thread.created', |
11 | 'action:api.video-comment-reply.created', | 13 | 'action:api.video-comment-reply.created', |
12 | 'action:api.video-comment.deleted', | 14 | 'action:api.video-comment.deleted', |
@@ -46,15 +48,22 @@ async function register ({ registerHook, registerSetting, settingsManager, stora | |||
46 | } | 48 | } |
47 | }) | 49 | }) |
48 | 50 | ||
49 | registerHook({ | 51 | for (const hook of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) { |
50 | target: 'filter:api.video.upload.accept.result', | 52 | registerHook({ |
51 | handler: ({ accepted }, { videoBody }) => { | 53 | target: hook, |
52 | if (!accepted) return { accepted: false } | 54 | handler: ({ accepted }, { videoBody, liveVideoBody }) => { |
53 | if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' } | 55 | if (!accepted) return { accepted: false } |
54 | 56 | ||
55 | return { accepted: true } | 57 | const name = videoBody |
56 | } | 58 | ? videoBody.name |
57 | }) | 59 | : liveVideoBody.name |
60 | |||
61 | if (name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' } | ||
62 | |||
63 | return { accepted: true } | ||
64 | } | ||
65 | }) | ||
66 | } | ||
58 | 67 | ||
59 | registerHook({ | 68 | registerHook({ |
60 | target: 'filter:api.video.pre-import-url.accept.result', | 69 | 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 @@ | |||
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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { | 4 | import { ServerHookName, VideoPrivacy } from '@shared/models' |
5 | cleanupTests, | ||
6 | flushAndRunMultipleServers, | ||
7 | killallServers, | ||
8 | reRunServer, | ||
9 | ServerInfo, | ||
10 | waitUntilLog | ||
11 | } from '../../../shared/extra-utils/server/servers' | ||
12 | import { | 5 | import { |
13 | addVideoCommentReply, | 6 | addVideoCommentReply, |
14 | addVideoCommentThread, | 7 | addVideoCommentThread, |
15 | blockUser, | 8 | blockUser, |
9 | createLive, | ||
16 | createUser, | 10 | createUser, |
17 | deleteVideoComment, | 11 | deleteVideoComment, |
18 | getPluginTestPath, | 12 | getPluginTestPath, |
@@ -20,6 +14,7 @@ import { | |||
20 | registerUser, | 14 | registerUser, |
21 | removeUser, | 15 | removeUser, |
22 | setAccessTokensToServers, | 16 | setAccessTokensToServers, |
17 | setDefaultVideoChannel, | ||
23 | unblockUser, | 18 | unblockUser, |
24 | updateUser, | 19 | updateUser, |
25 | updateVideo, | 20 | updateVideo, |
@@ -27,13 +22,21 @@ import { | |||
27 | userLogin, | 22 | userLogin, |
28 | viewVideo | 23 | viewVideo |
29 | } from '../../../shared/extra-utils' | 24 | } from '../../../shared/extra-utils' |
25 | import { | ||
26 | cleanupTests, | ||
27 | flushAndRunMultipleServers, | ||
28 | killallServers, | ||
29 | reRunServer, | ||
30 | ServerInfo, | ||
31 | waitUntilLog | ||
32 | } from '../../../shared/extra-utils/server/servers' | ||
30 | 33 | ||
31 | describe('Test plugin action hooks', function () { | 34 | describe('Test plugin action hooks', function () { |
32 | let servers: ServerInfo[] | 35 | let servers: ServerInfo[] |
33 | let videoUUID: string | 36 | let videoUUID: string |
34 | let threadId: number | 37 | let threadId: number |
35 | 38 | ||
36 | function checkHook (hook: string) { | 39 | function checkHook (hook: ServerHookName) { |
37 | return waitUntilLog(servers[0], 'Run hook ' + hook) | 40 | return waitUntilLog(servers[0], 'Run hook ' + hook) |
38 | } | 41 | } |
39 | 42 | ||
@@ -42,6 +45,7 @@ describe('Test plugin action hooks', function () { | |||
42 | 45 | ||
43 | servers = await flushAndRunMultipleServers(2) | 46 | servers = await flushAndRunMultipleServers(2) |
44 | await setAccessTokensToServers(servers) | 47 | await setAccessTokensToServers(servers) |
48 | await setDefaultVideoChannel(servers) | ||
45 | 49 | ||
46 | await installPlugin({ | 50 | await installPlugin({ |
47 | url: servers[0].url, | 51 | url: servers[0].url, |
@@ -51,7 +55,11 @@ describe('Test plugin action hooks', function () { | |||
51 | 55 | ||
52 | killallServers([ servers[0] ]) | 56 | killallServers([ servers[0] ]) |
53 | 57 | ||
54 | await reRunServer(servers[0]) | 58 | await reRunServer(servers[0], { |
59 | live: { | ||
60 | enabled: true | ||
61 | } | ||
62 | }) | ||
55 | }) | 63 | }) |
56 | 64 | ||
57 | describe('Application hooks', function () { | 65 | describe('Application hooks', function () { |
@@ -81,6 +89,21 @@ describe('Test plugin action hooks', function () { | |||
81 | }) | 89 | }) |
82 | }) | 90 | }) |
83 | 91 | ||
92 | describe('Live hooks', function () { | ||
93 | |||
94 | it('Should run action:api.live-video.created', async function () { | ||
95 | const attributes = { | ||
96 | name: 'live', | ||
97 | privacy: VideoPrivacy.PUBLIC, | ||
98 | channelId: servers[0].videoChannel.id | ||
99 | } | ||
100 | |||
101 | await createLive(servers[0].url, servers[0].accessToken, attributes) | ||
102 | |||
103 | await checkHook('action:api.live-video.created') | ||
104 | }) | ||
105 | }) | ||
106 | |||
84 | describe('Comments hooks', function () { | 107 | describe('Comments hooks', function () { |
85 | it('Should run action:api.video-thread.created', async function () { | 108 | it('Should run action:api.video-thread.created', async function () { |
86 | const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') | 109 | 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' | |||
6 | import { | 6 | import { |
7 | addVideoCommentReply, | 7 | addVideoCommentReply, |
8 | addVideoCommentThread, | 8 | addVideoCommentThread, |
9 | createLive, | ||
9 | doubleFollow, | 10 | doubleFollow, |
10 | getConfig, | 11 | getConfig, |
11 | getPluginTestPath, | 12 | getPluginTestPath, |
@@ -19,6 +20,7 @@ import { | |||
19 | registerUser, | 20 | registerUser, |
20 | setAccessTokensToServers, | 21 | setAccessTokensToServers, |
21 | setDefaultVideoChannel, | 22 | setDefaultVideoChannel, |
23 | updateCustomSubConfig, | ||
22 | updateVideo, | 24 | updateVideo, |
23 | uploadVideo, | 25 | uploadVideo, |
24 | waitJobs | 26 | waitJobs |
@@ -61,6 +63,17 @@ describe('Test plugin filter hooks', function () { | |||
61 | 63 | ||
62 | const res = await getVideosList(servers[0].url) | 64 | const res = await getVideosList(servers[0].url) |
63 | videoUUID = res.body.data[0].uuid | 65 | videoUUID = res.body.data[0].uuid |
66 | |||
67 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | ||
68 | live: { enabled: true }, | ||
69 | signup: { enabled: true }, | ||
70 | import: { | ||
71 | videos: { | ||
72 | http: { enabled: true }, | ||
73 | torrent: { enabled: true } | ||
74 | } | ||
75 | } | ||
76 | }) | ||
64 | }) | 77 | }) |
65 | 78 | ||
66 | it('Should run filter:api.videos.list.params', async function () { | 79 | it('Should run filter:api.videos.list.params', async function () { |
@@ -87,6 +100,16 @@ describe('Test plugin filter hooks', function () { | |||
87 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403) | 100 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403) |
88 | }) | 101 | }) |
89 | 102 | ||
103 | it('Should run filter:api.live-video.create.accept.result', async function () { | ||
104 | const attributes = { | ||
105 | name: 'video with bad word', | ||
106 | privacy: VideoPrivacy.PUBLIC, | ||
107 | channelId: servers[0].videoChannel.id | ||
108 | } | ||
109 | |||
110 | await createLive(servers[0].url, servers[0].accessToken, attributes, 403) | ||
111 | }) | ||
112 | |||
90 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { | 113 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { |
91 | const baseAttributes = { | 114 | const baseAttributes = { |
92 | name: 'normal title', | 115 | name: 'normal title', |