]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
d525fc39 | 2 | |
d525fc39 | 3 | import 'mocha' |
1fd61899 | 4 | import * as chai from 'chai' |
d525fc39 | 5 | import { |
7243f84d | 6 | cleanupTests, |
210feb6c | 7 | flushAndRunServer, |
7243f84d | 8 | immutableAssign, |
af971e06 | 9 | SearchCommand, |
d525fc39 C |
10 | ServerInfo, |
11 | setAccessTokensToServers, | |
1fd61899 C |
12 | setDefaultVideoChannel, |
13 | stopFfmpeg, | |
d525fc39 | 14 | uploadVideo, |
4f219914 C |
15 | wait |
16 | } from '@shared/extra-utils' | |
17 | import { VideoPrivacy } from '@shared/models' | |
d525fc39 C |
18 | |
19 | const expect = chai.expect | |
20 | ||
da3a3ab6 | 21 | describe('Test videos search', function () { |
d525fc39 C |
22 | let server: ServerInfo = null |
23 | let startDate: string | |
3cf53828 | 24 | let videoUUID: string |
d525fc39 | 25 | |
af971e06 C |
26 | let command: SearchCommand |
27 | ||
d525fc39 | 28 | before(async function () { |
3e3ae966 | 29 | this.timeout(60000) |
d525fc39 | 30 | |
210feb6c | 31 | server = await flushAndRunServer(1) |
d525fc39 C |
32 | |
33 | await setAccessTokensToServers([ server ]) | |
1fd61899 | 34 | await setDefaultVideoChannel([ server ]) |
d525fc39 C |
35 | |
36 | { | |
37 | const attributes1 = { | |
38 | name: '1111 2222 3333', | |
39 | fixture: '60fps_720p_small.mp4', // 2 seconds | |
40 | category: 1, | |
41 | licence: 1, | |
42 | nsfw: false, | |
43 | language: 'fr' | |
44 | } | |
45 | await uploadVideo(server.url, server.accessToken, attributes1) | |
46 | ||
47 | const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }) | |
48 | await uploadVideo(server.url, server.accessToken, attributes2) | |
49 | ||
3caf77d3 C |
50 | { |
51 | const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined }) | |
52 | const res = await uploadVideo(server.url, server.accessToken, attributes3) | |
53 | const videoId = res.body.video.id | |
3cf53828 | 54 | videoUUID = res.body.video.uuid |
3caf77d3 | 55 | |
a2470c9f | 56 | await server.captionsCommand.createVideoCaption({ |
3caf77d3 C |
57 | language: 'en', |
58 | videoId, | |
59 | fixture: 'subtitle-good2.vtt', | |
60 | mimeType: 'application/octet-stream' | |
61 | }) | |
62 | ||
a2470c9f | 63 | await server.captionsCommand.createVideoCaption({ |
3caf77d3 C |
64 | language: 'aa', |
65 | videoId, | |
66 | fixture: 'subtitle-good2.vtt', | |
67 | mimeType: 'application/octet-stream' | |
68 | }) | |
69 | } | |
d525fc39 C |
70 | |
71 | const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true }) | |
72 | await uploadVideo(server.url, server.accessToken, attributes4) | |
73 | ||
74 | await wait(1000) | |
75 | ||
76 | startDate = new Date().toISOString() | |
77 | ||
3caf77d3 | 78 | const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined }) |
d525fc39 C |
79 | await uploadVideo(server.url, server.accessToken, attributes5) |
80 | ||
a1587156 | 81 | const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }) |
d525fc39 C |
82 | await uploadVideo(server.url, server.accessToken, attributes6) |
83 | ||
31d065cc AM |
84 | const attributes7 = immutableAssign(attributes1, { |
85 | name: attributes1.name + ' - 7', | |
86 | originallyPublishedAt: '2019-02-12T09:58:08.286Z' | |
87 | }) | |
d525fc39 C |
88 | await uploadVideo(server.url, server.accessToken, attributes7) |
89 | ||
90 | const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) | |
91 | await uploadVideo(server.url, server.accessToken, attributes8) | |
92 | } | |
93 | ||
94 | { | |
95 | const attributes = { | |
96 | name: '3333 4444 5555', | |
97 | fixture: 'video_short.mp4', | |
98 | category: 2, | |
99 | licence: 2, | |
100 | language: 'en' | |
101 | } | |
102 | await uploadVideo(server.url, server.accessToken, attributes) | |
103 | ||
104 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' })) | |
105 | } | |
106 | ||
107 | { | |
108 | const attributes = { | |
109 | name: '6666 7777 8888', | |
110 | fixture: 'video_short.mp4', | |
111 | category: 3, | |
112 | licence: 3, | |
113 | language: 'pl' | |
114 | } | |
115 | await uploadVideo(server.url, server.accessToken, attributes) | |
116 | } | |
117 | ||
118 | { | |
119 | const attributes1 = { | |
120 | name: '9999', | |
121 | tags: [ 'aaaa', 'bbbb', 'cccc' ], | |
122 | category: 1 | |
123 | } | |
124 | await uploadVideo(server.url, server.accessToken, attributes1) | |
125 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) | |
126 | ||
127 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] })) | |
128 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] })) | |
129 | } | |
d4112450 C |
130 | |
131 | { | |
132 | const attributes1 = { | |
133 | name: 'aaaa 2', | |
134 | category: 1 | |
135 | } | |
136 | await uploadVideo(server.url, server.accessToken, attributes1) | |
137 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) | |
138 | } | |
af971e06 C |
139 | |
140 | command = server.searchCommand | |
d525fc39 C |
141 | }) |
142 | ||
143 | it('Should make a simple search and not have results', async function () { | |
af971e06 | 144 | const body = await command.searchVideos({ search: 'abc' }) |
d525fc39 | 145 | |
af971e06 C |
146 | expect(body.total).to.equal(0) |
147 | expect(body.data).to.have.lengthOf(0) | |
d525fc39 C |
148 | }) |
149 | ||
150 | it('Should make a simple search and have results', async function () { | |
af971e06 | 151 | const body = await command.searchVideos({ search: '4444 5555 duplicate' }) |
d525fc39 | 152 | |
af971e06 | 153 | expect(body.total).to.equal(2) |
d525fc39 | 154 | |
af971e06 | 155 | const videos = body.data |
d525fc39 C |
156 | expect(videos).to.have.lengthOf(2) |
157 | ||
158 | // bestmatch | |
159 | expect(videos[0].name).to.equal('3333 4444 5555 duplicate') | |
160 | expect(videos[1].name).to.equal('3333 4444 5555') | |
161 | }) | |
162 | ||
d4112450 | 163 | it('Should make a search on tags too, and have results', async function () { |
af971e06 | 164 | const search = { |
d4112450 C |
165 | search: 'aaaa', |
166 | categoryOneOf: [ 1 ] | |
167 | } | |
af971e06 | 168 | const body = await command.advancedVideoSearch({ search }) |
d4112450 | 169 | |
af971e06 | 170 | expect(body.total).to.equal(2) |
d4112450 | 171 | |
af971e06 | 172 | const videos = body.data |
d4112450 C |
173 | expect(videos).to.have.lengthOf(2) |
174 | ||
175 | // bestmatch | |
176 | expect(videos[0].name).to.equal('aaaa 2') | |
177 | expect(videos[1].name).to.equal('9999') | |
178 | }) | |
179 | ||
180 | it('Should filter on tags without a search', async function () { | |
af971e06 | 181 | const search = { |
d4112450 C |
182 | tagsAllOf: [ 'bbbb' ] |
183 | } | |
af971e06 | 184 | const body = await command.advancedVideoSearch({ search }) |
d4112450 | 185 | |
af971e06 | 186 | expect(body.total).to.equal(2) |
d4112450 | 187 | |
af971e06 | 188 | const videos = body.data |
d4112450 C |
189 | expect(videos).to.have.lengthOf(2) |
190 | ||
191 | expect(videos[0].name).to.equal('9999') | |
192 | expect(videos[1].name).to.equal('9999') | |
193 | }) | |
194 | ||
195 | it('Should filter on category without a search', async function () { | |
af971e06 | 196 | const search = { |
d4112450 C |
197 | categoryOneOf: [ 3 ] |
198 | } | |
af971e06 | 199 | const body = await command.advancedVideoSearch({ search: search }) |
d4112450 | 200 | |
af971e06 | 201 | expect(body.total).to.equal(1) |
d4112450 | 202 | |
af971e06 | 203 | const videos = body.data |
d4112450 C |
204 | expect(videos).to.have.lengthOf(1) |
205 | ||
206 | expect(videos[0].name).to.equal('6666 7777 8888') | |
207 | }) | |
208 | ||
d525fc39 C |
209 | it('Should search by tags (one of)', async function () { |
210 | const query = { | |
211 | search: '9999', | |
212 | categoryOneOf: [ 1 ], | |
4b1f1b81 | 213 | tagsOneOf: [ 'aAaa', 'ffff' ] |
d525fc39 | 214 | } |
d525fc39 | 215 | |
af971e06 C |
216 | { |
217 | const body = await command.advancedVideoSearch({ search: query }) | |
218 | expect(body.total).to.equal(2) | |
219 | } | |
220 | ||
221 | { | |
222 | const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } }) | |
223 | expect(body.total).to.equal(0) | |
224 | } | |
d525fc39 C |
225 | }) |
226 | ||
227 | it('Should search by tags (all of)', async function () { | |
228 | const query = { | |
229 | search: '9999', | |
230 | categoryOneOf: [ 1 ], | |
4b1f1b81 | 231 | tagsAllOf: [ 'CCcc' ] |
d525fc39 | 232 | } |
d525fc39 | 233 | |
af971e06 C |
234 | { |
235 | const body = await command.advancedVideoSearch({ search: query }) | |
236 | expect(body.total).to.equal(2) | |
237 | } | |
d525fc39 | 238 | |
af971e06 C |
239 | { |
240 | const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } }) | |
241 | expect(body.total).to.equal(0) | |
242 | } | |
243 | ||
244 | { | |
245 | const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } }) | |
246 | expect(body.total).to.equal(1) | |
247 | } | |
d525fc39 C |
248 | }) |
249 | ||
250 | it('Should search by category', async function () { | |
251 | const query = { | |
252 | search: '6666', | |
253 | categoryOneOf: [ 3 ] | |
254 | } | |
d525fc39 | 255 | |
af971e06 C |
256 | { |
257 | const body = await command.advancedVideoSearch({ search: query }) | |
258 | expect(body.total).to.equal(1) | |
259 | expect(body.data[0].name).to.equal('6666 7777 8888') | |
260 | } | |
261 | ||
262 | { | |
263 | const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } }) | |
264 | expect(body.total).to.equal(0) | |
265 | } | |
d525fc39 C |
266 | }) |
267 | ||
268 | it('Should search by licence', async function () { | |
269 | const query = { | |
270 | search: '4444 5555', | |
271 | licenceOneOf: [ 2 ] | |
272 | } | |
d525fc39 | 273 | |
af971e06 C |
274 | { |
275 | const body = await command.advancedVideoSearch({ search: query }) | |
276 | expect(body.total).to.equal(2) | |
277 | expect(body.data[0].name).to.equal('3333 4444 5555') | |
278 | expect(body.data[1].name).to.equal('3333 4444 5555 duplicate') | |
279 | } | |
280 | ||
281 | { | |
282 | const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } }) | |
283 | expect(body.total).to.equal(0) | |
284 | } | |
d525fc39 C |
285 | }) |
286 | ||
287 | it('Should search by languages', async function () { | |
288 | const query = { | |
289 | search: '1111 2222 3333', | |
290 | languageOneOf: [ 'pl', 'en' ] | |
291 | } | |
d525fc39 | 292 | |
3caf77d3 | 293 | { |
af971e06 C |
294 | const body = await command.advancedVideoSearch({ search: query }) |
295 | expect(body.total).to.equal(2) | |
296 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') | |
297 | expect(body.data[1].name).to.equal('1111 2222 3333 - 4') | |
3caf77d3 C |
298 | } |
299 | ||
300 | { | |
af971e06 C |
301 | const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } }) |
302 | expect(body.total).to.equal(3) | |
303 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') | |
304 | expect(body.data[1].name).to.equal('1111 2222 3333 - 4') | |
305 | expect(body.data[2].name).to.equal('1111 2222 3333 - 5') | |
3caf77d3 C |
306 | } |
307 | ||
308 | { | |
af971e06 C |
309 | const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } }) |
310 | expect(body.total).to.equal(0) | |
3caf77d3 | 311 | } |
d525fc39 C |
312 | }) |
313 | ||
314 | it('Should search by start date', async function () { | |
315 | const query = { | |
316 | search: '1111 2222 3333', | |
317 | startDate | |
318 | } | |
319 | ||
af971e06 C |
320 | const body = await command.advancedVideoSearch({ search: query }) |
321 | expect(body.total).to.equal(4) | |
d525fc39 | 322 | |
af971e06 | 323 | const videos = body.data |
d525fc39 C |
324 | expect(videos[0].name).to.equal('1111 2222 3333 - 5') |
325 | expect(videos[1].name).to.equal('1111 2222 3333 - 6') | |
326 | expect(videos[2].name).to.equal('1111 2222 3333 - 7') | |
327 | expect(videos[3].name).to.equal('1111 2222 3333 - 8') | |
328 | }) | |
329 | ||
330 | it('Should make an advanced search', async function () { | |
331 | const query = { | |
332 | search: '1111 2222 3333', | |
333 | languageOneOf: [ 'pl', 'fr' ], | |
334 | durationMax: 4, | |
0b18f4aa | 335 | nsfw: 'false' as 'false', |
d525fc39 C |
336 | licenceOneOf: [ 1, 4 ] |
337 | } | |
338 | ||
af971e06 C |
339 | const body = await command.advancedVideoSearch({ search: query }) |
340 | expect(body.total).to.equal(4) | |
d525fc39 | 341 | |
af971e06 | 342 | const videos = body.data |
d525fc39 C |
343 | expect(videos[0].name).to.equal('1111 2222 3333') |
344 | expect(videos[1].name).to.equal('1111 2222 3333 - 6') | |
345 | expect(videos[2].name).to.equal('1111 2222 3333 - 7') | |
346 | expect(videos[3].name).to.equal('1111 2222 3333 - 8') | |
347 | }) | |
348 | ||
349 | it('Should make an advanced search and sort results', async function () { | |
350 | const query = { | |
351 | search: '1111 2222 3333', | |
352 | languageOneOf: [ 'pl', 'fr' ], | |
353 | durationMax: 4, | |
0b18f4aa | 354 | nsfw: 'false' as 'false', |
d525fc39 C |
355 | licenceOneOf: [ 1, 4 ], |
356 | sort: '-name' | |
357 | } | |
358 | ||
af971e06 C |
359 | const body = await command.advancedVideoSearch({ search: query }) |
360 | expect(body.total).to.equal(4) | |
d525fc39 | 361 | |
af971e06 | 362 | const videos = body.data |
d525fc39 C |
363 | expect(videos[0].name).to.equal('1111 2222 3333 - 8') |
364 | expect(videos[1].name).to.equal('1111 2222 3333 - 7') | |
365 | expect(videos[2].name).to.equal('1111 2222 3333 - 6') | |
366 | expect(videos[3].name).to.equal('1111 2222 3333') | |
367 | }) | |
368 | ||
369 | it('Should make an advanced search and only show the first result', async function () { | |
370 | const query = { | |
371 | search: '1111 2222 3333', | |
372 | languageOneOf: [ 'pl', 'fr' ], | |
373 | durationMax: 4, | |
0b18f4aa | 374 | nsfw: 'false' as 'false', |
d525fc39 C |
375 | licenceOneOf: [ 1, 4 ], |
376 | sort: '-name', | |
377 | start: 0, | |
378 | count: 1 | |
379 | } | |
380 | ||
af971e06 C |
381 | const body = await command.advancedVideoSearch({ search: query }) |
382 | expect(body.total).to.equal(4) | |
d525fc39 | 383 | |
af971e06 | 384 | const videos = body.data |
d525fc39 C |
385 | expect(videos[0].name).to.equal('1111 2222 3333 - 8') |
386 | }) | |
387 | ||
388 | it('Should make an advanced search and only show the last result', async function () { | |
389 | const query = { | |
390 | search: '1111 2222 3333', | |
391 | languageOneOf: [ 'pl', 'fr' ], | |
392 | durationMax: 4, | |
0b18f4aa | 393 | nsfw: 'false' as 'false', |
d525fc39 C |
394 | licenceOneOf: [ 1, 4 ], |
395 | sort: '-name', | |
396 | start: 3, | |
397 | count: 1 | |
398 | } | |
399 | ||
af971e06 C |
400 | const body = await command.advancedVideoSearch({ search: query }) |
401 | expect(body.total).to.equal(4) | |
d525fc39 | 402 | |
af971e06 | 403 | const videos = body.data |
d525fc39 C |
404 | expect(videos[0].name).to.equal('1111 2222 3333') |
405 | }) | |
406 | ||
31d065cc AM |
407 | it('Should search on originally published date', async function () { |
408 | const baseQuery = { | |
409 | search: '1111 2222 3333', | |
410 | languageOneOf: [ 'pl', 'fr' ], | |
411 | durationMax: 4, | |
412 | nsfw: 'false' as 'false', | |
413 | licenceOneOf: [ 1, 4 ] | |
414 | } | |
415 | ||
416 | { | |
417 | const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) | |
af971e06 | 418 | const body = await command.advancedVideoSearch({ search: query }) |
31d065cc | 419 | |
af971e06 C |
420 | expect(body.total).to.equal(1) |
421 | expect(body.data[0].name).to.equal('1111 2222 3333 - 7') | |
31d065cc AM |
422 | } |
423 | ||
424 | { | |
425 | const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) | |
af971e06 | 426 | const body = await command.advancedVideoSearch({ search: query }) |
31d065cc | 427 | |
af971e06 C |
428 | expect(body.total).to.equal(1) |
429 | expect(body.data[0].name).to.equal('1111 2222 3333 - 7') | |
31d065cc AM |
430 | } |
431 | ||
432 | { | |
433 | const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) | |
af971e06 | 434 | const body = await command.advancedVideoSearch({ search: query }) |
31d065cc | 435 | |
af971e06 | 436 | expect(body.total).to.equal(0) |
31d065cc AM |
437 | } |
438 | ||
439 | { | |
440 | const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) | |
af971e06 | 441 | const body = await command.advancedVideoSearch({ search: query }) |
31d065cc | 442 | |
af971e06 | 443 | expect(body.total).to.equal(0) |
31d065cc AM |
444 | } |
445 | ||
446 | { | |
447 | const query = immutableAssign(baseQuery, { | |
448 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', | |
449 | originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' | |
450 | }) | |
af971e06 | 451 | const body = await command.advancedVideoSearch({ search: query }) |
31d065cc | 452 | |
af971e06 | 453 | expect(body.total).to.equal(0) |
31d065cc AM |
454 | } |
455 | ||
456 | { | |
457 | const query = immutableAssign(baseQuery, { | |
458 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', | |
459 | originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' | |
460 | }) | |
af971e06 | 461 | const body = await command.advancedVideoSearch({ search: query }) |
31d065cc | 462 | |
af971e06 C |
463 | expect(body.total).to.equal(1) |
464 | expect(body.data[0].name).to.equal('1111 2222 3333 - 7') | |
31d065cc AM |
465 | } |
466 | }) | |
467 | ||
3cf53828 C |
468 | it('Should search by UUID', async function () { |
469 | const search = videoUUID | |
af971e06 | 470 | const body = await command.advancedVideoSearch({ search: { search } }) |
3cf53828 | 471 | |
af971e06 C |
472 | expect(body.total).to.equal(1) |
473 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') | |
3cf53828 C |
474 | }) |
475 | ||
1fd61899 C |
476 | it('Should search by live', async function () { |
477 | this.timeout(30000) | |
478 | ||
479 | { | |
65e6e260 | 480 | const newConfig = { |
1fd61899 C |
481 | search: { |
482 | searchIndex: { enabled: false } | |
483 | }, | |
484 | live: { enabled: true } | |
485 | } | |
65e6e260 | 486 | await server.configCommand.updateCustomSubConfig({ newConfig }) |
1fd61899 C |
487 | } |
488 | ||
489 | { | |
af971e06 | 490 | const body = await command.advancedVideoSearch({ search: { isLive: true } }) |
1fd61899 | 491 | |
af971e06 C |
492 | expect(body.total).to.equal(0) |
493 | expect(body.data).to.have.lengthOf(0) | |
1fd61899 C |
494 | } |
495 | ||
496 | { | |
4f219914 C |
497 | const liveCommand = server.liveCommand |
498 | ||
499 | const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id } | |
04aed767 | 500 | const live = await liveCommand.create({ fields: liveAttributes }) |
1fd61899 | 501 | |
4f219914 | 502 | const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id }) |
04aed767 | 503 | await liveCommand.waitUntilPublished({ videoId: live.id }) |
1fd61899 | 504 | |
af971e06 | 505 | const body = await command.advancedVideoSearch({ search: { isLive: true } }) |
1fd61899 | 506 | |
af971e06 C |
507 | expect(body.total).to.equal(1) |
508 | expect(body.data[0].name).to.equal('live') | |
1fd61899 | 509 | |
af971e06 | 510 | await stopFfmpeg(ffmpegCommand) |
1fd61899 C |
511 | } |
512 | }) | |
513 | ||
7c3b7976 C |
514 | after(async function () { |
515 | await cleanupTests([ server ]) | |
d525fc39 C |
516 | }) |
517 | }) |