]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/filter-hooks.ts
Merge branch 'feature/improve-live' 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 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 let downloadVideo2Token: string
434
435 before(async function () {
436 this.timeout(120000)
437
438 await servers[0].config.updateCustomSubConfig({
439 newConfig: {
440 transcoding: {
441 webtorrent: {
442 enabled: true
443 },
444 hls: {
445 enabled: true
446 }
447 }
448 }
449 })
450
451 const uuids: string[] = []
452
453 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
454 const uuid = (await servers[0].videos.quickUpload({ name })).uuid
455 uuids.push(uuid)
456 }
457
458 await waitJobs(servers)
459
460 for (const uuid of uuids) {
461 downloadVideos.push(await servers[0].videos.get({ id: uuid }))
462 }
463
464 downloadVideo2Token = await servers[0].videoToken.getVideoFileToken({ videoId: downloadVideos[2].uuid })
465 })
466
467 it('Should run filter:api.download.torrent.allowed.result', async function () {
468 const res = await makeRawRequest({ url: downloadVideos[0].files[0].torrentDownloadUrl, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
469 expect(res.body.error).to.equal('Liu Bei')
470
471 await makeRawRequest({ url: downloadVideos[1].files[0].torrentDownloadUrl, expectedStatus: HttpStatusCode.OK_200 })
472 await makeRawRequest({ url: downloadVideos[2].files[0].torrentDownloadUrl, expectedStatus: HttpStatusCode.OK_200 })
473 })
474
475 it('Should run filter:api.download.video.allowed.result', async function () {
476 {
477 const refused = downloadVideos[1].files[0].fileDownloadUrl
478 const allowed = [
479 downloadVideos[0].files[0].fileDownloadUrl,
480 downloadVideos[2].files[0].fileDownloadUrl
481 ]
482
483 const res = await makeRawRequest({ url: refused, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
484 expect(res.body.error).to.equal('Cao Cao')
485
486 for (const url of allowed) {
487 await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
488 await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
489 }
490 }
491
492 {
493 const refused = downloadVideos[2].streamingPlaylists[0].files[0].fileDownloadUrl
494
495 const allowed = [
496 downloadVideos[2].files[0].fileDownloadUrl,
497 downloadVideos[0].streamingPlaylists[0].files[0].fileDownloadUrl,
498 downloadVideos[1].streamingPlaylists[0].files[0].fileDownloadUrl
499 ]
500
501 // Only streaming playlist is refuse
502 const res = await makeRawRequest({ url: refused, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
503 expect(res.body.error).to.equal('Sun Jian')
504
505 // But not we there is a user in res
506 await makeRawRequest({ url: refused, token: servers[0].accessToken, expectedStatus: HttpStatusCode.OK_200 })
507 await makeRawRequest({ url: refused, query: { videoFileToken: downloadVideo2Token }, expectedStatus: HttpStatusCode.OK_200 })
508
509 // Other files work
510 for (const url of allowed) {
511 await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
512 }
513 }
514 })
515 })
516
517 describe('Embed filters', function () {
518 const embedVideos: VideoDetails[] = []
519 const embedPlaylists: VideoPlaylist[] = []
520
521 before(async function () {
522 this.timeout(60000)
523
524 await servers[0].config.disableTranscoding()
525
526 for (const name of [ 'bad embed', 'good embed' ]) {
527 {
528 const uuid = (await servers[0].videos.quickUpload({ name })).uuid
529 embedVideos.push(await servers[0].videos.get({ id: uuid }))
530 }
531
532 {
533 const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC }
534 const { id } = await servers[0].playlists.create({ attributes })
535
536 const playlist = await servers[0].playlists.get({ playlistId: id })
537 embedPlaylists.push(playlist)
538 }
539 }
540 })
541
542 it('Should run filter:html.embed.video.allowed.result', async function () {
543 const res = await makeGetRequest({ url: servers[0].url, path: embedVideos[0].embedPath, expectedStatus: HttpStatusCode.OK_200 })
544 expect(res.text).to.equal('Lu Bu')
545 })
546
547 it('Should run filter:html.embed.video-playlist.allowed.result', async function () {
548 const res = await makeGetRequest({ url: servers[0].url, path: embedPlaylists[0].embedPath, expectedStatus: HttpStatusCode.OK_200 })
549 expect(res.text).to.equal('Diao Chan')
550 })
551 })
552
553 describe('Search filters', function () {
554
555 before(async function () {
556 await servers[0].config.updateCustomSubConfig({
557 newConfig: {
558 search: {
559 searchIndex: {
560 enabled: true,
561 isDefaultSearch: false,
562 disableLocalSearch: false
563 }
564 }
565 }
566 })
567 })
568
569 it('Should run filter:api.search.videos.local.list.{params,result}', async function () {
570 await servers[0].search.advancedVideoSearch({
571 search: {
572 search: 'Sun Quan'
573 }
574 })
575
576 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
577 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
578 })
579
580 it('Should run filter:api.search.videos.index.list.{params,result}', async function () {
581 await servers[0].search.advancedVideoSearch({
582 search: {
583 search: 'Sun Quan',
584 searchTarget: 'search-index'
585 }
586 })
587
588 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
589 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
590 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1)
591 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1)
592 })
593
594 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () {
595 await servers[0].search.advancedChannelSearch({
596 search: {
597 search: 'Sun Ce'
598 }
599 })
600
601 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
602 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
603 })
604
605 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () {
606 await servers[0].search.advancedChannelSearch({
607 search: {
608 search: 'Sun Ce',
609 searchTarget: 'search-index'
610 }
611 })
612
613 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
614 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
615 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1)
616 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1)
617 })
618
619 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () {
620 await servers[0].search.advancedPlaylistSearch({
621 search: {
622 search: 'Sun Jian'
623 }
624 })
625
626 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
627 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
628 })
629
630 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () {
631 await servers[0].search.advancedPlaylistSearch({
632 search: {
633 search: 'Sun Jian',
634 searchTarget: 'search-index'
635 }
636 })
637
638 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
639 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
640 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1)
641 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1)
642 })
643 })
644
645 describe('Upload/import/live attributes filters', function () {
646
647 before(async function () {
648 await servers[0].config.enableLive({ transcoding: false, allowReplay: false })
649 await servers[0].config.enableImports()
650 await servers[0].config.disableTranscoding()
651 })
652
653 it('Should run filter:api.video.upload.video-attribute.result', async function () {
654 for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
655 const { id } = await servers[0].videos.upload({ attributes: { name: 'video', description: 'upload' }, mode })
656
657 const video = await servers[0].videos.get({ id })
658 expect(video.description).to.equal('upload - filter:api.video.upload.video-attribute.result')
659 }
660 })
661
662 it('Should run filter:api.video.import-url.video-attribute.result', async function () {
663 const attributes = {
664 name: 'video',
665 description: 'import url',
666 channelId: servers[0].store.channel.id,
667 targetUrl: FIXTURE_URLS.goodVideo,
668 privacy: VideoPrivacy.PUBLIC
669 }
670 const { video: { id } } = await servers[0].imports.importVideo({ attributes })
671
672 const video = await servers[0].videos.get({ id })
673 expect(video.description).to.equal('import url - filter:api.video.import-url.video-attribute.result')
674 })
675
676 it('Should run filter:api.video.import-torrent.video-attribute.result', async function () {
677 const attributes = {
678 name: 'video',
679 description: 'import torrent',
680 channelId: servers[0].store.channel.id,
681 magnetUri: FIXTURE_URLS.magnet,
682 privacy: VideoPrivacy.PUBLIC
683 }
684 const { video: { id } } = await servers[0].imports.importVideo({ attributes })
685
686 const video = await servers[0].videos.get({ id })
687 expect(video.description).to.equal('import torrent - filter:api.video.import-torrent.video-attribute.result')
688 })
689
690 it('Should run filter:api.video.live.video-attribute.result', async function () {
691 const fields = {
692 name: 'live',
693 description: 'live',
694 channelId: servers[0].store.channel.id,
695 privacy: VideoPrivacy.PUBLIC
696 }
697 const { id } = await servers[0].live.create({ fields })
698
699 const video = await servers[0].videos.get({ id })
700 expect(video.description).to.equal('live - filter:api.video.live.video-attribute.result')
701 })
702 })
703
704 describe('Stats filters', function () {
705
706 it('Should run filter:api.server.stats.get.result', async function () {
707 const data = await servers[0].stats.get()
708
709 expect((data as any).customStats).to.equal(14)
710 })
711
712 })
713
714 describe('Job queue filters', function () {
715 let videoUUID: string
716
717 before(async function () {
718 this.timeout(120_000)
719
720 await servers[0].config.enableMinimumTranscoding()
721 const { uuid } = await servers[0].videos.quickUpload({ name: 'studio' })
722
723 const video = await servers[0].videos.get({ id: uuid })
724 expect(video.duration).at.least(2)
725 videoUUID = video.uuid
726
727 await waitJobs(servers)
728
729 await servers[0].config.enableStudio()
730 })
731
732 it('Should run filter:job-queue.process.params', async function () {
733 this.timeout(120_000)
734
735 await servers[0].videoStudio.createEditionTasks({
736 videoId: videoUUID,
737 tasks: [
738 {
739 name: 'add-intro',
740 options: {
741 file: 'video_very_short_240p.mp4'
742 }
743 }
744 ]
745 })
746
747 await waitJobs(servers)
748
749 await servers[0].servers.waitUntilLog('Run hook filter:job-queue.process.params', 1, false)
750
751 const video = await servers[0].videos.get({ id: videoUUID })
752 expect(video.duration).at.most(2)
753 })
754
755 it('Should run filter:job-queue.process.result', async function () {
756 await servers[0].servers.waitUntilLog('Run hook filter:job-queue.process.result', 1, false)
757 })
758 })
759
760 describe('Transcoding filters', async function () {
761
762 it('Should run filter:transcoding.auto.resolutions-to-transcode.result', async function () {
763 const { uuid } = await servers[0].videos.quickUpload({ name: 'transcode-filter' })
764
765 await waitJobs(servers)
766
767 const video = await servers[0].videos.get({ id: uuid })
768 expect(video.files).to.have.lengthOf(2)
769 expect(video.files.find(f => f.resolution.id === 100 as any)).to.exist
770 })
771 })
772
773 describe('Video channel filters', async function () {
774
775 it('Should run filter:api.video-channels.list.params', async function () {
776 const { data } = await servers[0].channels.list({ start: 0, count: 0 })
777
778 // plugin do +1 to the count parameter
779 expect(data).to.have.lengthOf(1)
780 })
781
782 it('Should run filter:api.video-channels.list.result', async function () {
783 const { total } = await servers[0].channels.list({ start: 0, count: 1 })
784
785 // plugin do +1 to the total parameter
786 expect(total).to.equal(4)
787 })
788
789 it('Should run filter:api.video-channel.get.result', async function () {
790 const channel = await servers[0].channels.get({ channelName: 'root_channel' })
791 expect(channel.displayName).to.equal('Main root channel <3')
792 })
793 })
794
795 after(async function () {
796 await cleanupTests(servers)
797 })
798 })