1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
12 setAccessTokensToServers,
17 } from '../../../../shared/extra-utils'
19 const expect = chai.expect
21 describe('Test a videos search', function () {
22 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)
46 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: 'en' })
47 await uploadVideo(server.url, server.accessToken, attributes3)
49 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
50 await uploadVideo(server.url, server.accessToken, attributes4)
54 startDate = new Date().toISOString()
56 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2 })
57 await uploadVideo(server.url, server.accessToken, attributes5)
59 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] })
60 await uploadVideo(server.url, server.accessToken, attributes6)
62 const attributes7 = immutableAssign(attributes1, {
63 name: attributes1.name + ' - 7',
64 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
66 await uploadVideo(server.url, server.accessToken, attributes7)
68 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
69 await uploadVideo(server.url, server.accessToken, attributes8)
74 name: '3333 4444 5555',
75 fixture: 'video_short.mp4',
80 await uploadVideo(server.url, server.accessToken, attributes)
82 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
87 name: '6666 7777 8888',
88 fixture: 'video_short.mp4',
93 await uploadVideo(server.url, server.accessToken, attributes)
99 tags: [ 'aaaa', 'bbbb', 'cccc' ],
102 await uploadVideo(server.url, server.accessToken, attributes1)
103 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
105 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
106 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
110 const attributes1 = {
114 await uploadVideo(server.url, server.accessToken, attributes1)
115 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
119 it('Should make a simple search and not have results', async function () {
120 const res = await searchVideo(server.url, 'abc')
122 expect(res.body.total).to.equal(0)
123 expect(res.body.data).to.have.lengthOf(0)
126 it('Should make a simple search and have results', async function () {
127 const res = await searchVideo(server.url, '4444 5555 duplicate')
129 expect(res.body.total).to.equal(2)
131 const videos = res.body.data
132 expect(videos).to.have.lengthOf(2)
135 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
136 expect(videos[1].name).to.equal('3333 4444 5555')
139 it('Should make a search on tags too, and have results', async function () {
144 const res = await advancedVideosSearch(server.url, query)
146 expect(res.body.total).to.equal(2)
148 const videos = res.body.data
149 expect(videos).to.have.lengthOf(2)
152 expect(videos[0].name).to.equal('aaaa 2')
153 expect(videos[1].name).to.equal('9999')
156 it('Should filter on tags without a search', async function () {
158 tagsAllOf: [ 'bbbb' ]
160 const res = await advancedVideosSearch(server.url, query)
162 expect(res.body.total).to.equal(2)
164 const videos = res.body.data
165 expect(videos).to.have.lengthOf(2)
167 expect(videos[0].name).to.equal('9999')
168 expect(videos[1].name).to.equal('9999')
171 it('Should filter on category without a search', async function () {
175 const res = await advancedVideosSearch(server.url, query)
177 expect(res.body.total).to.equal(1)
179 const videos = res.body.data
180 expect(videos).to.have.lengthOf(1)
182 expect(videos[0].name).to.equal('6666 7777 8888')
185 it('Should search by tags (one of)', async function () {
188 categoryOneOf: [ 1 ],
189 tagsOneOf: [ 'aaaa', 'ffff' ]
191 const res1 = await advancedVideosSearch(server.url, query)
192 expect(res1.body.total).to.equal(2)
194 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
195 expect(res2.body.total).to.equal(0)
198 it('Should search by tags (all of)', async function () {
201 categoryOneOf: [ 1 ],
202 tagsAllOf: [ 'cccc' ]
204 const res1 = await advancedVideosSearch(server.url, query)
205 expect(res1.body.total).to.equal(2)
207 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blabla' ] }))
208 expect(res2.body.total).to.equal(0)
210 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'cccc' ] }))
211 expect(res3.body.total).to.equal(1)
214 it('Should search by category', async function () {
219 const res1 = await advancedVideosSearch(server.url, query)
220 expect(res1.body.total).to.equal(1)
221 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
223 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
224 expect(res2.body.total).to.equal(0)
227 it('Should search by licence', async function () {
232 const res1 = await advancedVideosSearch(server.url, query)
233 expect(res1.body.total).to.equal(2)
234 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
235 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
237 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
238 expect(res2.body.total).to.equal(0)
241 it('Should search by languages', async function () {
243 search: '1111 2222 3333',
244 languageOneOf: [ 'pl', 'en' ]
246 const res1 = await advancedVideosSearch(server.url, query)
247 expect(res1.body.total).to.equal(2)
248 expect(res1.body.data[0].name).to.equal('1111 2222 3333 - 3')
249 expect(res1.body.data[1].name).to.equal('1111 2222 3333 - 4')
251 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
252 expect(res2.body.total).to.equal(0)
255 it('Should search by start date', async function () {
257 search: '1111 2222 3333',
261 const res = await advancedVideosSearch(server.url, query)
262 expect(res.body.total).to.equal(4)
264 const videos = res.body.data
265 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
266 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
267 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
268 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
271 it('Should make an advanced search', async function () {
273 search: '1111 2222 3333',
274 languageOneOf: [ 'pl', 'fr' ],
276 nsfw: 'false' as 'false',
277 licenceOneOf: [ 1, 4 ]
280 const res = await advancedVideosSearch(server.url, query)
281 expect(res.body.total).to.equal(4)
283 const videos = res.body.data
284 expect(videos[0].name).to.equal('1111 2222 3333')
285 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
286 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
287 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
290 it('Should make an advanced search and sort results', async function () {
292 search: '1111 2222 3333',
293 languageOneOf: [ 'pl', 'fr' ],
295 nsfw: 'false' as 'false',
296 licenceOneOf: [ 1, 4 ],
300 const res = await advancedVideosSearch(server.url, query)
301 expect(res.body.total).to.equal(4)
303 const videos = res.body.data
304 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
305 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
306 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
307 expect(videos[3].name).to.equal('1111 2222 3333')
310 it('Should make an advanced search and only show the first result', async function () {
312 search: '1111 2222 3333',
313 languageOneOf: [ 'pl', 'fr' ],
315 nsfw: 'false' as 'false',
316 licenceOneOf: [ 1, 4 ],
322 const res = await advancedVideosSearch(server.url, query)
323 expect(res.body.total).to.equal(4)
325 const videos = res.body.data
326 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
329 it('Should make an advanced search and only show the last result', async function () {
331 search: '1111 2222 3333',
332 languageOneOf: [ 'pl', 'fr' ],
334 nsfw: 'false' as 'false',
335 licenceOneOf: [ 1, 4 ],
341 const res = await advancedVideosSearch(server.url, query)
342 expect(res.body.total).to.equal(4)
344 const videos = res.body.data
345 expect(videos[0].name).to.equal('1111 2222 3333')
348 it('Should search on originally published date', async function () {
350 search: '1111 2222 3333',
351 languageOneOf: [ 'pl', 'fr' ],
353 nsfw: 'false' as 'false',
354 licenceOneOf: [ 1, 4 ]
358 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
359 const res = await advancedVideosSearch(server.url, query)
361 expect(res.body.total).to.equal(1)
362 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
366 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
367 const res = await advancedVideosSearch(server.url, query)
369 expect(res.body.total).to.equal(1)
370 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
374 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
375 const res = await advancedVideosSearch(server.url, query)
377 expect(res.body.total).to.equal(0)
381 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
382 const res = await advancedVideosSearch(server.url, query)
384 expect(res.body.total).to.equal(0)
388 const query = immutableAssign(baseQuery, {
389 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
390 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
392 const res = await advancedVideosSearch(server.url, query)
394 expect(res.body.total).to.equal(0)
398 const query = immutableAssign(baseQuery, {
399 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
400 originallyPublishedEndDate: '2019-04-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 after(async function () {
410 await cleanupTests([ server ])