1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
12 setAccessTokensToServers,
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, { name: attributes1.name + ' - 7' })
64 await uploadVideo(server.url, server.accessToken, attributes7)
66 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
67 await uploadVideo(server.url, server.accessToken, attributes8)
72 name: '3333 4444 5555',
73 fixture: 'video_short.mp4',
78 await uploadVideo(server.url, server.accessToken, attributes)
80 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
85 name: '6666 7777 8888',
86 fixture: 'video_short.mp4',
91 await uploadVideo(server.url, server.accessToken, attributes)
97 tags: [ 'aaaa', 'bbbb', 'cccc' ],
100 await uploadVideo(server.url, server.accessToken, attributes1)
101 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
103 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
104 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
108 const attributes1 = {
112 await uploadVideo(server.url, server.accessToken, attributes1)
113 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
117 it('Should make a simple search and not have results', async function () {
118 const res = await searchVideo(server.url, 'abc')
120 expect(res.body.total).to.equal(0)
121 expect(res.body.data).to.have.lengthOf(0)
124 it('Should make a simple search and have results', async function () {
125 const res = await searchVideo(server.url, '4444 5555 duplicate')
127 expect(res.body.total).to.equal(2)
129 const videos = res.body.data
130 expect(videos).to.have.lengthOf(2)
133 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
134 expect(videos[1].name).to.equal('3333 4444 5555')
137 it('Should make a search on tags too, and have results', async function () {
142 const res = await advancedVideosSearch(server.url, query)
144 expect(res.body.total).to.equal(2)
146 const videos = res.body.data
147 expect(videos).to.have.lengthOf(2)
150 expect(videos[0].name).to.equal('aaaa 2')
151 expect(videos[1].name).to.equal('9999')
154 it('Should filter on tags without a search', async function () {
156 tagsAllOf: [ 'bbbb' ]
158 const res = await advancedVideosSearch(server.url, query)
160 expect(res.body.total).to.equal(2)
162 const videos = res.body.data
163 expect(videos).to.have.lengthOf(2)
165 expect(videos[0].name).to.equal('9999')
166 expect(videos[1].name).to.equal('9999')
169 it('Should filter on category without a search', async function () {
173 const res = await advancedVideosSearch(server.url, query)
175 expect(res.body.total).to.equal(1)
177 const videos = res.body.data
178 expect(videos).to.have.lengthOf(1)
180 expect(videos[0].name).to.equal('6666 7777 8888')
183 it('Should search by tags (one of)', async function () {
186 categoryOneOf: [ 1 ],
187 tagsOneOf: [ 'aaaa', 'ffff' ]
189 const res1 = await advancedVideosSearch(server.url, query)
190 expect(res1.body.total).to.equal(2)
192 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
193 expect(res2.body.total).to.equal(0)
196 it('Should search by tags (all of)', async function () {
199 categoryOneOf: [ 1 ],
200 tagsAllOf: [ 'cccc' ]
202 const res1 = await advancedVideosSearch(server.url, query)
203 expect(res1.body.total).to.equal(2)
205 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blabla' ] }))
206 expect(res2.body.total).to.equal(0)
208 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'cccc' ] }))
209 expect(res3.body.total).to.equal(1)
212 it('Should search by category', async function () {
217 const res1 = await advancedVideosSearch(server.url, query)
218 expect(res1.body.total).to.equal(1)
219 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
221 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
222 expect(res2.body.total).to.equal(0)
225 it('Should search by licence', async function () {
230 const res1 = await advancedVideosSearch(server.url, query)
231 expect(res1.body.total).to.equal(2)
232 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
233 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
235 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
236 expect(res2.body.total).to.equal(0)
239 it('Should search by languages', async function () {
241 search: '1111 2222 3333',
242 languageOneOf: [ 'pl', 'en' ]
244 const res1 = await advancedVideosSearch(server.url, query)
245 expect(res1.body.total).to.equal(2)
246 expect(res1.body.data[0].name).to.equal('1111 2222 3333 - 3')
247 expect(res1.body.data[1].name).to.equal('1111 2222 3333 - 4')
249 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
250 expect(res2.body.total).to.equal(0)
253 it('Should search by start date', async function () {
255 search: '1111 2222 3333',
259 const res = await advancedVideosSearch(server.url, query)
260 expect(res.body.total).to.equal(4)
262 const videos = res.body.data
263 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
264 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
265 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
266 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
269 it('Should make an advanced search', async function () {
271 search: '1111 2222 3333',
272 languageOneOf: [ 'pl', 'fr' ],
274 nsfw: 'false' as 'false',
275 licenceOneOf: [ 1, 4 ]
278 const res = await advancedVideosSearch(server.url, query)
279 expect(res.body.total).to.equal(4)
281 const videos = res.body.data
282 expect(videos[0].name).to.equal('1111 2222 3333')
283 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
284 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
285 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
288 it('Should make an advanced search and sort results', async function () {
290 search: '1111 2222 3333',
291 languageOneOf: [ 'pl', 'fr' ],
293 nsfw: 'false' as 'false',
294 licenceOneOf: [ 1, 4 ],
298 const res = await advancedVideosSearch(server.url, query)
299 expect(res.body.total).to.equal(4)
301 const videos = res.body.data
302 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
303 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
304 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
305 expect(videos[3].name).to.equal('1111 2222 3333')
308 it('Should make an advanced search and only show the first result', async function () {
310 search: '1111 2222 3333',
311 languageOneOf: [ 'pl', 'fr' ],
313 nsfw: 'false' as 'false',
314 licenceOneOf: [ 1, 4 ],
320 const res = await advancedVideosSearch(server.url, query)
321 expect(res.body.total).to.equal(4)
323 const videos = res.body.data
324 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
327 it('Should make an advanced search and only show the last result', async function () {
329 search: '1111 2222 3333',
330 languageOneOf: [ 'pl', 'fr' ],
332 nsfw: 'false' as 'false',
333 licenceOneOf: [ 1, 4 ],
339 const res = await advancedVideosSearch(server.url, query)
340 expect(res.body.total).to.equal(4)
342 const videos = res.body.data
343 expect(videos[0].name).to.equal('1111 2222 3333')
346 after(async function () {
347 killallServers([ server ])
349 // Keep the logs if the test failed