1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
12 setAccessTokensToServers,
16 } from '../../../../shared/utils'
18 const expect = chai.expect
20 describe('Test a videos search', function () {
21 let server: ServerInfo = null
24 before(async function () {
29 server = await runServer(1)
31 await setAccessTokensToServers([ server ])
35 name: '1111 2222 3333',
36 fixture: '60fps_720p_small.mp4', // 2 seconds
42 await uploadVideo(server.url, server.accessToken, attributes1)
44 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
45 await uploadVideo(server.url, server.accessToken, attributes2)
47 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: 'en' })
48 await uploadVideo(server.url, server.accessToken, attributes3)
50 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
51 await uploadVideo(server.url, server.accessToken, attributes4)
55 startDate = new Date().toISOString()
57 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2 })
58 await uploadVideo(server.url, server.accessToken, attributes5)
60 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] })
61 await uploadVideo(server.url, server.accessToken, attributes6)
63 const attributes7 = immutableAssign(attributes1, {
64 name: attributes1.name + ' - 7',
65 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
67 await uploadVideo(server.url, server.accessToken, attributes7)
69 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
70 await uploadVideo(server.url, server.accessToken, attributes8)
75 name: '3333 4444 5555',
76 fixture: 'video_short.mp4',
81 await uploadVideo(server.url, server.accessToken, attributes)
83 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
88 name: '6666 7777 8888',
89 fixture: 'video_short.mp4',
94 await uploadVideo(server.url, server.accessToken, attributes)
100 tags: [ 'aaaa', 'bbbb', 'cccc' ],
103 await uploadVideo(server.url, server.accessToken, attributes1)
104 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
106 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
107 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
111 const attributes1 = {
115 await uploadVideo(server.url, server.accessToken, attributes1)
116 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
120 it('Should make a simple search and not have results', async function () {
121 const res = await searchVideo(server.url, 'abc')
123 expect(res.body.total).to.equal(0)
124 expect(res.body.data).to.have.lengthOf(0)
127 it('Should make a simple search and have results', async function () {
128 const res = await searchVideo(server.url, '4444 5555 duplicate')
130 expect(res.body.total).to.equal(2)
132 const videos = res.body.data
133 expect(videos).to.have.lengthOf(2)
136 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
137 expect(videos[1].name).to.equal('3333 4444 5555')
140 it('Should make a search on tags too, and have results', async function () {
145 const res = await advancedVideosSearch(server.url, query)
147 expect(res.body.total).to.equal(2)
149 const videos = res.body.data
150 expect(videos).to.have.lengthOf(2)
153 expect(videos[0].name).to.equal('aaaa 2')
154 expect(videos[1].name).to.equal('9999')
157 it('Should filter on tags without a search', async function () {
159 tagsAllOf: [ 'bbbb' ]
161 const res = await advancedVideosSearch(server.url, query)
163 expect(res.body.total).to.equal(2)
165 const videos = res.body.data
166 expect(videos).to.have.lengthOf(2)
168 expect(videos[0].name).to.equal('9999')
169 expect(videos[1].name).to.equal('9999')
172 it('Should filter on category without a search', async function () {
176 const res = await advancedVideosSearch(server.url, query)
178 expect(res.body.total).to.equal(1)
180 const videos = res.body.data
181 expect(videos).to.have.lengthOf(1)
183 expect(videos[0].name).to.equal('6666 7777 8888')
186 it('Should search by tags (one of)', async function () {
189 categoryOneOf: [ 1 ],
190 tagsOneOf: [ 'aaaa', 'ffff' ]
192 const res1 = await advancedVideosSearch(server.url, query)
193 expect(res1.body.total).to.equal(2)
195 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
196 expect(res2.body.total).to.equal(0)
199 it('Should search by tags (all of)', async function () {
202 categoryOneOf: [ 1 ],
203 tagsAllOf: [ 'cccc' ]
205 const res1 = await advancedVideosSearch(server.url, query)
206 expect(res1.body.total).to.equal(2)
208 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blabla' ] }))
209 expect(res2.body.total).to.equal(0)
211 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'cccc' ] }))
212 expect(res3.body.total).to.equal(1)
215 it('Should search by category', async function () {
220 const res1 = await advancedVideosSearch(server.url, query)
221 expect(res1.body.total).to.equal(1)
222 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
224 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
225 expect(res2.body.total).to.equal(0)
228 it('Should search by licence', async function () {
233 const res1 = await advancedVideosSearch(server.url, query)
234 expect(res1.body.total).to.equal(2)
235 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
236 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
238 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
239 expect(res2.body.total).to.equal(0)
242 it('Should search by languages', async function () {
244 search: '1111 2222 3333',
245 languageOneOf: [ 'pl', 'en' ]
247 const res1 = await advancedVideosSearch(server.url, query)
248 expect(res1.body.total).to.equal(2)
249 expect(res1.body.data[0].name).to.equal('1111 2222 3333 - 3')
250 expect(res1.body.data[1].name).to.equal('1111 2222 3333 - 4')
252 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
253 expect(res2.body.total).to.equal(0)
256 it('Should search by start date', async function () {
258 search: '1111 2222 3333',
262 const res = await advancedVideosSearch(server.url, query)
263 expect(res.body.total).to.equal(4)
265 const videos = res.body.data
266 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
267 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
268 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
269 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
272 it('Should make an advanced search', async function () {
274 search: '1111 2222 3333',
275 languageOneOf: [ 'pl', 'fr' ],
277 nsfw: 'false' as 'false',
278 licenceOneOf: [ 1, 4 ]
281 const res = await advancedVideosSearch(server.url, query)
282 expect(res.body.total).to.equal(4)
284 const videos = res.body.data
285 expect(videos[0].name).to.equal('1111 2222 3333')
286 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
287 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
288 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
291 it('Should make an advanced search and sort results', async function () {
293 search: '1111 2222 3333',
294 languageOneOf: [ 'pl', 'fr' ],
296 nsfw: 'false' as 'false',
297 licenceOneOf: [ 1, 4 ],
301 const res = await advancedVideosSearch(server.url, query)
302 expect(res.body.total).to.equal(4)
304 const videos = res.body.data
305 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
306 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
307 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
308 expect(videos[3].name).to.equal('1111 2222 3333')
311 it('Should make an advanced search and only show the first result', async function () {
313 search: '1111 2222 3333',
314 languageOneOf: [ 'pl', 'fr' ],
316 nsfw: 'false' as 'false',
317 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 - 8')
330 it('Should make an advanced search and only show the last result', async function () {
332 search: '1111 2222 3333',
333 languageOneOf: [ 'pl', 'fr' ],
335 nsfw: 'false' as 'false',
336 licenceOneOf: [ 1, 4 ],
342 const res = await advancedVideosSearch(server.url, query)
343 expect(res.body.total).to.equal(4)
345 const videos = res.body.data
346 expect(videos[0].name).to.equal('1111 2222 3333')
349 it('Should search on originally published date', async function () {
351 search: '1111 2222 3333',
352 languageOneOf: [ 'pl', 'fr' ],
354 nsfw: 'false' as 'false',
355 licenceOneOf: [ 1, 4 ]
359 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
360 const res = await advancedVideosSearch(server.url, query)
362 expect(res.body.total).to.equal(1)
363 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
367 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
368 const res = await advancedVideosSearch(server.url, query)
370 expect(res.body.total).to.equal(1)
371 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
375 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
376 const res = await advancedVideosSearch(server.url, query)
378 expect(res.body.total).to.equal(0)
382 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
383 const res = await advancedVideosSearch(server.url, query)
385 expect(res.body.total).to.equal(0)
389 const query = immutableAssign(baseQuery, {
390 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
391 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
393 const res = await advancedVideosSearch(server.url, query)
395 expect(res.body.total).to.equal(0)
399 const query = immutableAssign(baseQuery, {
400 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
401 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
403 const res = await advancedVideosSearch(server.url, query)
405 expect(res.body.total).to.equal(1)
406 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
410 after(async function () {
411 killallServers([ server ])
413 // Keep the logs if the test failed