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