1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoPrivacy } from '@shared/models'
13 sendRTMPStreamInVideo,
15 setAccessTokensToServers,
16 setDefaultVideoChannel,
18 updateCustomSubConfig,
21 waitUntilLivePublished
22 } from '../../../../shared/extra-utils'
23 import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
25 const expect = chai.expect
27 describe('Test videos search', function () {
28 let server: ServerInfo = null
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 }))
149 it('Should make a simple search and not have results', async function () {
150 const res = await searchVideo(server.url, 'abc')
152 expect(res.body.total).to.equal(0)
153 expect(res.body.data).to.have.lengthOf(0)
156 it('Should make a simple search and have results', async function () {
157 const res = await searchVideo(server.url, '4444 5555 duplicate')
159 expect(res.body.total).to.equal(2)
161 const videos = res.body.data
162 expect(videos).to.have.lengthOf(2)
165 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
166 expect(videos[1].name).to.equal('3333 4444 5555')
169 it('Should make a search on tags too, and have results', async function () {
174 const res = await advancedVideosSearch(server.url, query)
176 expect(res.body.total).to.equal(2)
178 const videos = res.body.data
179 expect(videos).to.have.lengthOf(2)
182 expect(videos[0].name).to.equal('aaaa 2')
183 expect(videos[1].name).to.equal('9999')
186 it('Should filter on tags without a search', async function () {
188 tagsAllOf: [ 'bbbb' ]
190 const res = await advancedVideosSearch(server.url, query)
192 expect(res.body.total).to.equal(2)
194 const videos = res.body.data
195 expect(videos).to.have.lengthOf(2)
197 expect(videos[0].name).to.equal('9999')
198 expect(videos[1].name).to.equal('9999')
201 it('Should filter on category without a search', async function () {
205 const res = await advancedVideosSearch(server.url, query)
207 expect(res.body.total).to.equal(1)
209 const videos = res.body.data
210 expect(videos).to.have.lengthOf(1)
212 expect(videos[0].name).to.equal('6666 7777 8888')
215 it('Should search by tags (one of)', async function () {
218 categoryOneOf: [ 1 ],
219 tagsOneOf: [ 'aAaa', 'ffff' ]
221 const res1 = await advancedVideosSearch(server.url, query)
222 expect(res1.body.total).to.equal(2)
224 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
225 expect(res2.body.total).to.equal(0)
228 it('Should search by tags (all of)', async function () {
231 categoryOneOf: [ 1 ],
232 tagsAllOf: [ 'CCcc' ]
234 const res1 = await advancedVideosSearch(server.url, query)
235 expect(res1.body.total).to.equal(2)
237 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blAbla' ] }))
238 expect(res2.body.total).to.equal(0)
240 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'CCCC' ] }))
241 expect(res3.body.total).to.equal(1)
244 it('Should search by category', async function () {
249 const res1 = await advancedVideosSearch(server.url, query)
250 expect(res1.body.total).to.equal(1)
251 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
253 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
254 expect(res2.body.total).to.equal(0)
257 it('Should search by licence', async function () {
262 const res1 = await advancedVideosSearch(server.url, query)
263 expect(res1.body.total).to.equal(2)
264 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
265 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
267 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
268 expect(res2.body.total).to.equal(0)
271 it('Should search by languages', async function () {
273 search: '1111 2222 3333',
274 languageOneOf: [ 'pl', 'en' ]
278 const res = await advancedVideosSearch(server.url, query)
279 expect(res.body.total).to.equal(2)
280 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
281 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4')
285 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] }))
286 expect(res.body.total).to.equal(3)
287 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
288 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4')
289 expect(res.body.data[2].name).to.equal('1111 2222 3333 - 5')
293 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
294 expect(res.body.total).to.equal(0)
298 it('Should search by start date', async function () {
300 search: '1111 2222 3333',
304 const res = await advancedVideosSearch(server.url, query)
305 expect(res.body.total).to.equal(4)
307 const videos = res.body.data
308 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
309 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
310 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
311 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
314 it('Should make an advanced search', async function () {
316 search: '1111 2222 3333',
317 languageOneOf: [ 'pl', 'fr' ],
319 nsfw: 'false' as 'false',
320 licenceOneOf: [ 1, 4 ]
323 const res = await advancedVideosSearch(server.url, query)
324 expect(res.body.total).to.equal(4)
326 const videos = res.body.data
327 expect(videos[0].name).to.equal('1111 2222 3333')
328 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
329 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
330 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
333 it('Should make an advanced search and sort results', async function () {
335 search: '1111 2222 3333',
336 languageOneOf: [ 'pl', 'fr' ],
338 nsfw: 'false' as 'false',
339 licenceOneOf: [ 1, 4 ],
343 const res = await advancedVideosSearch(server.url, query)
344 expect(res.body.total).to.equal(4)
346 const videos = res.body.data
347 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
348 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
349 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
350 expect(videos[3].name).to.equal('1111 2222 3333')
353 it('Should make an advanced search and only show the first result', async function () {
355 search: '1111 2222 3333',
356 languageOneOf: [ 'pl', 'fr' ],
358 nsfw: 'false' as 'false',
359 licenceOneOf: [ 1, 4 ],
365 const res = await advancedVideosSearch(server.url, query)
366 expect(res.body.total).to.equal(4)
368 const videos = res.body.data
369 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
372 it('Should make an advanced search and only show the last result', async function () {
374 search: '1111 2222 3333',
375 languageOneOf: [ 'pl', 'fr' ],
377 nsfw: 'false' as 'false',
378 licenceOneOf: [ 1, 4 ],
384 const res = await advancedVideosSearch(server.url, query)
385 expect(res.body.total).to.equal(4)
387 const videos = res.body.data
388 expect(videos[0].name).to.equal('1111 2222 3333')
391 it('Should search on originally published date', async function () {
393 search: '1111 2222 3333',
394 languageOneOf: [ 'pl', 'fr' ],
396 nsfw: 'false' as 'false',
397 licenceOneOf: [ 1, 4 ]
401 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
402 const res = await advancedVideosSearch(server.url, query)
404 expect(res.body.total).to.equal(1)
405 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
409 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
410 const res = await advancedVideosSearch(server.url, query)
412 expect(res.body.total).to.equal(1)
413 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
417 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
418 const res = await advancedVideosSearch(server.url, query)
420 expect(res.body.total).to.equal(0)
424 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
425 const res = await advancedVideosSearch(server.url, query)
427 expect(res.body.total).to.equal(0)
431 const query = immutableAssign(baseQuery, {
432 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
433 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
435 const res = await advancedVideosSearch(server.url, query)
437 expect(res.body.total).to.equal(0)
441 const query = immutableAssign(baseQuery, {
442 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
443 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
445 const res = await advancedVideosSearch(server.url, query)
447 expect(res.body.total).to.equal(1)
448 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
452 it('Should search by UUID', async function () {
453 const search = videoUUID
454 const res = await advancedVideosSearch(server.url, { search })
456 expect(res.body.total).to.equal(1)
457 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
460 it('Should search by live', async function () {
466 searchIndex: { enabled: false }
468 live: { enabled: true }
470 await updateCustomSubConfig(server.url, server.accessToken, options)
474 const res = await advancedVideosSearch(server.url, { isLive: true })
476 expect(res.body.total).to.equal(0)
477 expect(res.body.data).to.have.lengthOf(0)
481 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id }
482 const resLive = await createLive(server.url, server.accessToken, liveOptions)
483 const liveVideoId = resLive.body.video.uuid
485 const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId)
486 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId)
488 const res = await advancedVideosSearch(server.url, { isLive: true })
490 expect(res.body.total).to.equal(1)
491 expect(res.body.data[0].name).to.equal('live')
493 await stopFfmpeg(command)
497 after(async function () {
498 await cleanupTests([ server ])