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,
19 waitUntilLivePublished
20 } from '../../../../shared/extra-utils'
21 import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
23 const expect = chai.expect
25 describe('Test videos search', function () {
26 let server: ServerInfo = null
30 let command: SearchCommand
32 before(async function () {
35 server = await flushAndRunServer(1)
37 await setAccessTokensToServers([ server ])
38 await setDefaultVideoChannel([ server ])
42 name: '1111 2222 3333',
43 fixture: '60fps_720p_small.mp4', // 2 seconds
49 await uploadVideo(server.url, server.accessToken, attributes1)
51 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
52 await uploadVideo(server.url, server.accessToken, attributes2)
55 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined })
56 const res = await uploadVideo(server.url, server.accessToken, attributes3)
57 const videoId = res.body.video.id
58 videoUUID = res.body.video.uuid
60 await createVideoCaption({
62 accessToken: server.accessToken,
65 fixture: 'subtitle-good2.vtt',
66 mimeType: 'application/octet-stream'
69 await createVideoCaption({
71 accessToken: server.accessToken,
74 fixture: 'subtitle-good2.vtt',
75 mimeType: 'application/octet-stream'
79 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
80 await uploadVideo(server.url, server.accessToken, attributes4)
84 startDate = new Date().toISOString()
86 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined })
87 await uploadVideo(server.url, server.accessToken, attributes5)
89 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] })
90 await uploadVideo(server.url, server.accessToken, attributes6)
92 const attributes7 = immutableAssign(attributes1, {
93 name: attributes1.name + ' - 7',
94 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
96 await uploadVideo(server.url, server.accessToken, attributes7)
98 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
99 await uploadVideo(server.url, server.accessToken, attributes8)
104 name: '3333 4444 5555',
105 fixture: 'video_short.mp4',
110 await uploadVideo(server.url, server.accessToken, attributes)
112 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
117 name: '6666 7777 8888',
118 fixture: 'video_short.mp4',
123 await uploadVideo(server.url, server.accessToken, attributes)
127 const attributes1 = {
129 tags: [ 'aaaa', 'bbbb', 'cccc' ],
132 await uploadVideo(server.url, server.accessToken, attributes1)
133 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
135 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
136 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
140 const attributes1 = {
144 await uploadVideo(server.url, server.accessToken, attributes1)
145 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
148 command = server.searchCommand
151 it('Should make a simple search and not have results', async function () {
152 const body = await command.searchVideos({ search: 'abc' })
154 expect(body.total).to.equal(0)
155 expect(body.data).to.have.lengthOf(0)
158 it('Should make a simple search and have results', async function () {
159 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
161 expect(body.total).to.equal(2)
163 const videos = body.data
164 expect(videos).to.have.lengthOf(2)
167 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
168 expect(videos[1].name).to.equal('3333 4444 5555')
171 it('Should make a search on tags too, and have results', async function () {
176 const body = await command.advancedVideoSearch({ search })
178 expect(body.total).to.equal(2)
180 const videos = body.data
181 expect(videos).to.have.lengthOf(2)
184 expect(videos[0].name).to.equal('aaaa 2')
185 expect(videos[1].name).to.equal('9999')
188 it('Should filter on tags without a search', async function () {
190 tagsAllOf: [ 'bbbb' ]
192 const body = await command.advancedVideoSearch({ search })
194 expect(body.total).to.equal(2)
196 const videos = body.data
197 expect(videos).to.have.lengthOf(2)
199 expect(videos[0].name).to.equal('9999')
200 expect(videos[1].name).to.equal('9999')
203 it('Should filter on category without a search', async function () {
207 const body = await command.advancedVideoSearch({ search: search })
209 expect(body.total).to.equal(1)
211 const videos = body.data
212 expect(videos).to.have.lengthOf(1)
214 expect(videos[0].name).to.equal('6666 7777 8888')
217 it('Should search by tags (one of)', async function () {
220 categoryOneOf: [ 1 ],
221 tagsOneOf: [ 'aAaa', 'ffff' ]
225 const body = await command.advancedVideoSearch({ search: query })
226 expect(body.total).to.equal(2)
230 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
231 expect(body.total).to.equal(0)
235 it('Should search by tags (all of)', async function () {
238 categoryOneOf: [ 1 ],
239 tagsAllOf: [ 'CCcc' ]
243 const body = await command.advancedVideoSearch({ search: query })
244 expect(body.total).to.equal(2)
248 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
249 expect(body.total).to.equal(0)
253 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
254 expect(body.total).to.equal(1)
258 it('Should search by category', async function () {
265 const body = await command.advancedVideoSearch({ search: query })
266 expect(body.total).to.equal(1)
267 expect(body.data[0].name).to.equal('6666 7777 8888')
271 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
272 expect(body.total).to.equal(0)
276 it('Should search by licence', async function () {
283 const body = await command.advancedVideoSearch({ search: query })
284 expect(body.total).to.equal(2)
285 expect(body.data[0].name).to.equal('3333 4444 5555')
286 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
290 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
291 expect(body.total).to.equal(0)
295 it('Should search by languages', async function () {
297 search: '1111 2222 3333',
298 languageOneOf: [ 'pl', 'en' ]
302 const body = await command.advancedVideoSearch({ search: query })
303 expect(body.total).to.equal(2)
304 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
305 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
309 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
310 expect(body.total).to.equal(3)
311 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
312 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
313 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
317 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
318 expect(body.total).to.equal(0)
322 it('Should search by start date', async function () {
324 search: '1111 2222 3333',
328 const body = await command.advancedVideoSearch({ search: query })
329 expect(body.total).to.equal(4)
331 const videos = body.data
332 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
333 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
334 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
335 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
338 it('Should make an advanced search', async function () {
340 search: '1111 2222 3333',
341 languageOneOf: [ 'pl', 'fr' ],
343 nsfw: 'false' as 'false',
344 licenceOneOf: [ 1, 4 ]
347 const body = await command.advancedVideoSearch({ search: query })
348 expect(body.total).to.equal(4)
350 const videos = body.data
351 expect(videos[0].name).to.equal('1111 2222 3333')
352 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
353 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
354 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
357 it('Should make an advanced search and sort results', async function () {
359 search: '1111 2222 3333',
360 languageOneOf: [ 'pl', 'fr' ],
362 nsfw: 'false' as 'false',
363 licenceOneOf: [ 1, 4 ],
367 const body = await command.advancedVideoSearch({ search: query })
368 expect(body.total).to.equal(4)
370 const videos = body.data
371 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
372 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
373 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
374 expect(videos[3].name).to.equal('1111 2222 3333')
377 it('Should make an advanced search and only show the first result', async function () {
379 search: '1111 2222 3333',
380 languageOneOf: [ 'pl', 'fr' ],
382 nsfw: 'false' as 'false',
383 licenceOneOf: [ 1, 4 ],
389 const body = await command.advancedVideoSearch({ search: query })
390 expect(body.total).to.equal(4)
392 const videos = body.data
393 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
396 it('Should make an advanced search and only show the last result', async function () {
398 search: '1111 2222 3333',
399 languageOneOf: [ 'pl', 'fr' ],
401 nsfw: 'false' as 'false',
402 licenceOneOf: [ 1, 4 ],
408 const body = await command.advancedVideoSearch({ search: query })
409 expect(body.total).to.equal(4)
411 const videos = body.data
412 expect(videos[0].name).to.equal('1111 2222 3333')
415 it('Should search on originally published date', async function () {
417 search: '1111 2222 3333',
418 languageOneOf: [ 'pl', 'fr' ],
420 nsfw: 'false' as 'false',
421 licenceOneOf: [ 1, 4 ]
425 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
426 const body = await command.advancedVideoSearch({ search: query })
428 expect(body.total).to.equal(1)
429 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
433 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
434 const body = await command.advancedVideoSearch({ search: query })
436 expect(body.total).to.equal(1)
437 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
441 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
442 const body = await command.advancedVideoSearch({ search: query })
444 expect(body.total).to.equal(0)
448 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
449 const body = await command.advancedVideoSearch({ search: query })
451 expect(body.total).to.equal(0)
455 const query = immutableAssign(baseQuery, {
456 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
457 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
459 const body = await command.advancedVideoSearch({ search: query })
461 expect(body.total).to.equal(0)
465 const query = immutableAssign(baseQuery, {
466 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
467 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
469 const body = await command.advancedVideoSearch({ search: query })
471 expect(body.total).to.equal(1)
472 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
476 it('Should search by UUID', async function () {
477 const search = videoUUID
478 const body = await command.advancedVideoSearch({ search: { search } })
480 expect(body.total).to.equal(1)
481 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
484 it('Should search by live', async function () {
490 searchIndex: { enabled: false }
492 live: { enabled: true }
494 await server.configCommand.updateCustomSubConfig({ newConfig })
498 const body = await command.advancedVideoSearch({ search: { isLive: true } })
500 expect(body.total).to.equal(0)
501 expect(body.data).to.have.lengthOf(0)
505 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id }
506 const resLive = await createLive(server.url, server.accessToken, liveOptions)
507 const liveVideoId = resLive.body.video.uuid
509 const ffmpegCommand = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId)
510 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId)
512 const body = await command.advancedVideoSearch({ search: { isLive: true } })
514 expect(body.total).to.equal(1)
515 expect(body.data[0].name).to.equal('live')
517 await stopFfmpeg(ffmpegCommand)
521 after(async function () {
522 await cleanupTests([ server ])