aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/filter-hooks.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/plugins/filter-hooks.ts')
-rw-r--r--server/tests/plugins/filter-hooks.ts400
1 files changed, 190 insertions, 210 deletions
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index 644b41dea..c00ac8f91 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -2,192 +2,152 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels'
6import { ServerConfig } from '@shared/models'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
8import { 5import {
9 addVideoCommentReply, 6 cleanupTests,
10 addVideoCommentThread, 7 createMultipleServers,
11 advancedVideoPlaylistSearch,
12 advancedVideosSearch,
13 createLive,
14 createVideoPlaylist,
15 doubleFollow, 8 doubleFollow,
16 getAccountVideos, 9 FIXTURE_URLS,
17 getConfig,
18 getMyVideos,
19 getPluginTestPath,
20 getVideo,
21 getVideoChannelVideos,
22 getVideoCommentThreads,
23 getVideoPlaylist,
24 getVideosList,
25 getVideosListPagination,
26 getVideoThreadComments,
27 getVideoWithToken,
28 installPlugin,
29 makeRawRequest, 10 makeRawRequest,
30 registerUser, 11 PeerTubeServer,
12 PluginsCommand,
31 setAccessTokensToServers, 13 setAccessTokensToServers,
32 setDefaultVideoChannel, 14 setDefaultVideoChannel,
33 updateCustomSubConfig,
34 updateVideo,
35 uploadVideo,
36 uploadVideoAndGetId,
37 waitJobs 15 waitJobs
38} from '../../../shared/extra-utils' 16} from '@shared/extra-utils'
39import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 17import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
40import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports'
41import {
42 VideoCommentThreadTree,
43 VideoDetails,
44 VideoImport,
45 VideoImportState,
46 VideoPlaylist,
47 VideoPlaylistPrivacy,
48 VideoPrivacy
49} from '../../../shared/models/videos'
50 18
51const expect = chai.expect 19const expect = chai.expect
52 20
53describe('Test plugin filter hooks', function () { 21describe('Test plugin filter hooks', function () {
54 let servers: ServerInfo[] 22 let servers: PeerTubeServer[]
55 let videoUUID: string 23 let videoUUID: string
56 let threadId: number 24 let threadId: number
57 25
58 before(async function () { 26 before(async function () {
59 this.timeout(60000) 27 this.timeout(60000)
60 28
61 servers = await flushAndRunMultipleServers(2) 29 servers = await createMultipleServers(2)
62 await setAccessTokensToServers(servers) 30 await setAccessTokensToServers(servers)
63 await setDefaultVideoChannel(servers) 31 await setDefaultVideoChannel(servers)
64 await doubleFollow(servers[0], servers[1]) 32 await doubleFollow(servers[0], servers[1])
65 33
66 await installPlugin({ 34 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
67 url: servers[0].url, 35 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
68 accessToken: servers[0].accessToken,
69 path: getPluginTestPath()
70 })
71
72 await installPlugin({
73 url: servers[0].url,
74 accessToken: servers[0].accessToken,
75 path: getPluginTestPath('-filter-translations')
76 })
77 36
78 for (let i = 0; i < 10; i++) { 37 for (let i = 0; i < 10; i++) {
79 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) 38 await servers[0].videos.upload({ attributes: { name: 'default video ' + i } })
80 } 39 }
81 40
82 const res = await getVideosList(servers[0].url) 41 const { data } = await servers[0].videos.list()
83 videoUUID = res.body.data[0].uuid 42 videoUUID = data[0].uuid
84 43
85 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 44 await servers[0].config.updateCustomSubConfig({
86 live: { enabled: true }, 45 newConfig: {
87 signup: { enabled: true }, 46 live: { enabled: true },
88 import: { 47 signup: { enabled: true },
89 videos: { 48 import: {
90 http: { enabled: true }, 49 videos: {
91 torrent: { enabled: true } 50 http: { enabled: true },
51 torrent: { enabled: true }
52 }
92 } 53 }
93 } 54 }
94 }) 55 })
95 }) 56 })
96 57
97 it('Should run filter:api.videos.list.params', async function () { 58 it('Should run filter:api.videos.list.params', async function () {
98 const res = await getVideosListPagination(servers[0].url, 0, 2) 59 const { data } = await servers[0].videos.list({ start: 0, count: 2 })
99 60
100 // 2 plugins do +1 to the count parameter 61 // 2 plugins do +1 to the count parameter
101 expect(res.body.data).to.have.lengthOf(4) 62 expect(data).to.have.lengthOf(4)
102 }) 63 })
103 64
104 it('Should run filter:api.videos.list.result', async function () { 65 it('Should run filter:api.videos.list.result', async function () {
105 const res = await getVideosListPagination(servers[0].url, 0, 0) 66 const { total } = await servers[0].videos.list({ start: 0, count: 0 })
106 67
107 // Plugin do +1 to the total result 68 // Plugin do +1 to the total result
108 expect(res.body.total).to.equal(11) 69 expect(total).to.equal(11)
109 }) 70 })
110 71
111 it('Should run filter:api.accounts.videos.list.params', async function () { 72 it('Should run filter:api.accounts.videos.list.params', async function () {
112 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) 73 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
113 74
114 // 1 plugin do +1 to the count parameter 75 // 1 plugin do +1 to the count parameter
115 expect(res.body.data).to.have.lengthOf(3) 76 expect(data).to.have.lengthOf(3)
116 }) 77 })
117 78
118 it('Should run filter:api.accounts.videos.list.result', async function () { 79 it('Should run filter:api.accounts.videos.list.result', async function () {
119 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) 80 const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
120 81
121 // Plugin do +2 to the total result 82 // Plugin do +2 to the total result
122 expect(res.body.total).to.equal(12) 83 expect(total).to.equal(12)
123 }) 84 })
124 85
125 it('Should run filter:api.video-channels.videos.list.params', async function () { 86 it('Should run filter:api.video-channels.videos.list.params', async function () {
126 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) 87 const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
127 88
128 // 1 plugin do +3 to the count parameter 89 // 1 plugin do +3 to the count parameter
129 expect(res.body.data).to.have.lengthOf(5) 90 expect(data).to.have.lengthOf(5)
130 }) 91 })
131 92
132 it('Should run filter:api.video-channels.videos.list.result', async function () { 93 it('Should run filter:api.video-channels.videos.list.result', async function () {
133 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) 94 const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
134 95
135 // Plugin do +3 to the total result 96 // Plugin do +3 to the total result
136 expect(res.body.total).to.equal(13) 97 expect(total).to.equal(13)
137 }) 98 })
138 99
139 it('Should run filter:api.user.me.videos.list.params', async function () { 100 it('Should run filter:api.user.me.videos.list.params', async function () {
140 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) 101 const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
141 102
142 // 1 plugin do +4 to the count parameter 103 // 1 plugin do +4 to the count parameter
143 expect(res.body.data).to.have.lengthOf(6) 104 expect(data).to.have.lengthOf(6)
144 }) 105 })
145 106
146 it('Should run filter:api.user.me.videos.list.result', async function () { 107 it('Should run filter:api.user.me.videos.list.result', async function () {
147 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) 108 const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
148 109
149 // Plugin do +4 to the total result 110 // Plugin do +4 to the total result
150 expect(res.body.total).to.equal(14) 111 expect(total).to.equal(14)
151 }) 112 })
152 113
153 it('Should run filter:api.video.get.result', async function () { 114 it('Should run filter:api.video.get.result', async function () {
154 const res = await getVideo(servers[0].url, videoUUID) 115 const video = await servers[0].videos.get({ id: videoUUID })
155 116 expect(video.name).to.contain('<3')
156 expect(res.body.name).to.contain('<3')
157 }) 117 })
158 118
159 it('Should run filter:api.video.upload.accept.result', async function () { 119 it('Should run filter:api.video.upload.accept.result', async function () {
160 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) 120 await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
161 }) 121 })
162 122
163 it('Should run filter:api.live-video.create.accept.result', async function () { 123 it('Should run filter:api.live-video.create.accept.result', async function () {
164 const attributes = { 124 const attributes = {
165 name: 'video with bad word', 125 name: 'video with bad word',
166 privacy: VideoPrivacy.PUBLIC, 126 privacy: VideoPrivacy.PUBLIC,
167 channelId: servers[0].videoChannel.id 127 channelId: servers[0].store.channel.id
168 } 128 }
169 129
170 await createLive(servers[0].url, servers[0].accessToken, attributes, HttpStatusCode.FORBIDDEN_403) 130 await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
171 }) 131 })
172 132
173 it('Should run filter:api.video.pre-import-url.accept.result', async function () { 133 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
174 const baseAttributes = { 134 const attributes = {
175 name: 'normal title', 135 name: 'normal title',
176 privacy: VideoPrivacy.PUBLIC, 136 privacy: VideoPrivacy.PUBLIC,
177 channelId: servers[0].videoChannel.id, 137 channelId: servers[0].store.channel.id,
178 targetUrl: getGoodVideoUrl() + 'bad' 138 targetUrl: FIXTURE_URLS.goodVideo + 'bad'
179 } 139 }
180 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) 140 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
181 }) 141 })
182 142
183 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { 143 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
184 const baseAttributes = { 144 const attributes = {
185 name: 'bad torrent', 145 name: 'bad torrent',
186 privacy: VideoPrivacy.PUBLIC, 146 privacy: VideoPrivacy.PUBLIC,
187 channelId: servers[0].videoChannel.id, 147 channelId: servers[0].store.channel.id,
188 torrentfile: 'video-720p.torrent' as any 148 torrentfile: 'video-720p.torrent' as any
189 } 149 }
190 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) 150 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
191 }) 151 })
192 152
193 it('Should run filter:api.video.post-import-url.accept.result', async function () { 153 it('Should run filter:api.video.post-import-url.accept.result', async function () {
@@ -196,21 +156,21 @@ describe('Test plugin filter hooks', function () {
196 let videoImportId: number 156 let videoImportId: number
197 157
198 { 158 {
199 const baseAttributes = { 159 const attributes = {
200 name: 'title with bad word', 160 name: 'title with bad word',
201 privacy: VideoPrivacy.PUBLIC, 161 privacy: VideoPrivacy.PUBLIC,
202 channelId: servers[0].videoChannel.id, 162 channelId: servers[0].store.channel.id,
203 targetUrl: getGoodVideoUrl() 163 targetUrl: FIXTURE_URLS.goodVideo
204 } 164 }
205 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) 165 const body = await servers[0].imports.importVideo({ attributes })
206 videoImportId = res.body.id 166 videoImportId = body.id
207 } 167 }
208 168
209 await waitJobs(servers) 169 await waitJobs(servers)
210 170
211 { 171 {
212 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) 172 const body = await servers[0].imports.getMyVideoImports()
213 const videoImports = res.body.data as VideoImport[] 173 const videoImports = body.data
214 174
215 const videoImport = videoImports.find(i => i.id === videoImportId) 175 const videoImport = videoImports.find(i => i.id === videoImportId)
216 176
@@ -225,21 +185,20 @@ describe('Test plugin filter hooks', function () {
225 let videoImportId: number 185 let videoImportId: number
226 186
227 { 187 {
228 const baseAttributes = { 188 const attributes = {
229 name: 'title with bad word', 189 name: 'title with bad word',
230 privacy: VideoPrivacy.PUBLIC, 190 privacy: VideoPrivacy.PUBLIC,
231 channelId: servers[0].videoChannel.id, 191 channelId: servers[0].store.channel.id,
232 torrentfile: 'video-720p.torrent' as any 192 torrentfile: 'video-720p.torrent' as any
233 } 193 }
234 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) 194 const body = await servers[0].imports.importVideo({ attributes })
235 videoImportId = res.body.id 195 videoImportId = body.id
236 } 196 }
237 197
238 await waitJobs(servers) 198 await waitJobs(servers)
239 199
240 { 200 {
241 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) 201 const { data: videoImports } = await servers[0].imports.getMyVideoImports()
242 const videoImports = res.body.data as VideoImport[]
243 202
244 const videoImport = videoImports.find(i => i.id === videoImportId) 203 const videoImport = videoImports.find(i => i.id === videoImportId)
245 204
@@ -249,60 +208,63 @@ describe('Test plugin filter hooks', function () {
249 }) 208 })
250 209
251 it('Should run filter:api.video-thread.create.accept.result', async function () { 210 it('Should run filter:api.video-thread.create.accept.result', async function () {
252 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', HttpStatusCode.FORBIDDEN_403) 211 await servers[0].comments.createThread({
212 videoId: videoUUID,
213 text: 'comment with bad word',
214 expectedStatus: HttpStatusCode.FORBIDDEN_403
215 })
253 }) 216 })
254 217
255 it('Should run filter:api.video-comment-reply.create.accept.result', async function () { 218 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
256 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') 219 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
257 threadId = res.body.comment.id 220 threadId = created.id
258 221
259 await addVideoCommentReply( 222 await servers[0].comments.addReply({
260 servers[0].url, 223 videoId: videoUUID,
261 servers[0].accessToken, 224 toCommentId: threadId,
262 videoUUID, 225 text: 'comment with bad word',
263 threadId, 226 expectedStatus: HttpStatusCode.FORBIDDEN_403
264 'comment with bad word', 227 })
265 HttpStatusCode.FORBIDDEN_403 228 await servers[0].comments.addReply({
266 ) 229 videoId: videoUUID,
267 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', HttpStatusCode.OK_200) 230 toCommentId: threadId,
231 text: 'comment with good word',
232 expectedStatus: HttpStatusCode.OK_200
233 })
268 }) 234 })
269 235
270 it('Should run filter:api.video-threads.list.params', async function () { 236 it('Should run filter:api.video-threads.list.params', async function () {
271 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) 237 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
272 238
273 // our plugin do +1 to the count parameter 239 // our plugin do +1 to the count parameter
274 expect(res.body.data).to.have.lengthOf(1) 240 expect(data).to.have.lengthOf(1)
275 }) 241 })
276 242
277 it('Should run filter:api.video-threads.list.result', async function () { 243 it('Should run filter:api.video-threads.list.result', async function () {
278 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) 244 const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
279 245
280 // Plugin do +1 to the total result 246 // Plugin do +1 to the total result
281 expect(res.body.total).to.equal(2) 247 expect(total).to.equal(2)
282 }) 248 })
283 249
284 it('Should run filter:api.video-thread-comments.list.params') 250 it('Should run filter:api.video-thread-comments.list.params')
285 251
286 it('Should run filter:api.video-thread-comments.list.result', async function () { 252 it('Should run filter:api.video-thread-comments.list.result', async function () {
287 const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) 253 const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
288 254
289 const thread = res.body as VideoCommentThreadTree
290 expect(thread.comment.text.endsWith(' <3')).to.be.true 255 expect(thread.comment.text.endsWith(' <3')).to.be.true
291 }) 256 })
292 257
293 describe('Should run filter:video.auto-blacklist.result', function () { 258 describe('Should run filter:video.auto-blacklist.result', function () {
294 259
295 async function checkIsBlacklisted (oldRes: any, value: boolean) { 260 async function checkIsBlacklisted (id: number | string, value: boolean) {
296 const videoId = oldRes.body.video.uuid 261 const video = await servers[0].videos.getWithToken({ id })
297
298 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId)
299 const video: VideoDetails = res.body
300 expect(video.blacklisted).to.equal(value) 262 expect(video.blacklisted).to.equal(value)
301 } 263 }
302 264
303 it('Should blacklist on upload', async function () { 265 it('Should blacklist on upload', async function () {
304 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) 266 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video please blacklist me' } })
305 await checkIsBlacklisted(res, true) 267 await checkIsBlacklisted(uuid, true)
306 }) 268 })
307 269
308 it('Should blacklist on import', async function () { 270 it('Should blacklist on import', async function () {
@@ -310,60 +272,62 @@ describe('Test plugin filter hooks', function () {
310 272
311 const attributes = { 273 const attributes = {
312 name: 'video please blacklist me', 274 name: 'video please blacklist me',
313 targetUrl: getGoodVideoUrl(), 275 targetUrl: FIXTURE_URLS.goodVideo,
314 channelId: servers[0].videoChannel.id 276 channelId: servers[0].store.channel.id
315 } 277 }
316 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 278 const body = await servers[0].imports.importVideo({ attributes })
317 await checkIsBlacklisted(res, true) 279 await checkIsBlacklisted(body.video.uuid, true)
318 }) 280 })
319 281
320 it('Should blacklist on update', async function () { 282 it('Should blacklist on update', async function () {
321 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 283 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
322 const videoId = res.body.video.uuid 284 await checkIsBlacklisted(uuid, false)
323 await checkIsBlacklisted(res, false)
324 285
325 await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) 286 await servers[0].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } })
326 await checkIsBlacklisted(res, true) 287 await checkIsBlacklisted(uuid, true)
327 }) 288 })
328 289
329 it('Should blacklist on remote upload', async function () { 290 it('Should blacklist on remote upload', async function () {
330 this.timeout(120000) 291 this.timeout(120000)
331 292
332 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) 293 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'remote please blacklist me' } })
333 await waitJobs(servers) 294 await waitJobs(servers)
334 295
335 await checkIsBlacklisted(res, true) 296 await checkIsBlacklisted(uuid, true)
336 }) 297 })
337 298
338 it('Should blacklist on remote update', async function () { 299 it('Should blacklist on remote update', async function () {
339 this.timeout(120000) 300 this.timeout(120000)
340 301
341 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) 302 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video' } })
342 await waitJobs(servers) 303 await waitJobs(servers)
343 304
344 const videoId = res.body.video.uuid 305 await checkIsBlacklisted(uuid, false)
345 await checkIsBlacklisted(res, false)
346 306
347 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) 307 await servers[1].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } })
348 await waitJobs(servers) 308 await waitJobs(servers)
349 309
350 await checkIsBlacklisted(res, true) 310 await checkIsBlacklisted(uuid, true)
351 }) 311 })
352 }) 312 })
353 313
354 describe('Should run filter:api.user.signup.allowed.result', function () { 314 describe('Should run filter:api.user.signup.allowed.result', function () {
355 315
356 it('Should run on config endpoint', async function () { 316 it('Should run on config endpoint', async function () {
357 const res = await getConfig(servers[0].url) 317 const body = await servers[0].config.getConfig()
358 expect((res.body as ServerConfig).signup.allowed).to.be.true 318 expect(body.signup.allowed).to.be.true
359 }) 319 })
360 320
361 it('Should allow a signup', async function () { 321 it('Should allow a signup', async function () {
362 await registerUser(servers[0].url, 'john', 'password') 322 await servers[0].users.register({ username: 'john', password: 'password' })
363 }) 323 })
364 324
365 it('Should not allow a signup', async function () { 325 it('Should not allow a signup', async function () {
366 const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403) 326 const res = await servers[0].users.register({
327 username: 'jma',
328 password: 'password',
329 expectedStatus: HttpStatusCode.FORBIDDEN_403
330 })
367 331
368 expect(res.body.error).to.equal('No jma') 332 expect(res.body.error).to.equal('No jma')
369 }) 333 })
@@ -375,13 +339,15 @@ describe('Test plugin filter hooks', function () {
375 before(async function () { 339 before(async function () {
376 this.timeout(120000) 340 this.timeout(120000)
377 341
378 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 342 await servers[0].config.updateCustomSubConfig({
379 transcoding: { 343 newConfig: {
380 webtorrent: { 344 transcoding: {
381 enabled: true 345 webtorrent: {
382 }, 346 enabled: true
383 hls: { 347 },
384 enabled: true 348 hls: {
349 enabled: true
350 }
385 } 351 }
386 } 352 }
387 }) 353 })
@@ -389,15 +355,14 @@ describe('Test plugin filter hooks', function () {
389 const uuids: string[] = [] 355 const uuids: string[] = []
390 356
391 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { 357 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
392 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid 358 const uuid = (await servers[0].videos.quickUpload({ name: name })).uuid
393 uuids.push(uuid) 359 uuids.push(uuid)
394 } 360 }
395 361
396 await waitJobs(servers) 362 await waitJobs(servers)
397 363
398 for (const uuid of uuids) { 364 for (const uuid of uuids) {
399 const res = await getVideo(servers[0].url, uuid) 365 downloadVideos.push(await servers[0].videos.get({ id: uuid }))
400 downloadVideos.push(res.body)
401 } 366 }
402 }) 367 })
403 368
@@ -437,25 +402,26 @@ describe('Test plugin filter hooks', function () {
437 before(async function () { 402 before(async function () {
438 this.timeout(60000) 403 this.timeout(60000)
439 404
440 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 405 await servers[0].config.updateCustomSubConfig({
441 transcoding: { 406 newConfig: {
442 enabled: false 407 transcoding: {
408 enabled: false
409 }
443 } 410 }
444 }) 411 })
445 412
446 for (const name of [ 'bad embed', 'good embed' ]) { 413 for (const name of [ 'bad embed', 'good embed' ]) {
447 { 414 {
448 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid 415 const uuid = (await servers[0].videos.quickUpload({ name: name })).uuid
449 const res = await getVideo(servers[0].url, uuid) 416 embedVideos.push(await servers[0].videos.get({ id: uuid }))
450 embedVideos.push(res.body)
451 } 417 }
452 418
453 { 419 {
454 const playlistAttrs = { displayName: name, videoChannelId: servers[0].videoChannel.id, privacy: VideoPlaylistPrivacy.PUBLIC } 420 const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC }
455 const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) 421 const { id } = await servers[0].playlists.create({ attributes })
456 422
457 const resPlaylist = await getVideoPlaylist(servers[0].url, res.body.videoPlaylist.id) 423 const playlist = await servers[0].playlists.get({ playlistId: id })
458 embedPlaylists.push(resPlaylist.body) 424 embedPlaylists.push(playlist)
459 } 425 }
460 } 426 }
461 }) 427 })
@@ -474,78 +440,92 @@ describe('Test plugin filter hooks', function () {
474 describe('Search filters', function () { 440 describe('Search filters', function () {
475 441
476 before(async function () { 442 before(async function () {
477 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 443 await servers[0].config.updateCustomSubConfig({
478 search: { 444 newConfig: {
479 searchIndex: { 445 search: {
480 enabled: true, 446 searchIndex: {
481 isDefaultSearch: false, 447 enabled: true,
482 disableLocalSearch: false 448 isDefaultSearch: false,
449 disableLocalSearch: false
450 }
483 } 451 }
484 } 452 }
485 }) 453 })
486 }) 454 })
487 455
488 it('Should run filter:api.search.videos.local.list.{params,result}', async function () { 456 it('Should run filter:api.search.videos.local.list.{params,result}', async function () {
489 await advancedVideosSearch(servers[0].url, { 457 await servers[0].search.advancedVideoSearch({
490 search: 'Sun Quan' 458 search: {
459 search: 'Sun Quan'
460 }
491 }) 461 })
492 462
493 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) 463 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
494 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1) 464 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
495 }) 465 })
496 466
497 it('Should run filter:api.search.videos.index.list.{params,result}', async function () { 467 it('Should run filter:api.search.videos.index.list.{params,result}', async function () {
498 await advancedVideosSearch(servers[0].url, { 468 await servers[0].search.advancedVideoSearch({
499 search: 'Sun Quan', 469 search: {
500 searchTarget: 'search-index' 470 search: 'Sun Quan',
471 searchTarget: 'search-index'
472 }
501 }) 473 })
502 474
503 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) 475 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
504 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1) 476 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
505 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.params', 1) 477 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1)
506 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.result', 1) 478 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1)
507 }) 479 })
508 480
509 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { 481 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () {
510 await advancedVideoChannelSearch(servers[0].url, { 482 await servers[0].search.advancedChannelSearch({
511 search: 'Sun Ce' 483 search: {
484 search: 'Sun Ce'
485 }
512 }) 486 })
513 487
514 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) 488 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
515 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1) 489 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
516 }) 490 })
517 491
518 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { 492 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () {
519 await advancedVideoChannelSearch(servers[0].url, { 493 await servers[0].search.advancedChannelSearch({
520 search: 'Sun Ce', 494 search: {
521 searchTarget: 'search-index' 495 search: 'Sun Ce',
496 searchTarget: 'search-index'
497 }
522 }) 498 })
523 499
524 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) 500 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
525 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1) 501 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
526 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.params', 1) 502 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1)
527 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.result', 1) 503 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1)
528 }) 504 })
529 505
530 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { 506 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () {
531 await advancedVideoPlaylistSearch(servers[0].url, { 507 await servers[0].search.advancedPlaylistSearch({
532 search: 'Sun Jian' 508 search: {
509 search: 'Sun Jian'
510 }
533 }) 511 })
534 512
535 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) 513 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
536 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1) 514 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
537 }) 515 })
538 516
539 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { 517 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () {
540 await advancedVideoPlaylistSearch(servers[0].url, { 518 await servers[0].search.advancedPlaylistSearch({
541 search: 'Sun Jian', 519 search: {
542 searchTarget: 'search-index' 520 search: 'Sun Jian',
521 searchTarget: 'search-index'
522 }
543 }) 523 })
544 524
545 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) 525 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
546 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1) 526 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
547 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.params', 1) 527 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1)
548 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.result', 1) 528 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1)
549 }) 529 })
550 }) 530 })
551 531