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