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