1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 setAccessTokensToServers,
11 setDefaultVideoChannel,
15 } from '@shared/extra-utils'
16 import { VideoPrivacy } from '@shared/models'
18 const expect = chai.expect
20 describe('Test videos search', function () {
21 let server: ServerInfo = null
25 let command: SearchCommand
27 before(async function () {
30 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
33 await setDefaultVideoChannel([ server ])
37 name: '1111 2222 3333',
38 fixture: '60fps_720p_small.mp4', // 2 seconds
44 await uploadVideo(server.url, server.accessToken, attributes1)
46 const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
47 await uploadVideo(server.url, server.accessToken, attributes2)
50 const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
51 const res = await uploadVideo(server.url, server.accessToken, attributes3)
52 const videoId = res.body.video.id
53 videoUUID = res.body.video.uuid
55 await server.captionsCommand.createVideoCaption({
58 fixture: 'subtitle-good2.vtt',
59 mimeType: 'application/octet-stream'
62 await server.captionsCommand.createVideoCaption({
65 fixture: 'subtitle-good2.vtt',
66 mimeType: 'application/octet-stream'
70 const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
71 await uploadVideo(server.url, server.accessToken, attributes4)
75 startDate = new Date().toISOString()
77 const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
78 await uploadVideo(server.url, server.accessToken, attributes5)
80 const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
81 await uploadVideo(server.url, server.accessToken, attributes6)
83 const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
84 await uploadVideo(server.url, server.accessToken, attributes7)
86 const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
87 await uploadVideo(server.url, server.accessToken, attributes8)
92 name: '3333 4444 5555',
93 fixture: 'video_short.mp4',
98 await uploadVideo(server.url, server.accessToken, attributes)
100 await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' })
105 name: '6666 7777 8888',
106 fixture: 'video_short.mp4',
111 await uploadVideo(server.url, server.accessToken, attributes)
115 const attributes1 = {
117 tags: [ 'aaaa', 'bbbb', 'cccc' ],
120 await uploadVideo(server.url, server.accessToken, attributes1)
121 await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 })
123 await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] })
124 await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] })
128 const attributes1 = {
132 await uploadVideo(server.url, server.accessToken, attributes1)
133 await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 })
136 command = server.searchCommand
139 it('Should make a simple search and not have results', async function () {
140 const body = await command.searchVideos({ search: 'abc' })
142 expect(body.total).to.equal(0)
143 expect(body.data).to.have.lengthOf(0)
146 it('Should make a simple search and have results', async function () {
147 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
149 expect(body.total).to.equal(2)
151 const videos = body.data
152 expect(videos).to.have.lengthOf(2)
155 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
156 expect(videos[1].name).to.equal('3333 4444 5555')
159 it('Should make a search on tags too, and have results', async function () {
164 const body = await command.advancedVideoSearch({ search })
166 expect(body.total).to.equal(2)
168 const videos = body.data
169 expect(videos).to.have.lengthOf(2)
172 expect(videos[0].name).to.equal('aaaa 2')
173 expect(videos[1].name).to.equal('9999')
176 it('Should filter on tags without a search', async function () {
178 tagsAllOf: [ 'bbbb' ]
180 const body = await command.advancedVideoSearch({ search })
182 expect(body.total).to.equal(2)
184 const videos = body.data
185 expect(videos).to.have.lengthOf(2)
187 expect(videos[0].name).to.equal('9999')
188 expect(videos[1].name).to.equal('9999')
191 it('Should filter on category without a search', async function () {
195 const body = await command.advancedVideoSearch({ search: search })
197 expect(body.total).to.equal(1)
199 const videos = body.data
200 expect(videos).to.have.lengthOf(1)
202 expect(videos[0].name).to.equal('6666 7777 8888')
205 it('Should search by tags (one of)', async function () {
208 categoryOneOf: [ 1 ],
209 tagsOneOf: [ 'aAaa', 'ffff' ]
213 const body = await command.advancedVideoSearch({ search: query })
214 expect(body.total).to.equal(2)
218 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
219 expect(body.total).to.equal(0)
223 it('Should search by tags (all of)', async function () {
226 categoryOneOf: [ 1 ],
227 tagsAllOf: [ 'CCcc' ]
231 const body = await command.advancedVideoSearch({ search: query })
232 expect(body.total).to.equal(2)
236 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
237 expect(body.total).to.equal(0)
241 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
242 expect(body.total).to.equal(1)
246 it('Should search by category', async function () {
253 const body = await command.advancedVideoSearch({ search: query })
254 expect(body.total).to.equal(1)
255 expect(body.data[0].name).to.equal('6666 7777 8888')
259 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
260 expect(body.total).to.equal(0)
264 it('Should search by licence', async function () {
271 const body = await command.advancedVideoSearch({ search: query })
272 expect(body.total).to.equal(2)
273 expect(body.data[0].name).to.equal('3333 4444 5555')
274 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
278 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
279 expect(body.total).to.equal(0)
283 it('Should search by languages', async function () {
285 search: '1111 2222 3333',
286 languageOneOf: [ 'pl', 'en' ]
290 const body = await command.advancedVideoSearch({ search: query })
291 expect(body.total).to.equal(2)
292 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
293 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
297 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
298 expect(body.total).to.equal(3)
299 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
300 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
301 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
305 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
306 expect(body.total).to.equal(0)
310 it('Should search by start date', async function () {
312 search: '1111 2222 3333',
316 const body = await command.advancedVideoSearch({ search: query })
317 expect(body.total).to.equal(4)
319 const videos = body.data
320 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
321 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
322 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
323 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
326 it('Should make an advanced search', async function () {
328 search: '1111 2222 3333',
329 languageOneOf: [ 'pl', 'fr' ],
331 nsfw: 'false' as 'false',
332 licenceOneOf: [ 1, 4 ]
335 const body = await command.advancedVideoSearch({ search: query })
336 expect(body.total).to.equal(4)
338 const videos = body.data
339 expect(videos[0].name).to.equal('1111 2222 3333')
340 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
341 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
342 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
345 it('Should make an advanced search and sort results', async function () {
347 search: '1111 2222 3333',
348 languageOneOf: [ 'pl', 'fr' ],
350 nsfw: 'false' as 'false',
351 licenceOneOf: [ 1, 4 ],
355 const body = await command.advancedVideoSearch({ search: query })
356 expect(body.total).to.equal(4)
358 const videos = body.data
359 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
360 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
361 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
362 expect(videos[3].name).to.equal('1111 2222 3333')
365 it('Should make an advanced search and only show the first result', async function () {
367 search: '1111 2222 3333',
368 languageOneOf: [ 'pl', 'fr' ],
370 nsfw: 'false' as 'false',
371 licenceOneOf: [ 1, 4 ],
377 const body = await command.advancedVideoSearch({ search: query })
378 expect(body.total).to.equal(4)
380 const videos = body.data
381 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
384 it('Should make an advanced search and only show the last result', async function () {
386 search: '1111 2222 3333',
387 languageOneOf: [ 'pl', 'fr' ],
389 nsfw: 'false' as 'false',
390 licenceOneOf: [ 1, 4 ],
396 const body = await command.advancedVideoSearch({ search: query })
397 expect(body.total).to.equal(4)
399 const videos = body.data
400 expect(videos[0].name).to.equal('1111 2222 3333')
403 it('Should search on originally published date', async function () {
405 search: '1111 2222 3333',
406 languageOneOf: [ 'pl', 'fr' ],
408 nsfw: 'false' as 'false',
409 licenceOneOf: [ 1, 4 ]
413 const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }
414 const body = await command.advancedVideoSearch({ search: query })
416 expect(body.total).to.equal(1)
417 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
421 const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }
422 const body = await command.advancedVideoSearch({ search: query })
424 expect(body.total).to.equal(1)
425 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
429 const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }
430 const body = await command.advancedVideoSearch({ search: query })
432 expect(body.total).to.equal(0)
436 const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }
437 const body = await command.advancedVideoSearch({ search: query })
439 expect(body.total).to.equal(0)
445 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
446 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
448 const body = await command.advancedVideoSearch({ search: query })
450 expect(body.total).to.equal(0)
456 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
457 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
459 const body = await command.advancedVideoSearch({ search: query })
461 expect(body.total).to.equal(1)
462 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
466 it('Should search by UUID', async function () {
467 const search = videoUUID
468 const body = await command.advancedVideoSearch({ search: { search } })
470 expect(body.total).to.equal(1)
471 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
474 it('Should search by live', async function () {
480 searchIndex: { enabled: false }
482 live: { enabled: true }
484 await server.configCommand.updateCustomSubConfig({ newConfig })
488 const body = await command.advancedVideoSearch({ search: { isLive: true } })
490 expect(body.total).to.equal(0)
491 expect(body.data).to.have.lengthOf(0)
495 const liveCommand = server.liveCommand
497 const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id }
498 const live = await liveCommand.create({ fields: liveAttributes })
500 const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id })
501 await liveCommand.waitUntilPublished({ videoId: live.id })
503 const body = await command.advancedVideoSearch({ search: { isLive: true } })
505 expect(body.total).to.equal(1)
506 expect(body.data[0].name).to.equal('live')
508 await stopFfmpeg(ffmpegCommand)
512 after(async function () {
513 await cleanupTests([ server ])