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 it('Should make a simple search and not have results', async function () {
109 const res = await searchVideo(server.url, 'abc')
111 expect(res.body.total).to.equal(0)
112 expect(res.body.data).to.have.lengthOf(0)
115 it('Should make a simple search and have results', async function () {
116 const res = await searchVideo(server.url, '4444 5555 duplicate')
118 expect(res.body.total).to.equal(2)
120 const videos = res.body.data
121 expect(videos).to.have.lengthOf(2)
124 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
125 expect(videos[1].name).to.equal('3333 4444 5555')
128 it('Should search by tags (one of)', async function () {
131 categoryOneOf: [ 1 ],
132 tagsOneOf: [ 'aaaa', 'ffff' ]
134 const res1 = await advancedVideosSearch(server.url, query)
135 expect(res1.body.total).to.equal(2)
137 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
138 expect(res2.body.total).to.equal(0)
141 it('Should search by tags (all of)', async function () {
144 categoryOneOf: [ 1 ],
145 tagsAllOf: [ 'cccc' ]
147 const res1 = await advancedVideosSearch(server.url, query)
148 expect(res1.body.total).to.equal(2)
150 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blabla' ] }))
151 expect(res2.body.total).to.equal(0)
153 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'cccc' ] }))
154 expect(res3.body.total).to.equal(1)
157 it('Should search by category', async function () {
162 const res1 = await advancedVideosSearch(server.url, query)
163 expect(res1.body.total).to.equal(1)
164 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
166 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
167 expect(res2.body.total).to.equal(0)
170 it('Should search by licence', async function () {
175 const res1 = await advancedVideosSearch(server.url, query)
176 expect(res1.body.total).to.equal(2)
177 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
178 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
180 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
181 expect(res2.body.total).to.equal(0)
184 it('Should search by languages', async function () {
186 search: '1111 2222 3333',
187 languageOneOf: [ 'pl', 'en' ]
189 const res1 = await advancedVideosSearch(server.url, query)
190 expect(res1.body.total).to.equal(2)
191 expect(res1.body.data[0].name).to.equal('1111 2222 3333 - 3')
192 expect(res1.body.data[1].name).to.equal('1111 2222 3333 - 4')
194 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
195 expect(res2.body.total).to.equal(0)
198 it('Should search by start date', async function () {
200 search: '1111 2222 3333',
204 const res = await advancedVideosSearch(server.url, query)
205 expect(res.body.total).to.equal(4)
207 const videos = res.body.data
208 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
209 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
210 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
211 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
214 it('Should make an advanced search', async function () {
216 search: '1111 2222 3333',
217 languageOneOf: [ 'pl', 'fr' ],
219 nsfw: 'false' as 'false',
220 licenceOneOf: [ 1, 4 ]
223 const res = await advancedVideosSearch(server.url, query)
224 expect(res.body.total).to.equal(4)
226 const videos = res.body.data
227 expect(videos[0].name).to.equal('1111 2222 3333')
228 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
229 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
230 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
233 it('Should make an advanced search and sort results', async function () {
235 search: '1111 2222 3333',
236 languageOneOf: [ 'pl', 'fr' ],
238 nsfw: 'false' as 'false',
239 licenceOneOf: [ 1, 4 ],
243 const res = await advancedVideosSearch(server.url, query)
244 expect(res.body.total).to.equal(4)
246 const videos = res.body.data
247 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
248 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
249 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
250 expect(videos[3].name).to.equal('1111 2222 3333')
253 it('Should make an advanced search and only show the first result', async function () {
255 search: '1111 2222 3333',
256 languageOneOf: [ 'pl', 'fr' ],
258 nsfw: 'false' as 'false',
259 licenceOneOf: [ 1, 4 ],
265 const res = await advancedVideosSearch(server.url, query)
266 expect(res.body.total).to.equal(4)
268 const videos = res.body.data
269 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
272 it('Should make an advanced search and only show the last result', async function () {
274 search: '1111 2222 3333',
275 languageOneOf: [ 'pl', 'fr' ],
277 nsfw: 'false' as 'false',
278 licenceOneOf: [ 1, 4 ],
284 const res = await advancedVideosSearch(server.url, query)
285 expect(res.body.total).to.equal(4)
287 const videos = res.body.data
288 expect(videos[0].name).to.equal('1111 2222 3333')
291 after(async function () {
292 killallServers([ server ])
294 // Keep the logs if the test failed