1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
17 } from '@shared/extra-utils'
18 import { VideoPrivacy } from '@shared/models'
20 const expect = chai.expect
22 describe('Test videos search', function () {
23 let server: ServerInfo = null
27 let command: SearchCommand
29 before(async function () {
32 server = await flushAndRunServer(1)
34 await setAccessTokensToServers([ server ])
35 await setDefaultVideoChannel([ server ])
39 name: '1111 2222 3333',
40 fixture: '60fps_720p_small.mp4', // 2 seconds
46 await uploadVideo(server.url, server.accessToken, attributes1)
48 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
49 await uploadVideo(server.url, server.accessToken, attributes2)
52 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined })
53 const res = await uploadVideo(server.url, server.accessToken, attributes3)
54 const videoId = res.body.video.id
55 videoUUID = res.body.video.uuid
57 await createVideoCaption({
59 accessToken: server.accessToken,
62 fixture: 'subtitle-good2.vtt',
63 mimeType: 'application/octet-stream'
66 await createVideoCaption({
68 accessToken: server.accessToken,
71 fixture: 'subtitle-good2.vtt',
72 mimeType: 'application/octet-stream'
76 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
77 await uploadVideo(server.url, server.accessToken, attributes4)
81 startDate = new Date().toISOString()
83 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined })
84 await uploadVideo(server.url, server.accessToken, attributes5)
86 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] })
87 await uploadVideo(server.url, server.accessToken, attributes6)
89 const attributes7 = immutableAssign(attributes1, {
90 name: attributes1.name + ' - 7',
91 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
93 await uploadVideo(server.url, server.accessToken, attributes7)
95 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
96 await uploadVideo(server.url, server.accessToken, attributes8)
101 name: '3333 4444 5555',
102 fixture: 'video_short.mp4',
107 await uploadVideo(server.url, server.accessToken, attributes)
109 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
114 name: '6666 7777 8888',
115 fixture: 'video_short.mp4',
120 await uploadVideo(server.url, server.accessToken, attributes)
124 const attributes1 = {
126 tags: [ 'aaaa', 'bbbb', 'cccc' ],
129 await uploadVideo(server.url, server.accessToken, attributes1)
130 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
132 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
133 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
137 const attributes1 = {
141 await uploadVideo(server.url, server.accessToken, attributes1)
142 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
145 command = server.searchCommand
148 it('Should make a simple search and not have results', async function () {
149 const body = await command.searchVideos({ search: 'abc' })
151 expect(body.total).to.equal(0)
152 expect(body.data).to.have.lengthOf(0)
155 it('Should make a simple search and have results', async function () {
156 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
158 expect(body.total).to.equal(2)
160 const videos = body.data
161 expect(videos).to.have.lengthOf(2)
164 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
165 expect(videos[1].name).to.equal('3333 4444 5555')
168 it('Should make a search on tags too, and have results', async function () {
173 const body = await command.advancedVideoSearch({ search })
175 expect(body.total).to.equal(2)
177 const videos = body.data
178 expect(videos).to.have.lengthOf(2)
181 expect(videos[0].name).to.equal('aaaa 2')
182 expect(videos[1].name).to.equal('9999')
185 it('Should filter on tags without a search', async function () {
187 tagsAllOf: [ 'bbbb' ]
189 const body = await command.advancedVideoSearch({ search })
191 expect(body.total).to.equal(2)
193 const videos = body.data
194 expect(videos).to.have.lengthOf(2)
196 expect(videos[0].name).to.equal('9999')
197 expect(videos[1].name).to.equal('9999')
200 it('Should filter on category without a search', async function () {
204 const body = await command.advancedVideoSearch({ search: search })
206 expect(body.total).to.equal(1)
208 const videos = body.data
209 expect(videos).to.have.lengthOf(1)
211 expect(videos[0].name).to.equal('6666 7777 8888')
214 it('Should search by tags (one of)', async function () {
217 categoryOneOf: [ 1 ],
218 tagsOneOf: [ 'aAaa', 'ffff' ]
222 const body = await command.advancedVideoSearch({ search: query })
223 expect(body.total).to.equal(2)
227 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
228 expect(body.total).to.equal(0)
232 it('Should search by tags (all of)', async function () {
235 categoryOneOf: [ 1 ],
236 tagsAllOf: [ 'CCcc' ]
240 const body = await command.advancedVideoSearch({ search: query })
241 expect(body.total).to.equal(2)
245 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
246 expect(body.total).to.equal(0)
250 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
251 expect(body.total).to.equal(1)
255 it('Should search by category', async function () {
262 const body = await command.advancedVideoSearch({ search: query })
263 expect(body.total).to.equal(1)
264 expect(body.data[0].name).to.equal('6666 7777 8888')
268 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
269 expect(body.total).to.equal(0)
273 it('Should search by licence', async function () {
280 const body = await command.advancedVideoSearch({ search: query })
281 expect(body.total).to.equal(2)
282 expect(body.data[0].name).to.equal('3333 4444 5555')
283 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
287 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
288 expect(body.total).to.equal(0)
292 it('Should search by languages', async function () {
294 search: '1111 2222 3333',
295 languageOneOf: [ 'pl', 'en' ]
299 const body = await command.advancedVideoSearch({ search: query })
300 expect(body.total).to.equal(2)
301 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
302 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
306 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
307 expect(body.total).to.equal(3)
308 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
309 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
310 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
314 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
315 expect(body.total).to.equal(0)
319 it('Should search by start date', async function () {
321 search: '1111 2222 3333',
325 const body = await command.advancedVideoSearch({ search: query })
326 expect(body.total).to.equal(4)
328 const videos = body.data
329 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
330 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
331 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
332 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
335 it('Should make an advanced search', async function () {
337 search: '1111 2222 3333',
338 languageOneOf: [ 'pl', 'fr' ],
340 nsfw: 'false' as 'false',
341 licenceOneOf: [ 1, 4 ]
344 const body = await command.advancedVideoSearch({ search: query })
345 expect(body.total).to.equal(4)
347 const videos = body.data
348 expect(videos[0].name).to.equal('1111 2222 3333')
349 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
350 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
351 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
354 it('Should make an advanced search and sort results', async function () {
356 search: '1111 2222 3333',
357 languageOneOf: [ 'pl', 'fr' ],
359 nsfw: 'false' as 'false',
360 licenceOneOf: [ 1, 4 ],
364 const body = await command.advancedVideoSearch({ search: query })
365 expect(body.total).to.equal(4)
367 const videos = body.data
368 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
369 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
370 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
371 expect(videos[3].name).to.equal('1111 2222 3333')
374 it('Should make an advanced search and only show the first result', async function () {
376 search: '1111 2222 3333',
377 languageOneOf: [ 'pl', 'fr' ],
379 nsfw: 'false' as 'false',
380 licenceOneOf: [ 1, 4 ],
386 const body = await command.advancedVideoSearch({ search: query })
387 expect(body.total).to.equal(4)
389 const videos = body.data
390 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
393 it('Should make an advanced search and only show the last result', async function () {
395 search: '1111 2222 3333',
396 languageOneOf: [ 'pl', 'fr' ],
398 nsfw: 'false' as 'false',
399 licenceOneOf: [ 1, 4 ],
405 const body = await command.advancedVideoSearch({ search: query })
406 expect(body.total).to.equal(4)
408 const videos = body.data
409 expect(videos[0].name).to.equal('1111 2222 3333')
412 it('Should search on originally published date', async function () {
414 search: '1111 2222 3333',
415 languageOneOf: [ 'pl', 'fr' ],
417 nsfw: 'false' as 'false',
418 licenceOneOf: [ 1, 4 ]
422 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
423 const body = await command.advancedVideoSearch({ search: query })
425 expect(body.total).to.equal(1)
426 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
430 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
431 const body = await command.advancedVideoSearch({ search: query })
433 expect(body.total).to.equal(1)
434 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
438 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
439 const body = await command.advancedVideoSearch({ search: query })
441 expect(body.total).to.equal(0)
445 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
446 const body = await command.advancedVideoSearch({ search: query })
448 expect(body.total).to.equal(0)
452 const query = immutableAssign(baseQuery, {
453 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
454 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
456 const body = await command.advancedVideoSearch({ search: query })
458 expect(body.total).to.equal(0)
462 const query = immutableAssign(baseQuery, {
463 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
464 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
466 const body = await command.advancedVideoSearch({ search: query })
468 expect(body.total).to.equal(1)
469 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
473 it('Should search by UUID', async function () {
474 const search = videoUUID
475 const body = await command.advancedVideoSearch({ search: { search } })
477 expect(body.total).to.equal(1)
478 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
481 it('Should search by live', async function () {
487 searchIndex: { enabled: false }
489 live: { enabled: true }
491 await server.configCommand.updateCustomSubConfig({ newConfig })
495 const body = await command.advancedVideoSearch({ search: { isLive: true } })
497 expect(body.total).to.equal(0)
498 expect(body.data).to.have.lengthOf(0)
502 const liveCommand = server.liveCommand
504 const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id }
505 const live = await liveCommand.createLive({ fields: liveAttributes })
507 const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id })
508 await liveCommand.waitUntilLivePublished({ videoId: live.id })
510 const body = await command.advancedVideoSearch({ search: { isLive: true } })
512 expect(body.total).to.equal(1)
513 expect(body.data[0].name).to.equal('live')
515 await stopFfmpeg(ffmpegCommand)
519 after(async function () {
520 await cleanupTests([ server ])