1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoPrivacy } from '@shared/models'
12 sendRTMPStreamInVideo,
14 setAccessTokensToServers,
15 setDefaultVideoChannel,
17 updateCustomSubConfig,
20 waitUntilLivePublished
21 } from '../../../../shared/extra-utils'
22 import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
24 const expect = chai.expect
26 describe('Test videos search', function () {
27 let server: ServerInfo = null
31 let command: SearchCommand
33 before(async function () {
36 server = await flushAndRunServer(1)
38 await setAccessTokensToServers([ server ])
39 await setDefaultVideoChannel([ server ])
43 name: '1111 2222 3333',
44 fixture: '60fps_720p_small.mp4', // 2 seconds
50 await uploadVideo(server.url, server.accessToken, attributes1)
52 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
53 await uploadVideo(server.url, server.accessToken, attributes2)
56 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined })
57 const res = await uploadVideo(server.url, server.accessToken, attributes3)
58 const videoId = res.body.video.id
59 videoUUID = res.body.video.uuid
61 await createVideoCaption({
63 accessToken: server.accessToken,
66 fixture: 'subtitle-good2.vtt',
67 mimeType: 'application/octet-stream'
70 await createVideoCaption({
72 accessToken: server.accessToken,
75 fixture: 'subtitle-good2.vtt',
76 mimeType: 'application/octet-stream'
80 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
81 await uploadVideo(server.url, server.accessToken, attributes4)
85 startDate = new Date().toISOString()
87 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined })
88 await uploadVideo(server.url, server.accessToken, attributes5)
90 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] })
91 await uploadVideo(server.url, server.accessToken, attributes6)
93 const attributes7 = immutableAssign(attributes1, {
94 name: attributes1.name + ' - 7',
95 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
97 await uploadVideo(server.url, server.accessToken, attributes7)
99 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
100 await uploadVideo(server.url, server.accessToken, attributes8)
105 name: '3333 4444 5555',
106 fixture: 'video_short.mp4',
111 await uploadVideo(server.url, server.accessToken, attributes)
113 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
118 name: '6666 7777 8888',
119 fixture: 'video_short.mp4',
124 await uploadVideo(server.url, server.accessToken, attributes)
128 const attributes1 = {
130 tags: [ 'aaaa', 'bbbb', 'cccc' ],
133 await uploadVideo(server.url, server.accessToken, attributes1)
134 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
136 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
137 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
141 const attributes1 = {
145 await uploadVideo(server.url, server.accessToken, attributes1)
146 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
149 command = server.searchCommand
152 it('Should make a simple search and not have results', async function () {
153 const body = await command.searchVideos({ search: 'abc' })
155 expect(body.total).to.equal(0)
156 expect(body.data).to.have.lengthOf(0)
159 it('Should make a simple search and have results', async function () {
160 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
162 expect(body.total).to.equal(2)
164 const videos = body.data
165 expect(videos).to.have.lengthOf(2)
168 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
169 expect(videos[1].name).to.equal('3333 4444 5555')
172 it('Should make a search on tags too, and have results', async function () {
177 const body = await command.advancedVideoSearch({ search })
179 expect(body.total).to.equal(2)
181 const videos = body.data
182 expect(videos).to.have.lengthOf(2)
185 expect(videos[0].name).to.equal('aaaa 2')
186 expect(videos[1].name).to.equal('9999')
189 it('Should filter on tags without a search', async function () {
191 tagsAllOf: [ 'bbbb' ]
193 const body = await command.advancedVideoSearch({ search })
195 expect(body.total).to.equal(2)
197 const videos = body.data
198 expect(videos).to.have.lengthOf(2)
200 expect(videos[0].name).to.equal('9999')
201 expect(videos[1].name).to.equal('9999')
204 it('Should filter on category without a search', async function () {
208 const body = await command.advancedVideoSearch({ search: search })
210 expect(body.total).to.equal(1)
212 const videos = body.data
213 expect(videos).to.have.lengthOf(1)
215 expect(videos[0].name).to.equal('6666 7777 8888')
218 it('Should search by tags (one of)', async function () {
221 categoryOneOf: [ 1 ],
222 tagsOneOf: [ 'aAaa', 'ffff' ]
226 const body = await command.advancedVideoSearch({ search: query })
227 expect(body.total).to.equal(2)
231 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
232 expect(body.total).to.equal(0)
236 it('Should search by tags (all of)', async function () {
239 categoryOneOf: [ 1 ],
240 tagsAllOf: [ 'CCcc' ]
244 const body = await command.advancedVideoSearch({ search: query })
245 expect(body.total).to.equal(2)
249 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
250 expect(body.total).to.equal(0)
254 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
255 expect(body.total).to.equal(1)
259 it('Should search by category', async function () {
266 const body = await command.advancedVideoSearch({ search: query })
267 expect(body.total).to.equal(1)
268 expect(body.data[0].name).to.equal('6666 7777 8888')
272 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
273 expect(body.total).to.equal(0)
277 it('Should search by licence', async function () {
284 const body = await command.advancedVideoSearch({ search: query })
285 expect(body.total).to.equal(2)
286 expect(body.data[0].name).to.equal('3333 4444 5555')
287 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
291 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
292 expect(body.total).to.equal(0)
296 it('Should search by languages', async function () {
298 search: '1111 2222 3333',
299 languageOneOf: [ 'pl', 'en' ]
303 const body = await command.advancedVideoSearch({ search: query })
304 expect(body.total).to.equal(2)
305 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
306 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
310 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
311 expect(body.total).to.equal(3)
312 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
313 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
314 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
318 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
319 expect(body.total).to.equal(0)
323 it('Should search by start date', async function () {
325 search: '1111 2222 3333',
329 const body = await command.advancedVideoSearch({ search: query })
330 expect(body.total).to.equal(4)
332 const videos = body.data
333 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
334 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
335 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
336 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
339 it('Should make an advanced search', async function () {
341 search: '1111 2222 3333',
342 languageOneOf: [ 'pl', 'fr' ],
344 nsfw: 'false' as 'false',
345 licenceOneOf: [ 1, 4 ]
348 const body = await command.advancedVideoSearch({ search: query })
349 expect(body.total).to.equal(4)
351 const videos = body.data
352 expect(videos[0].name).to.equal('1111 2222 3333')
353 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
354 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
355 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
358 it('Should make an advanced search and sort results', async function () {
360 search: '1111 2222 3333',
361 languageOneOf: [ 'pl', 'fr' ],
363 nsfw: 'false' as 'false',
364 licenceOneOf: [ 1, 4 ],
368 const body = await command.advancedVideoSearch({ search: query })
369 expect(body.total).to.equal(4)
371 const videos = body.data
372 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
373 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
374 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
375 expect(videos[3].name).to.equal('1111 2222 3333')
378 it('Should make an advanced search and only show the first result', async function () {
380 search: '1111 2222 3333',
381 languageOneOf: [ 'pl', 'fr' ],
383 nsfw: 'false' as 'false',
384 licenceOneOf: [ 1, 4 ],
390 const body = await command.advancedVideoSearch({ search: query })
391 expect(body.total).to.equal(4)
393 const videos = body.data
394 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
397 it('Should make an advanced search and only show the last result', async function () {
399 search: '1111 2222 3333',
400 languageOneOf: [ 'pl', 'fr' ],
402 nsfw: 'false' as 'false',
403 licenceOneOf: [ 1, 4 ],
409 const body = await command.advancedVideoSearch({ search: query })
410 expect(body.total).to.equal(4)
412 const videos = body.data
413 expect(videos[0].name).to.equal('1111 2222 3333')
416 it('Should search on originally published date', async function () {
418 search: '1111 2222 3333',
419 languageOneOf: [ 'pl', 'fr' ],
421 nsfw: 'false' as 'false',
422 licenceOneOf: [ 1, 4 ]
426 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
427 const body = await command.advancedVideoSearch({ search: query })
429 expect(body.total).to.equal(1)
430 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
434 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
435 const body = await command.advancedVideoSearch({ search: query })
437 expect(body.total).to.equal(1)
438 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
442 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
443 const body = await command.advancedVideoSearch({ search: query })
445 expect(body.total).to.equal(0)
449 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
450 const body = await command.advancedVideoSearch({ search: query })
452 expect(body.total).to.equal(0)
456 const query = immutableAssign(baseQuery, {
457 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
458 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
460 const body = await command.advancedVideoSearch({ search: query })
462 expect(body.total).to.equal(0)
466 const query = immutableAssign(baseQuery, {
467 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
468 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
470 const body = await command.advancedVideoSearch({ search: query })
472 expect(body.total).to.equal(1)
473 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
477 it('Should search by UUID', async function () {
478 const search = videoUUID
479 const body = await command.advancedVideoSearch({ search: { search } })
481 expect(body.total).to.equal(1)
482 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
485 it('Should search by live', async function () {
491 searchIndex: { enabled: false }
493 live: { enabled: true }
495 await updateCustomSubConfig(server.url, server.accessToken, options)
499 const body = await command.advancedVideoSearch({ search: { isLive: true } })
501 expect(body.total).to.equal(0)
502 expect(body.data).to.have.lengthOf(0)
506 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id }
507 const resLive = await createLive(server.url, server.accessToken, liveOptions)
508 const liveVideoId = resLive.body.video.uuid
510 const ffmpegCommand = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId)
511 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId)
513 const body = await command.advancedVideoSearch({ search: { isLive: true } })
515 expect(body.total).to.equal(1)
516 expect(body.data[0].name).to.equal('live')
518 await stopFfmpeg(ffmpegCommand)
522 after(async function () {
523 await cleanupTests([ server ])