1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
16 } from '@shared/extra-utils'
17 import { VideoPrivacy } from '@shared/models'
19 const expect = chai.expect
21 describe('Test videos search', function () {
22 let server: ServerInfo = null
26 let command: SearchCommand
28 before(async function () {
31 server = await flushAndRunServer(1)
33 await setAccessTokensToServers([ server ])
34 await setDefaultVideoChannel([ server ])
38 name: '1111 2222 3333',
39 fixture: '60fps_720p_small.mp4', // 2 seconds
45 await uploadVideo(server.url, server.accessToken, attributes1)
47 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
48 await uploadVideo(server.url, server.accessToken, attributes2)
51 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined })
52 const res = await uploadVideo(server.url, server.accessToken, attributes3)
53 const videoId = res.body.video.id
54 videoUUID = res.body.video.uuid
56 await server.captionsCommand.createVideoCaption({
59 fixture: 'subtitle-good2.vtt',
60 mimeType: 'application/octet-stream'
63 await server.captionsCommand.createVideoCaption({
66 fixture: 'subtitle-good2.vtt',
67 mimeType: 'application/octet-stream'
71 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
72 await uploadVideo(server.url, server.accessToken, attributes4)
76 startDate = new Date().toISOString()
78 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined })
79 await uploadVideo(server.url, server.accessToken, attributes5)
81 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] })
82 await uploadVideo(server.url, server.accessToken, attributes6)
84 const attributes7 = immutableAssign(attributes1, {
85 name: attributes1.name + ' - 7',
86 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
88 await uploadVideo(server.url, server.accessToken, attributes7)
90 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
91 await uploadVideo(server.url, server.accessToken, attributes8)
96 name: '3333 4444 5555',
97 fixture: 'video_short.mp4',
102 await uploadVideo(server.url, server.accessToken, attributes)
104 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
109 name: '6666 7777 8888',
110 fixture: 'video_short.mp4',
115 await uploadVideo(server.url, server.accessToken, attributes)
119 const attributes1 = {
121 tags: [ 'aaaa', 'bbbb', 'cccc' ],
124 await uploadVideo(server.url, server.accessToken, attributes1)
125 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
127 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
128 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
132 const attributes1 = {
136 await uploadVideo(server.url, server.accessToken, attributes1)
137 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
140 command = server.searchCommand
143 it('Should make a simple search and not have results', async function () {
144 const body = await command.searchVideos({ search: 'abc' })
146 expect(body.total).to.equal(0)
147 expect(body.data).to.have.lengthOf(0)
150 it('Should make a simple search and have results', async function () {
151 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
153 expect(body.total).to.equal(2)
155 const videos = body.data
156 expect(videos).to.have.lengthOf(2)
159 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
160 expect(videos[1].name).to.equal('3333 4444 5555')
163 it('Should make a search on tags too, and have results', async function () {
168 const body = await command.advancedVideoSearch({ search })
170 expect(body.total).to.equal(2)
172 const videos = body.data
173 expect(videos).to.have.lengthOf(2)
176 expect(videos[0].name).to.equal('aaaa 2')
177 expect(videos[1].name).to.equal('9999')
180 it('Should filter on tags without a search', async function () {
182 tagsAllOf: [ 'bbbb' ]
184 const body = await command.advancedVideoSearch({ search })
186 expect(body.total).to.equal(2)
188 const videos = body.data
189 expect(videos).to.have.lengthOf(2)
191 expect(videos[0].name).to.equal('9999')
192 expect(videos[1].name).to.equal('9999')
195 it('Should filter on category without a search', async function () {
199 const body = await command.advancedVideoSearch({ search: search })
201 expect(body.total).to.equal(1)
203 const videos = body.data
204 expect(videos).to.have.lengthOf(1)
206 expect(videos[0].name).to.equal('6666 7777 8888')
209 it('Should search by tags (one of)', async function () {
212 categoryOneOf: [ 1 ],
213 tagsOneOf: [ 'aAaa', 'ffff' ]
217 const body = await command.advancedVideoSearch({ search: query })
218 expect(body.total).to.equal(2)
222 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
223 expect(body.total).to.equal(0)
227 it('Should search by tags (all of)', async function () {
230 categoryOneOf: [ 1 ],
231 tagsAllOf: [ 'CCcc' ]
235 const body = await command.advancedVideoSearch({ search: query })
236 expect(body.total).to.equal(2)
240 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
241 expect(body.total).to.equal(0)
245 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
246 expect(body.total).to.equal(1)
250 it('Should search by category', async function () {
257 const body = await command.advancedVideoSearch({ search: query })
258 expect(body.total).to.equal(1)
259 expect(body.data[0].name).to.equal('6666 7777 8888')
263 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
264 expect(body.total).to.equal(0)
268 it('Should search by licence', async function () {
275 const body = await command.advancedVideoSearch({ search: query })
276 expect(body.total).to.equal(2)
277 expect(body.data[0].name).to.equal('3333 4444 5555')
278 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
282 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
283 expect(body.total).to.equal(0)
287 it('Should search by languages', async function () {
289 search: '1111 2222 3333',
290 languageOneOf: [ 'pl', 'en' ]
294 const body = await command.advancedVideoSearch({ search: query })
295 expect(body.total).to.equal(2)
296 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
297 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
301 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
302 expect(body.total).to.equal(3)
303 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
304 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
305 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
309 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
310 expect(body.total).to.equal(0)
314 it('Should search by start date', async function () {
316 search: '1111 2222 3333',
320 const body = await command.advancedVideoSearch({ search: query })
321 expect(body.total).to.equal(4)
323 const videos = body.data
324 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
325 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
326 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
327 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
330 it('Should make an advanced search', async function () {
332 search: '1111 2222 3333',
333 languageOneOf: [ 'pl', 'fr' ],
335 nsfw: 'false' as 'false',
336 licenceOneOf: [ 1, 4 ]
339 const body = await command.advancedVideoSearch({ search: query })
340 expect(body.total).to.equal(4)
342 const videos = body.data
343 expect(videos[0].name).to.equal('1111 2222 3333')
344 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
345 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
346 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
349 it('Should make an advanced search and sort results', async function () {
351 search: '1111 2222 3333',
352 languageOneOf: [ 'pl', 'fr' ],
354 nsfw: 'false' as 'false',
355 licenceOneOf: [ 1, 4 ],
359 const body = await command.advancedVideoSearch({ search: query })
360 expect(body.total).to.equal(4)
362 const videos = body.data
363 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
364 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
365 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
366 expect(videos[3].name).to.equal('1111 2222 3333')
369 it('Should make an advanced search and only show the first result', async function () {
371 search: '1111 2222 3333',
372 languageOneOf: [ 'pl', 'fr' ],
374 nsfw: 'false' as 'false',
375 licenceOneOf: [ 1, 4 ],
381 const body = await command.advancedVideoSearch({ search: query })
382 expect(body.total).to.equal(4)
384 const videos = body.data
385 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
388 it('Should make an advanced search and only show the last result', async function () {
390 search: '1111 2222 3333',
391 languageOneOf: [ 'pl', 'fr' ],
393 nsfw: 'false' as 'false',
394 licenceOneOf: [ 1, 4 ],
400 const body = await command.advancedVideoSearch({ search: query })
401 expect(body.total).to.equal(4)
403 const videos = body.data
404 expect(videos[0].name).to.equal('1111 2222 3333')
407 it('Should search on originally published date', async function () {
409 search: '1111 2222 3333',
410 languageOneOf: [ 'pl', 'fr' ],
412 nsfw: 'false' as 'false',
413 licenceOneOf: [ 1, 4 ]
417 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
418 const body = await command.advancedVideoSearch({ search: query })
420 expect(body.total).to.equal(1)
421 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
425 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-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-01-11T09:58:08.286Z' })
434 const body = await command.advancedVideoSearch({ search: query })
436 expect(body.total).to.equal(0)
440 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
441 const body = await command.advancedVideoSearch({ search: query })
443 expect(body.total).to.equal(0)
447 const query = immutableAssign(baseQuery, {
448 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
449 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
451 const body = await command.advancedVideoSearch({ search: query })
453 expect(body.total).to.equal(0)
457 const query = immutableAssign(baseQuery, {
458 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
459 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
461 const body = await command.advancedVideoSearch({ search: query })
463 expect(body.total).to.equal(1)
464 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
468 it('Should search by UUID', async function () {
469 const search = videoUUID
470 const body = await command.advancedVideoSearch({ search: { search } })
472 expect(body.total).to.equal(1)
473 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
476 it('Should search by live', async function () {
482 searchIndex: { enabled: false }
484 live: { enabled: true }
486 await server.configCommand.updateCustomSubConfig({ newConfig })
490 const body = await command.advancedVideoSearch({ search: { isLive: true } })
492 expect(body.total).to.equal(0)
493 expect(body.data).to.have.lengthOf(0)
497 const liveCommand = server.liveCommand
499 const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id }
500 const live = await liveCommand.create({ fields: liveAttributes })
502 const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id })
503 await liveCommand.waitUntilPublished({ videoId: live.id })
505 const body = await command.advancedVideoSearch({ search: { isLive: true } })
507 expect(body.total).to.equal(1)
508 expect(body.data[0].name).to.equal('live')
510 await stopFfmpeg(ffmpegCommand)
514 after(async function () {
515 await cleanupTests([ server ])