1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
12 setAccessTokensToServers,
16 } from '../../../../shared/extra-utils'
18 const expect = chai.expect
20 describe('Test a 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)
45 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: 'en' })
46 await uploadVideo(server.url, server.accessToken, attributes3)
48 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
49 await uploadVideo(server.url, server.accessToken, attributes4)
53 startDate = new Date().toISOString()
55 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2 })
56 await uploadVideo(server.url, server.accessToken, attributes5)
58 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] })
59 await uploadVideo(server.url, server.accessToken, attributes6)
61 const attributes7 = immutableAssign(attributes1, {
62 name: attributes1.name + ' - 7',
63 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
65 await uploadVideo(server.url, server.accessToken, attributes7)
67 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
68 await uploadVideo(server.url, server.accessToken, attributes8)
73 name: '3333 4444 5555',
74 fixture: 'video_short.mp4',
79 await uploadVideo(server.url, server.accessToken, attributes)
81 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
86 name: '6666 7777 8888',
87 fixture: 'video_short.mp4',
92 await uploadVideo(server.url, server.accessToken, attributes)
98 tags: [ 'aaaa', 'bbbb', 'cccc' ],
101 await uploadVideo(server.url, server.accessToken, attributes1)
102 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
104 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
105 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
109 const attributes1 = {
113 await uploadVideo(server.url, server.accessToken, attributes1)
114 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
118 it('Should make a simple search and not have results', async function () {
119 const res = await searchVideo(server.url, 'abc')
121 expect(res.body.total).to.equal(0)
122 expect(res.body.data).to.have.lengthOf(0)
125 it('Should make a simple search and have results', async function () {
126 const res = await searchVideo(server.url, '4444 5555 duplicate')
128 expect(res.body.total).to.equal(2)
130 const videos = res.body.data
131 expect(videos).to.have.lengthOf(2)
134 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
135 expect(videos[1].name).to.equal('3333 4444 5555')
138 it('Should make a search on tags too, and have results', async function () {
143 const res = await advancedVideosSearch(server.url, query)
145 expect(res.body.total).to.equal(2)
147 const videos = res.body.data
148 expect(videos).to.have.lengthOf(2)
151 expect(videos[0].name).to.equal('aaaa 2')
152 expect(videos[1].name).to.equal('9999')
155 it('Should filter on tags without a search', async function () {
157 tagsAllOf: [ 'bbbb' ]
159 const res = await advancedVideosSearch(server.url, query)
161 expect(res.body.total).to.equal(2)
163 const videos = res.body.data
164 expect(videos).to.have.lengthOf(2)
166 expect(videos[0].name).to.equal('9999')
167 expect(videos[1].name).to.equal('9999')
170 it('Should filter on category without a search', async function () {
174 const res = await advancedVideosSearch(server.url, query)
176 expect(res.body.total).to.equal(1)
178 const videos = res.body.data
179 expect(videos).to.have.lengthOf(1)
181 expect(videos[0].name).to.equal('6666 7777 8888')
184 it('Should search by tags (one of)', async function () {
187 categoryOneOf: [ 1 ],
188 tagsOneOf: [ 'aaaa', 'ffff' ]
190 const res1 = await advancedVideosSearch(server.url, query)
191 expect(res1.body.total).to.equal(2)
193 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
194 expect(res2.body.total).to.equal(0)
197 it('Should search by tags (all of)', async function () {
200 categoryOneOf: [ 1 ],
201 tagsAllOf: [ 'cccc' ]
203 const res1 = await advancedVideosSearch(server.url, query)
204 expect(res1.body.total).to.equal(2)
206 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blabla' ] }))
207 expect(res2.body.total).to.equal(0)
209 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'cccc' ] }))
210 expect(res3.body.total).to.equal(1)
213 it('Should search by category', async function () {
218 const res1 = await advancedVideosSearch(server.url, query)
219 expect(res1.body.total).to.equal(1)
220 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
222 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
223 expect(res2.body.total).to.equal(0)
226 it('Should search by licence', async function () {
231 const res1 = await advancedVideosSearch(server.url, query)
232 expect(res1.body.total).to.equal(2)
233 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
234 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
236 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
237 expect(res2.body.total).to.equal(0)
240 it('Should search by languages', async function () {
242 search: '1111 2222 3333',
243 languageOneOf: [ 'pl', 'en' ]
245 const res1 = await advancedVideosSearch(server.url, query)
246 expect(res1.body.total).to.equal(2)
247 expect(res1.body.data[0].name).to.equal('1111 2222 3333 - 3')
248 expect(res1.body.data[1].name).to.equal('1111 2222 3333 - 4')
250 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
251 expect(res2.body.total).to.equal(0)
254 it('Should search by start date', async function () {
256 search: '1111 2222 3333',
260 const res = await advancedVideosSearch(server.url, query)
261 expect(res.body.total).to.equal(4)
263 const videos = res.body.data
264 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
265 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
266 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
267 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
270 it('Should make an advanced search', async function () {
272 search: '1111 2222 3333',
273 languageOneOf: [ 'pl', 'fr' ],
275 nsfw: 'false' as 'false',
276 licenceOneOf: [ 1, 4 ]
279 const res = await advancedVideosSearch(server.url, query)
280 expect(res.body.total).to.equal(4)
282 const videos = res.body.data
283 expect(videos[0].name).to.equal('1111 2222 3333')
284 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
285 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
286 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
289 it('Should make an advanced search and sort results', async function () {
291 search: '1111 2222 3333',
292 languageOneOf: [ 'pl', 'fr' ],
294 nsfw: 'false' as 'false',
295 licenceOneOf: [ 1, 4 ],
299 const res = await advancedVideosSearch(server.url, query)
300 expect(res.body.total).to.equal(4)
302 const videos = res.body.data
303 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
304 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
305 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
306 expect(videos[3].name).to.equal('1111 2222 3333')
309 it('Should make an advanced search and only show the first result', async function () {
311 search: '1111 2222 3333',
312 languageOneOf: [ 'pl', 'fr' ],
314 nsfw: 'false' as 'false',
315 licenceOneOf: [ 1, 4 ],
321 const res = await advancedVideosSearch(server.url, query)
322 expect(res.body.total).to.equal(4)
324 const videos = res.body.data
325 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
328 it('Should make an advanced search and only show the last result', async function () {
330 search: '1111 2222 3333',
331 languageOneOf: [ 'pl', 'fr' ],
333 nsfw: 'false' as 'false',
334 licenceOneOf: [ 1, 4 ],
340 const res = await advancedVideosSearch(server.url, query)
341 expect(res.body.total).to.equal(4)
343 const videos = res.body.data
344 expect(videos[0].name).to.equal('1111 2222 3333')
347 it('Should search on originally published date', async function () {
349 search: '1111 2222 3333',
350 languageOneOf: [ 'pl', 'fr' ],
352 nsfw: 'false' as 'false',
353 licenceOneOf: [ 1, 4 ]
357 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
358 const res = await advancedVideosSearch(server.url, query)
360 expect(res.body.total).to.equal(1)
361 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
365 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
366 const res = await advancedVideosSearch(server.url, query)
368 expect(res.body.total).to.equal(1)
369 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
373 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
374 const res = await advancedVideosSearch(server.url, query)
376 expect(res.body.total).to.equal(0)
380 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
381 const res = await advancedVideosSearch(server.url, query)
383 expect(res.body.total).to.equal(0)
387 const query = immutableAssign(baseQuery, {
388 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
389 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
391 const res = await advancedVideosSearch(server.url, query)
393 expect(res.body.total).to.equal(0)
397 const query = immutableAssign(baseQuery, {
398 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
399 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
401 const res = await advancedVideosSearch(server.url, query)
403 expect(res.body.total).to.equal(1)
404 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
409 killallServers([ server ])