1 /* tslint:disable:no-unused-expression */
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
24 before(async function () {
27 server = await flushAndRunServer(1)
29 await setAccessTokensToServers([ server ])
33 name: '1111 2222 3333',
34 fixture: '60fps_720p_small.mp4', // 2 seconds
40 await uploadVideo(server.url, server.accessToken, attributes1)
42 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
43 await uploadVideo(server.url, server.accessToken, attributes2)
46 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined })
47 const res = await uploadVideo(server.url, server.accessToken, attributes3)
48 const videoId = res.body.video.id
50 await createVideoCaption({
52 accessToken: server.accessToken,
55 fixture: 'subtitle-good2.vtt',
56 mimeType: 'application/octet-stream'
59 await createVideoCaption({
61 accessToken: server.accessToken,
64 fixture: 'subtitle-good2.vtt',
65 mimeType: 'application/octet-stream'
69 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
70 await uploadVideo(server.url, server.accessToken, attributes4)
74 startDate = new Date().toISOString()
76 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined })
77 await uploadVideo(server.url, server.accessToken, attributes5)
79 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] })
80 await uploadVideo(server.url, server.accessToken, attributes6)
82 const attributes7 = immutableAssign(attributes1, {
83 name: attributes1.name + ' - 7',
84 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
86 await uploadVideo(server.url, server.accessToken, attributes7)
88 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
89 await uploadVideo(server.url, server.accessToken, attributes8)
94 name: '3333 4444 5555',
95 fixture: 'video_short.mp4',
100 await uploadVideo(server.url, server.accessToken, attributes)
102 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
107 name: '6666 7777 8888',
108 fixture: 'video_short.mp4',
113 await uploadVideo(server.url, server.accessToken, attributes)
117 const attributes1 = {
119 tags: [ 'aaaa', 'bbbb', 'cccc' ],
122 await uploadVideo(server.url, server.accessToken, attributes1)
123 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
125 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
126 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
130 const attributes1 = {
134 await uploadVideo(server.url, server.accessToken, attributes1)
135 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
139 it('Should make a simple search and not have results', async function () {
140 const res = await searchVideo(server.url, 'abc')
142 expect(res.body.total).to.equal(0)
143 expect(res.body.data).to.have.lengthOf(0)
146 it('Should make a simple search and have results', async function () {
147 const res = await searchVideo(server.url, '4444 5555 duplicate')
149 expect(res.body.total).to.equal(2)
151 const videos = res.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 res = await advancedVideosSearch(server.url, query)
166 expect(res.body.total).to.equal(2)
168 const videos = res.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 res = await advancedVideosSearch(server.url, query)
182 expect(res.body.total).to.equal(2)
184 const videos = res.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 res = await advancedVideosSearch(server.url, query)
197 expect(res.body.total).to.equal(1)
199 const videos = res.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' ]
211 const res1 = await advancedVideosSearch(server.url, query)
212 expect(res1.body.total).to.equal(2)
214 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
215 expect(res2.body.total).to.equal(0)
218 it('Should search by tags (all of)', async function () {
221 categoryOneOf: [ 1 ],
222 tagsAllOf: [ 'cccc' ]
224 const res1 = await advancedVideosSearch(server.url, query)
225 expect(res1.body.total).to.equal(2)
227 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blabla' ] }))
228 expect(res2.body.total).to.equal(0)
230 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'cccc' ] }))
231 expect(res3.body.total).to.equal(1)
234 it('Should search by category', async function () {
239 const res1 = await advancedVideosSearch(server.url, query)
240 expect(res1.body.total).to.equal(1)
241 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
243 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
244 expect(res2.body.total).to.equal(0)
247 it('Should search by licence', async function () {
252 const res1 = await advancedVideosSearch(server.url, query)
253 expect(res1.body.total).to.equal(2)
254 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
255 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
257 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
258 expect(res2.body.total).to.equal(0)
261 it('Should search by languages', async function () {
263 search: '1111 2222 3333',
264 languageOneOf: [ 'pl', 'en' ]
268 const res = await advancedVideosSearch(server.url, query)
269 expect(res.body.total).to.equal(2)
270 expect(res.body.data[ 0 ].name).to.equal('1111 2222 3333 - 3')
271 expect(res.body.data[ 1 ].name).to.equal('1111 2222 3333 - 4')
275 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] }))
276 expect(res.body.total).to.equal(3)
277 expect(res.body.data[ 0 ].name).to.equal('1111 2222 3333 - 3')
278 expect(res.body.data[ 1 ].name).to.equal('1111 2222 3333 - 4')
279 expect(res.body.data[ 2 ].name).to.equal('1111 2222 3333 - 5')
283 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
284 expect(res.body.total).to.equal(0)
288 it('Should search by start date', async function () {
290 search: '1111 2222 3333',
294 const res = await advancedVideosSearch(server.url, query)
295 expect(res.body.total).to.equal(4)
297 const videos = res.body.data
298 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
299 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
300 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
301 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
304 it('Should make an advanced search', async function () {
306 search: '1111 2222 3333',
307 languageOneOf: [ 'pl', 'fr' ],
309 nsfw: 'false' as 'false',
310 licenceOneOf: [ 1, 4 ]
313 const res = await advancedVideosSearch(server.url, query)
314 expect(res.body.total).to.equal(4)
316 const videos = res.body.data
317 expect(videos[0].name).to.equal('1111 2222 3333')
318 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
319 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
320 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
323 it('Should make an advanced search and sort results', async function () {
325 search: '1111 2222 3333',
326 languageOneOf: [ 'pl', 'fr' ],
328 nsfw: 'false' as 'false',
329 licenceOneOf: [ 1, 4 ],
333 const res = await advancedVideosSearch(server.url, query)
334 expect(res.body.total).to.equal(4)
336 const videos = res.body.data
337 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
338 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
339 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
340 expect(videos[3].name).to.equal('1111 2222 3333')
343 it('Should make an advanced search and only show the first result', async function () {
345 search: '1111 2222 3333',
346 languageOneOf: [ 'pl', 'fr' ],
348 nsfw: 'false' as 'false',
349 licenceOneOf: [ 1, 4 ],
355 const res = await advancedVideosSearch(server.url, query)
356 expect(res.body.total).to.equal(4)
358 const videos = res.body.data
359 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
362 it('Should make an advanced search and only show the last result', async function () {
364 search: '1111 2222 3333',
365 languageOneOf: [ 'pl', 'fr' ],
367 nsfw: 'false' as 'false',
368 licenceOneOf: [ 1, 4 ],
374 const res = await advancedVideosSearch(server.url, query)
375 expect(res.body.total).to.equal(4)
377 const videos = res.body.data
378 expect(videos[0].name).to.equal('1111 2222 3333')
381 it('Should search on originally published date', async function () {
383 search: '1111 2222 3333',
384 languageOneOf: [ 'pl', 'fr' ],
386 nsfw: 'false' as 'false',
387 licenceOneOf: [ 1, 4 ]
391 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
392 const res = await advancedVideosSearch(server.url, query)
394 expect(res.body.total).to.equal(1)
395 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
399 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
400 const res = await advancedVideosSearch(server.url, query)
402 expect(res.body.total).to.equal(1)
403 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
407 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
408 const res = await advancedVideosSearch(server.url, query)
410 expect(res.body.total).to.equal(0)
414 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
415 const res = await advancedVideosSearch(server.url, query)
417 expect(res.body.total).to.equal(0)
421 const query = immutableAssign(baseQuery, {
422 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
423 originallyPublishedEndDate: '2019-01-10T09: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-04-11T09:58:08.286Z'
435 const res = await advancedVideosSearch(server.url, query)
437 expect(res.body.total).to.equal(1)
438 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
442 after(async function () {
443 await cleanupTests([ server ])