]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/filter-hooks.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / filter-hooks.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
5 import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 makeRawRequest,
10 PeerTubeServer,
11 PluginsCommand,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
14 waitJobs
15 } from '@shared/server-commands'
16 import { FIXTURE_URLS } from '../shared'
17
18 describe('Test plugin filter hooks', function () {
19 let servers: PeerTubeServer[]
20 let videoUUID: string
21 let threadId: number
22 let videoPlaylistUUID: string
23
24 before(async function () {
25 this.timeout(60000)
26
27 servers = await createMultipleServers(2)
28 await setAccessTokensToServers(servers)
29 await setDefaultVideoChannel(servers)
30 await doubleFollow(servers[0], servers[1])
31
32 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
33 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
34 {
35 ({ uuid: videoPlaylistUUID } = await servers[0].playlists.create({
36 attributes: {
37 displayName: 'my super playlist',
38 privacy: VideoPlaylistPrivacy.PUBLIC,
39 description: 'my super description',
40 videoChannelId: servers[0].store.channel.id
41 }
42 }))
43 }
44
45 for (let i = 0; i < 10; i++) {
46 const video = await servers[0].videos.upload({ attributes: { name: 'default video ' + i } })
47 await servers[0].playlists.addElement({ playlistId: videoPlaylistUUID, attributes: { videoId: video.id } })
48 }
49
50 const { data } = await servers[0].videos.list()
51 videoUUID = data[0].uuid
52
53 await servers[0].config.updateCustomSubConfig({
54 newConfig: {
55 live: { enabled: true },
56 signup: { enabled: true },
57 import: {
58 videos: {
59 http: { enabled: true },
60 torrent: { enabled: true }
61 }
62 }
63 }
64 })
65 })
66
67 describe('Videos', function () {
68
69 it('Should run filter:api.videos.list.params', async function () {
70 const { data } = await servers[0].videos.list({ start: 0, count: 2 })
71
72 // 2 plugins do +1 to the count parameter
73 expect(data).to.have.lengthOf(4)
74 })
75
76 it('Should run filter:api.videos.list.result', async function () {
77 const { total } = await servers[0].videos.list({ start: 0, count: 0 })
78
79 // Plugin do +1 to the total result
80 expect(total).to.equal(11)
81 })
82
83 it('Should run filter:api.video-playlist.videos.list.params', async function () {
84 const { data } = await servers[0].playlists.listVideos({
85 count: 2,
86 playlistId: videoPlaylistUUID
87 })
88
89 // 1 plugin do +1 to the count parameter
90 expect(data).to.have.lengthOf(3)
91 })
92
93 it('Should run filter:api.video-playlist.videos.list.result', async function () {
94 const { total } = await servers[0].playlists.listVideos({
95 count: 0,
96 playlistId: videoPlaylistUUID
97 })
98
99 // Plugin do +1 to the total result
100 expect(total).to.equal(11)
101 })
102
103 it('Should run filter:api.accounts.videos.list.params', async function () {
104 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
105
106 // 1 plugin do +1 to the count parameter
107 expect(data).to.have.lengthOf(3)
108 })
109
110 it('Should run filter:api.accounts.videos.list.result', async function () {
111 const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
112
113 // Plugin do +2 to the total result
114 expect(total).to.equal(12)
115 })
116
117 it('Should run filter:api.video-channels.videos.list.params', async function () {
118 const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
119
120 // 1 plugin do +3 to the count parameter
121 expect(data).to.have.lengthOf(5)
122 })
123
124 it('Should run filter:api.video-channels.videos.list.result', async function () {
125 const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
126
127 // Plugin do +3 to the total result
128 expect(total).to.equal(13)
129 })
130
131 it('Should run filter:api.user.me.videos.list.params', async function () {
132 const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
133
134 // 1 plugin do +4 to the count parameter
135 expect(data).to.have.lengthOf(6)
136 })
137
138 it('Should run filter:api.user.me.videos.list.result', async function () {
139 const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
140
141 // Plugin do +4 to the total result
142 expect(total).to.equal(14)
143 })
144
145 it('Should run filter:api.video.get.result', async function () {
146 const video = await servers[0].videos.get({ id: videoUUID })
147 expect(video.name).to.contain('<3')
148 })
149 })
150
151 describe('Video/live/import accept', function () {
152
153 it('Should run filter:api.video.upload.accept.result', async function () {
154 await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
155 })
156
157 it('Should run filter:api.live-video.create.accept.result', async function () {
158 const attributes = {
159 name: 'video with bad word',
160 privacy: VideoPrivacy.PUBLIC,
161 channelId: servers[0].store.channel.id
162 }
163
164 await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
165 })
166
167 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
168 const attributes = {
169 name: 'normal title',
170 privacy: VideoPrivacy.PUBLIC,
171 channelId: servers[0].store.channel.id,
172 targetUrl: FIXTURE_URLS.goodVideo + 'bad'
173 }
174 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
175 })
176
177 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
178 const attributes = {
179 name: 'bad torrent',
180 privacy: VideoPrivacy.PUBLIC,
181 channelId: servers[0].store.channel.id,
182 torrentfile: 'video-720p.torrent' as any
183 }
184 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
185 })
186
187 it('Should run filter:api.video.post-import-url.accept.result', async function () {
188 this.timeout(60000)
189
190 let videoImportId: number
191
192 {
193 const attributes = {
194 name: 'title with bad word',
195 privacy: VideoPrivacy.PUBLIC,
196 channelId: servers[0].store.channel.id,
197 targetUrl: FIXTURE_URLS.goodVideo
198 }
199 const body = await servers[0].imports.importVideo({ attributes })
200 videoImportId = body.id
201 }
202
203 await waitJobs(servers)
204
205 {
206 const body = await servers[0].imports.getMyVideoImports()
207 const videoImports = body.data
208
209 const videoImport = videoImports.find(i => i.id === videoImportId)
210
211 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
212 expect(videoImport.state.label).to.equal('Rejected')
213 }
214 })
215
216 it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
217 this.timeout(60000)
218
219 let videoImportId: number
220
221 {
222 const attributes = {
223 name: 'title with bad word',
224 privacy: VideoPrivacy.PUBLIC,
225 channelId: servers[0].store.channel.id,
226 torrentfile: 'video-720p.torrent' as any
227 }
228 const body = await servers[0].imports.importVideo({ attributes })
229 videoImportId = body.id
230 }
231
232 await waitJobs(servers)
233
234 {
235 const { data: videoImports } = await servers[0].imports.getMyVideoImports()
236
237 const videoImport = videoImports.find(i => i.id === videoImportId)
238
239 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
240 expect(videoImport.state.label).to.equal('Rejected')
241 }
242 })
243 })
244
245 describe('Video comments accept', function () {
246
247 it('Should run filter:api.video-thread.create.accept.result', async function () {
248 await servers[0].comments.createThread({
249 videoId: videoUUID,
250 text: 'comment with bad word',
251 expectedStatus: HttpStatusCode.FORBIDDEN_403
252 })
253 })
254
255 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
256 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
257 threadId = created.id
258
259 await servers[0].comments.addReply({
260 videoId: videoUUID,
261 toCommentId: threadId,
262 text: 'comment with bad word',
263 expectedStatus: HttpStatusCode.FORBIDDEN_403
264 })
265 await servers[0].comments.addReply({
266 videoId: videoUUID,
267 toCommentId: threadId,
268 text: 'comment with good word',
269 expectedStatus: HttpStatusCode.OK_200
270 })
271 })
272
273 it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a thread creation', async function () {
274 this.timeout(30000)
275
276 await servers[1].comments.createThread({ videoId: videoUUID, text: 'comment with bad word' })
277
278 await waitJobs(servers)
279
280 {
281 const thread = await servers[0].comments.listThreads({ videoId: videoUUID })
282 expect(thread.data).to.have.lengthOf(1)
283 expect(thread.data[0].text).to.not.include(' bad ')
284 }
285
286 {
287 const thread = await servers[1].comments.listThreads({ videoId: videoUUID })
288 expect(thread.data).to.have.lengthOf(2)
289 }
290 })
291
292 it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a reply creation', async function () {
293 this.timeout(30000)
294
295 const { data } = await servers[1].comments.listThreads({ videoId: videoUUID })
296 const threadIdServer2 = data.find(t => t.text === 'thread').id
297
298 await servers[1].comments.addReply({
299 videoId: videoUUID,
300 toCommentId: threadIdServer2,
301 text: 'comment with bad word'
302 })
303
304 await waitJobs(servers)
305
306 {
307 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
308 expect(tree.children).to.have.lengthOf(1)
309 expect(tree.children[0].comment.text).to.not.include(' bad ')
310 }
311
312 {
313 const tree = await servers[1].comments.getThread({ videoId: videoUUID, threadId: threadIdServer2 })
314 expect(tree.children).to.have.lengthOf(2)
315 }
316 })
317 })
318
319 describe('Video comments', function () {
320
321 it('Should run filter:api.video-threads.list.params', async function () {
322 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
323
324 // our plugin do +1 to the count parameter
325 expect(data).to.have.lengthOf(1)
326 })
327
328 it('Should run filter:api.video-threads.list.result', async function () {
329 const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
330
331 // Plugin do +1 to the total result
332 expect(total).to.equal(2)
333 })
334
335 it('Should run filter:api.video-thread-comments.list.params')
336
337 it('Should run filter:api.video-thread-comments.list.result', async function () {
338 const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
339
340 expect(thread.comment.text.endsWith(' <3')).to.be.true
341 })
342
343 it('Should run filter:api.overviews.videos.list.{params,result}', async function () {
344 await servers[0].overviews.getVideos({ page: 1 })
345
346 // 3 because we get 3 samples per page
347 await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3)
348 await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3)
349 })
350 })
351
352 describe('filter:video.auto-blacklist.result', function () {
353
354 async function checkIsBlacklisted (id: number | string, value: boolean) {
355 const video = await servers[0].videos.getWithToken({ id })
356 expect(video.blacklisted).to.equal(value)
357 }
358
359 it('Should blacklist on upload', async function () {
360 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video please blacklist me' } })
361 await checkIsBlacklisted(uuid, true)
362 })
363
364 it('Should blacklist on import', async function () {
365 this.timeout(15000)
366
367 const attributes = {
368 name: 'video please blacklist me',
369 targetUrl: FIXTURE_URLS.goodVideo,
370 channelId: servers[0].store.channel.id
371 }
372 const body = await servers[0].imports.importVideo({ attributes })
373 await checkIsBlacklisted(body.video.uuid, true)
374 })
375
376 it('Should blacklist on update', async function () {
377 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
378 await checkIsBlacklisted(uuid, false)
379
380 await servers[0].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } })
381 await checkIsBlacklisted(uuid, true)
382 })
383
384 it('Should blacklist on remote upload', async function () {
385 this.timeout(120000)
386
387 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'remote please blacklist me' } })
388 await waitJobs(servers)
389
390 await checkIsBlacklisted(uuid, true)
391 })
392
393 it('Should blacklist on remote update', async function () {
394 this.timeout(120000)
395
396 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video' } })
397 await waitJobs(servers)
398
399 await checkIsBlacklisted(uuid, false)
400
401 await servers[1].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } })
402 await waitJobs(servers)
403
404 await checkIsBlacklisted(uuid, true)
405 })
406 })
407
408 describe('Should run filter:api.user.signup.allowed.result', function () {
409
410 it('Should run on config endpoint', async function () {
411 const body = await servers[0].config.getConfig()
412 expect(body.signup.allowed).to.be.true
413 })
414
415 it('Should allow a signup', async function () {
416 await servers[0].users.register({ username: 'john', password: 'password' })
417 })
418
419 it('Should not allow a signup', async function () {
420 const res = await servers[0].users.register({
421 username: 'jma',
422 password: 'password',
423 expectedStatus: HttpStatusCode.FORBIDDEN_403
424 })
425
426 expect(res.body.error).to.equal('No jma')
427 })
428 })
429
430 describe('Download hooks', function () {
431 const downloadVideos: VideoDetails[] = []
432
433 before(async function () {
434 this.timeout(120000)
435
436 await servers[0].config.updateCustomSubConfig({
437 newConfig: {
438 transcoding: {
439 webtorrent: {
440 enabled: true
441 },
442 hls: {
443 enabled: true
444 }
445 }
446 }
447 })
448
449 const uuids: string[] = []
450
451 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
452 const uuid = (await servers[0].videos.quickUpload({ name })).uuid
453 uuids.push(uuid)
454 }
455
456 await waitJobs(servers)
457
458 for (const uuid of uuids) {
459 downloadVideos.push(await servers[0].videos.get({ id: uuid }))
460 }
461 })
462
463 it('Should run filter:api.download.torrent.allowed.result', async function () {
464 const res = await makeRawRequest(downloadVideos[0].files[0].torrentDownloadUrl, 403)
465 expect(res.body.error).to.equal('Liu Bei')
466
467 await makeRawRequest(downloadVideos[1].files[0].torrentDownloadUrl, 200)
468 await makeRawRequest(downloadVideos[2].files[0].torrentDownloadUrl, 200)
469 })
470
471 it('Should run filter:api.download.video.allowed.result', async function () {
472 {
473 const res = await makeRawRequest(downloadVideos[1].files[0].fileDownloadUrl, 403)
474 expect(res.body.error).to.equal('Cao Cao')
475
476 await makeRawRequest(downloadVideos[0].files[0].fileDownloadUrl, 200)
477 await makeRawRequest(downloadVideos[2].files[0].fileDownloadUrl, 200)
478 }
479
480 {
481 const res = await makeRawRequest(downloadVideos[2].streamingPlaylists[0].files[0].fileDownloadUrl, 403)
482 expect(res.body.error).to.equal('Sun Jian')
483
484 await makeRawRequest(downloadVideos[2].files[0].fileDownloadUrl, 200)
485
486 await makeRawRequest(downloadVideos[0].streamingPlaylists[0].files[0].fileDownloadUrl, 200)
487 await makeRawRequest(downloadVideos[1].streamingPlaylists[0].files[0].fileDownloadUrl, 200)
488 }
489 })
490 })
491
492 describe('Embed filters', function () {
493 const embedVideos: VideoDetails[] = []
494 const embedPlaylists: VideoPlaylist[] = []
495
496 before(async function () {
497 this.timeout(60000)
498
499 await servers[0].config.disableTranscoding()
500
501 for (const name of [ 'bad embed', 'good embed' ]) {
502 {
503 const uuid = (await servers[0].videos.quickUpload({ name })).uuid
504 embedVideos.push(await servers[0].videos.get({ id: uuid }))
505 }
506
507 {
508 const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC }
509 const { id } = await servers[0].playlists.create({ attributes })
510
511 const playlist = await servers[0].playlists.get({ playlistId: id })
512 embedPlaylists.push(playlist)
513 }
514 }
515 })
516
517 it('Should run filter:html.embed.video.allowed.result', async function () {
518 const res = await makeRawRequest(servers[0].url + embedVideos[0].embedPath, 200)
519 expect(res.text).to.equal('Lu Bu')
520 })
521
522 it('Should run filter:html.embed.video-playlist.allowed.result', async function () {
523 const res = await makeRawRequest(servers[0].url + embedPlaylists[0].embedPath, 200)
524 expect(res.text).to.equal('Diao Chan')
525 })
526 })
527
528 describe('Search filters', function () {
529
530 before(async function () {
531 await servers[0].config.updateCustomSubConfig({
532 newConfig: {
533 search: {
534 searchIndex: {
535 enabled: true,
536 isDefaultSearch: false,
537 disableLocalSearch: false
538 }
539 }
540 }
541 })
542 })
543
544 it('Should run filter:api.search.videos.local.list.{params,result}', async function () {
545 await servers[0].search.advancedVideoSearch({
546 search: {
547 search: 'Sun Quan'
548 }
549 })
550
551 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
552 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
553 })
554
555 it('Should run filter:api.search.videos.index.list.{params,result}', async function () {
556 await servers[0].search.advancedVideoSearch({
557 search: {
558 search: 'Sun Quan',
559 searchTarget: 'search-index'
560 }
561 })
562
563 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
564 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
565 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1)
566 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1)
567 })
568
569 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () {
570 await servers[0].search.advancedChannelSearch({
571 search: {
572 search: 'Sun Ce'
573 }
574 })
575
576 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
577 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
578 })
579
580 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () {
581 await servers[0].search.advancedChannelSearch({
582 search: {
583 search: 'Sun Ce',
584 searchTarget: 'search-index'
585 }
586 })
587
588 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
589 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
590 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1)
591 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1)
592 })
593
594 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () {
595 await servers[0].search.advancedPlaylistSearch({
596 search: {
597 search: 'Sun Jian'
598 }
599 })
600
601 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
602 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
603 })
604
605 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () {
606 await servers[0].search.advancedPlaylistSearch({
607 search: {
608 search: 'Sun Jian',
609 searchTarget: 'search-index'
610 }
611 })
612
613 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
614 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
615 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1)
616 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1)
617 })
618 })
619
620 describe('Upload/import/live attributes filters', function () {
621
622 before(async function () {
623 await servers[0].config.enableLive({ transcoding: false, allowReplay: false })
624 await servers[0].config.enableImports()
625 await servers[0].config.disableTranscoding()
626 })
627
628 it('Should run filter:api.video.upload.video-attribute.result', async function () {
629 for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
630 const { id } = await servers[0].videos.upload({ attributes: { name: 'video', description: 'upload' }, mode })
631
632 const video = await servers[0].videos.get({ id })
633 expect(video.description).to.equal('upload - filter:api.video.upload.video-attribute.result')
634 }
635 })
636
637 it('Should run filter:api.video.import-url.video-attribute.result', async function () {
638 const attributes = {
639 name: 'video',
640 description: 'import url',
641 channelId: servers[0].store.channel.id,
642 targetUrl: FIXTURE_URLS.goodVideo,
643 privacy: VideoPrivacy.PUBLIC
644 }
645 const { video: { id } } = await servers[0].imports.importVideo({ attributes })
646
647 const video = await servers[0].videos.get({ id })
648 expect(video.description).to.equal('import url - filter:api.video.import-url.video-attribute.result')
649 })
650
651 it('Should run filter:api.video.import-torrent.video-attribute.result', async function () {
652 const attributes = {
653 name: 'video',
654 description: 'import torrent',
655 channelId: servers[0].store.channel.id,
656 magnetUri: FIXTURE_URLS.magnet,
657 privacy: VideoPrivacy.PUBLIC
658 }
659 const { video: { id } } = await servers[0].imports.importVideo({ attributes })
660
661 const video = await servers[0].videos.get({ id })
662 expect(video.description).to.equal('import torrent - filter:api.video.import-torrent.video-attribute.result')
663 })
664
665 it('Should run filter:api.video.live.video-attribute.result', async function () {
666 const fields = {
667 name: 'live',
668 description: 'live',
669 channelId: servers[0].store.channel.id,
670 privacy: VideoPrivacy.PUBLIC
671 }
672 const { id } = await servers[0].live.create({ fields })
673
674 const video = await servers[0].videos.get({ id })
675 expect(video.description).to.equal('live - filter:api.video.live.video-attribute.result')
676 })
677 })
678
679 describe('Stats filters', function () {
680
681 it('Should run filter:api.server.stats.get.result', async function () {
682 const data = await servers[0].stats.get()
683
684 expect((data as any).customStats).to.equal(14)
685 })
686
687 })
688
689 describe('Job queue filters', function () {
690 let videoUUID: string
691
692 before(async function () {
693 this.timeout(120_000)
694
695 await servers[0].config.enableMinimumTranscoding()
696 const { uuid } = await servers[0].videos.quickUpload({ name: 'studio' })
697
698 const video = await servers[0].videos.get({ id: uuid })
699 expect(video.duration).at.least(2)
700 videoUUID = video.uuid
701
702 await waitJobs(servers)
703
704 await servers[0].config.enableStudio()
705 })
706
707 it('Should run filter:job-queue.process.params', async function () {
708 this.timeout(120_000)
709
710 await servers[0].videoStudio.createEditionTasks({
711 videoId: videoUUID,
712 tasks: [
713 {
714 name: 'add-intro',
715 options: {
716 file: 'video_very_short_240p.mp4'
717 }
718 }
719 ]
720 })
721
722 await waitJobs(servers)
723
724 await servers[0].servers.waitUntilLog('Run hook filter:job-queue.process.params', 1, false)
725
726 const video = await servers[0].videos.get({ id: videoUUID })
727 expect(video.duration).at.most(2)
728 })
729
730 it('Should run filter:job-queue.process.result', async function () {
731 await servers[0].servers.waitUntilLog('Run hook filter:job-queue.process.result', 1, false)
732 })
733 })
734
735 describe('Transcoding filters', async function () {
736
737 it('Should run filter:transcoding.auto.resolutions-to-transcode.result', async function () {
738 const { uuid } = await servers[0].videos.quickUpload({ name: 'transcode-filter' })
739
740 await waitJobs(servers)
741
742 const video = await servers[0].videos.get({ id: uuid })
743 expect(video.files).to.have.lengthOf(2)
744 expect(video.files.find(f => f.resolution.id === 100 as any)).to.exist
745 })
746 })
747
748 describe('Video channel filters', async function () {
749
750 it('Should run filter:api.video-channels.list.params', async function () {
751 const { data } = await servers[0].channels.list({ start: 0, count: 0 })
752
753 // plugin do +1 to the count parameter
754 expect(data).to.have.lengthOf(1)
755 })
756
757 it('Should run filter:api.video-channels.list.result', async function () {
758 const { total } = await servers[0].channels.list({ start: 0, count: 1 })
759
760 // plugin do +1 to the total parameter
761 expect(total).to.equal(4)
762 })
763
764 it('Should run filter:api.video-channel.get.result', async function () {
765 const channel = await servers[0].channels.get({ channelName: 'root_channel' })
766 expect(channel.displayName).to.equal('Main root channel <3')
767 })
768 })
769
770 after(async function () {
771 await cleanupTests(servers)
772 })
773 })