1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
12 setAccessTokensToServers,
15 } from '../../../../shared/extra-utils'
16 import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
18 const expect = chai.expect
20 describe('Test videos search', function () {
21 let server: ServerInfo = null
25 before(async function () {
28 server = await flushAndRunServer(1)
30 await setAccessTokensToServers([ server ])
34 name: '1111 2222 3333',
35 fixture: '60fps_720p_small.mp4', // 2 seconds
41 await uploadVideo(server.url, server.accessToken, attributes1)
43 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
44 await uploadVideo(server.url, server.accessToken, attributes2)
47 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined })
48 const res = await uploadVideo(server.url, server.accessToken, attributes3)
49 const videoId = res.body.video.id
50 videoUUID = res.body.video.uuid
52 await createVideoCaption({
54 accessToken: server.accessToken,
57 fixture: 'subtitle-good2.vtt',
58 mimeType: 'application/octet-stream'
61 await createVideoCaption({
63 accessToken: server.accessToken,
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 }))
141 it('Should make a simple search and not have results', async function () {
142 const res = await searchVideo(server.url, 'abc')
144 expect(res.body.total).to.equal(0)
145 expect(res.body.data).to.have.lengthOf(0)
148 it('Should make a simple search and have results', async function () {
149 const res = await searchVideo(server.url, '4444 5555 duplicate')
151 expect(res.body.total).to.equal(2)
153 const videos = res.body.data
154 expect(videos).to.have.lengthOf(2)
157 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
158 expect(videos[1].name).to.equal('3333 4444 5555')
161 it('Should make a search on tags too, and have results', async function () {
166 const res = await advancedVideosSearch(server.url, query)
168 expect(res.body.total).to.equal(2)
170 const videos = res.body.data
171 expect(videos).to.have.lengthOf(2)
174 expect(videos[0].name).to.equal('aaaa 2')
175 expect(videos[1].name).to.equal('9999')
178 it('Should filter on tags without a search', async function () {
180 tagsAllOf: [ 'bbbb' ]
182 const res = await advancedVideosSearch(server.url, query)
184 expect(res.body.total).to.equal(2)
186 const videos = res.body.data
187 expect(videos).to.have.lengthOf(2)
189 expect(videos[0].name).to.equal('9999')
190 expect(videos[1].name).to.equal('9999')
193 it('Should filter on category without a search', async function () {
197 const res = await advancedVideosSearch(server.url, query)
199 expect(res.body.total).to.equal(1)
201 const videos = res.body.data
202 expect(videos).to.have.lengthOf(1)
204 expect(videos[0].name).to.equal('6666 7777 8888')
207 it('Should search by tags (one of)', async function () {
210 categoryOneOf: [ 1 ],
211 tagsOneOf: [ 'aAaa', 'ffff' ]
213 const res1 = await advancedVideosSearch(server.url, query)
214 expect(res1.body.total).to.equal(2)
216 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
217 expect(res2.body.total).to.equal(0)
220 it('Should search by tags (all of)', async function () {
223 categoryOneOf: [ 1 ],
224 tagsAllOf: [ 'CCcc' ]
226 const res1 = await advancedVideosSearch(server.url, query)
227 expect(res1.body.total).to.equal(2)
229 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blAbla' ] }))
230 expect(res2.body.total).to.equal(0)
232 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'CCCC' ] }))
233 expect(res3.body.total).to.equal(1)
236 it('Should search by category', async function () {
241 const res1 = await advancedVideosSearch(server.url, query)
242 expect(res1.body.total).to.equal(1)
243 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
245 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
246 expect(res2.body.total).to.equal(0)
249 it('Should search by licence', async function () {
254 const res1 = await advancedVideosSearch(server.url, query)
255 expect(res1.body.total).to.equal(2)
256 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
257 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
259 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
260 expect(res2.body.total).to.equal(0)
263 it('Should search by languages', async function () {
265 search: '1111 2222 3333',
266 languageOneOf: [ 'pl', 'en' ]
270 const res = await advancedVideosSearch(server.url, query)
271 expect(res.body.total).to.equal(2)
272 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
273 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4')
277 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] }))
278 expect(res.body.total).to.equal(3)
279 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
280 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4')
281 expect(res.body.data[2].name).to.equal('1111 2222 3333 - 5')
285 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
286 expect(res.body.total).to.equal(0)
290 it('Should search by start date', async function () {
292 search: '1111 2222 3333',
296 const res = await advancedVideosSearch(server.url, query)
297 expect(res.body.total).to.equal(4)
299 const videos = res.body.data
300 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
301 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
302 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
303 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
306 it('Should make an advanced search', async function () {
308 search: '1111 2222 3333',
309 languageOneOf: [ 'pl', 'fr' ],
311 nsfw: 'false' as 'false',
312 licenceOneOf: [ 1, 4 ]
315 const res = await advancedVideosSearch(server.url, query)
316 expect(res.body.total).to.equal(4)
318 const videos = res.body.data
319 expect(videos[0].name).to.equal('1111 2222 3333')
320 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
321 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
322 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
325 it('Should make an advanced search and sort results', async function () {
327 search: '1111 2222 3333',
328 languageOneOf: [ 'pl', 'fr' ],
330 nsfw: 'false' as 'false',
331 licenceOneOf: [ 1, 4 ],
335 const res = await advancedVideosSearch(server.url, query)
336 expect(res.body.total).to.equal(4)
338 const videos = res.body.data
339 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
340 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
341 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
342 expect(videos[3].name).to.equal('1111 2222 3333')
345 it('Should make an advanced search and only show the first result', async function () {
347 search: '1111 2222 3333',
348 languageOneOf: [ 'pl', 'fr' ],
350 nsfw: 'false' as 'false',
351 licenceOneOf: [ 1, 4 ],
357 const res = await advancedVideosSearch(server.url, query)
358 expect(res.body.total).to.equal(4)
360 const videos = res.body.data
361 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
364 it('Should make an advanced search and only show the last result', async function () {
366 search: '1111 2222 3333',
367 languageOneOf: [ 'pl', 'fr' ],
369 nsfw: 'false' as 'false',
370 licenceOneOf: [ 1, 4 ],
376 const res = await advancedVideosSearch(server.url, query)
377 expect(res.body.total).to.equal(4)
379 const videos = res.body.data
380 expect(videos[0].name).to.equal('1111 2222 3333')
383 it('Should search on originally published date', async function () {
385 search: '1111 2222 3333',
386 languageOneOf: [ 'pl', 'fr' ],
388 nsfw: 'false' as 'false',
389 licenceOneOf: [ 1, 4 ]
393 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
394 const res = await advancedVideosSearch(server.url, query)
396 expect(res.body.total).to.equal(1)
397 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
401 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-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-01-11T09:58:08.286Z' })
410 const res = await advancedVideosSearch(server.url, query)
412 expect(res.body.total).to.equal(0)
416 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
417 const res = await advancedVideosSearch(server.url, query)
419 expect(res.body.total).to.equal(0)
423 const query = immutableAssign(baseQuery, {
424 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
425 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
427 const res = await advancedVideosSearch(server.url, query)
429 expect(res.body.total).to.equal(0)
433 const query = immutableAssign(baseQuery, {
434 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
435 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
437 const res = await advancedVideosSearch(server.url, query)
439 expect(res.body.total).to.equal(1)
440 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
444 it('Should search by UUID', async function () {
445 const search = videoUUID
446 const res = await advancedVideosSearch(server.url, { search })
448 expect(res.body.total).to.equal(1)
449 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
452 after(async function () {
453 await cleanupTests([ server ])