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