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