]>
Commit | Line | Data |
---|---|---|
d525fc39 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | advancedVideosSearch, | |
7 | flushTests, | |
8 | killallServers, | |
9 | runServer, | |
10 | searchVideo, | |
11 | ServerInfo, | |
12 | setAccessTokensToServers, | |
13 | uploadVideo, | |
14 | wait, | |
15 | immutableAssign | |
9639bd17 | 16 | } from '../../../../shared/utils' |
d525fc39 C |
17 | |
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test a videos search', function () { | |
21 | let server: ServerInfo = null | |
22 | let startDate: string | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(30000) | |
26 | ||
27 | await flushTests() | |
28 | ||
29 | server = await runServer(1) | |
30 | ||
31 | await setAccessTokensToServers([ server ]) | |
32 | ||
33 | { | |
34 | const attributes1 = { | |
35 | name: '1111 2222 3333', | |
36 | fixture: '60fps_720p_small.mp4', // 2 seconds | |
37 | category: 1, | |
38 | licence: 1, | |
39 | nsfw: false, | |
40 | language: 'fr' | |
41 | } | |
42 | await uploadVideo(server.url, server.accessToken, attributes1) | |
43 | ||
44 | const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }) | |
45 | await uploadVideo(server.url, server.accessToken, attributes2) | |
46 | ||
47 | const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: 'en' }) | |
48 | await uploadVideo(server.url, server.accessToken, attributes3) | |
49 | ||
50 | const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true }) | |
51 | await uploadVideo(server.url, server.accessToken, attributes4) | |
52 | ||
53 | await wait(1000) | |
54 | ||
55 | startDate = new Date().toISOString() | |
56 | ||
57 | const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2 }) | |
58 | await uploadVideo(server.url, server.accessToken, attributes5) | |
59 | ||
60 | const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] }) | |
61 | await uploadVideo(server.url, server.accessToken, attributes6) | |
62 | ||
31d065cc AM |
63 | const attributes7 = immutableAssign(attributes1, { |
64 | name: attributes1.name + ' - 7', | |
65 | originallyPublishedAt: '2019-02-12T09:58:08.286Z' | |
66 | }) | |
d525fc39 C |
67 | await uploadVideo(server.url, server.accessToken, attributes7) |
68 | ||
69 | const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) | |
70 | await uploadVideo(server.url, server.accessToken, attributes8) | |
71 | } | |
72 | ||
73 | { | |
74 | const attributes = { | |
75 | name: '3333 4444 5555', | |
76 | fixture: 'video_short.mp4', | |
77 | category: 2, | |
78 | licence: 2, | |
79 | language: 'en' | |
80 | } | |
81 | await uploadVideo(server.url, server.accessToken, attributes) | |
82 | ||
83 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' })) | |
84 | } | |
85 | ||
86 | { | |
87 | const attributes = { | |
88 | name: '6666 7777 8888', | |
89 | fixture: 'video_short.mp4', | |
90 | category: 3, | |
91 | licence: 3, | |
92 | language: 'pl' | |
93 | } | |
94 | await uploadVideo(server.url, server.accessToken, attributes) | |
95 | } | |
96 | ||
97 | { | |
98 | const attributes1 = { | |
99 | name: '9999', | |
100 | tags: [ 'aaaa', 'bbbb', 'cccc' ], | |
101 | category: 1 | |
102 | } | |
103 | await uploadVideo(server.url, server.accessToken, attributes1) | |
104 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) | |
105 | ||
106 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] })) | |
107 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] })) | |
108 | } | |
d4112450 C |
109 | |
110 | { | |
111 | const attributes1 = { | |
112 | name: 'aaaa 2', | |
113 | category: 1 | |
114 | } | |
115 | await uploadVideo(server.url, server.accessToken, attributes1) | |
116 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) | |
117 | } | |
d525fc39 C |
118 | }) |
119 | ||
120 | it('Should make a simple search and not have results', async function () { | |
121 | const res = await searchVideo(server.url, 'abc') | |
122 | ||
123 | expect(res.body.total).to.equal(0) | |
124 | expect(res.body.data).to.have.lengthOf(0) | |
125 | }) | |
126 | ||
127 | it('Should make a simple search and have results', async function () { | |
128 | const res = await searchVideo(server.url, '4444 5555 duplicate') | |
129 | ||
130 | expect(res.body.total).to.equal(2) | |
131 | ||
132 | const videos = res.body.data | |
133 | expect(videos).to.have.lengthOf(2) | |
134 | ||
135 | // bestmatch | |
136 | expect(videos[0].name).to.equal('3333 4444 5555 duplicate') | |
137 | expect(videos[1].name).to.equal('3333 4444 5555') | |
138 | }) | |
139 | ||
d4112450 C |
140 | it('Should make a search on tags too, and have results', async function () { |
141 | const query = { | |
142 | search: 'aaaa', | |
143 | categoryOneOf: [ 1 ] | |
144 | } | |
145 | const res = await advancedVideosSearch(server.url, query) | |
146 | ||
147 | expect(res.body.total).to.equal(2) | |
148 | ||
149 | const videos = res.body.data | |
150 | expect(videos).to.have.lengthOf(2) | |
151 | ||
152 | // bestmatch | |
153 | expect(videos[0].name).to.equal('aaaa 2') | |
154 | expect(videos[1].name).to.equal('9999') | |
155 | }) | |
156 | ||
157 | it('Should filter on tags without a search', async function () { | |
158 | const query = { | |
159 | tagsAllOf: [ 'bbbb' ] | |
160 | } | |
161 | const res = await advancedVideosSearch(server.url, query) | |
162 | ||
163 | expect(res.body.total).to.equal(2) | |
164 | ||
165 | const videos = res.body.data | |
166 | expect(videos).to.have.lengthOf(2) | |
167 | ||
168 | expect(videos[0].name).to.equal('9999') | |
169 | expect(videos[1].name).to.equal('9999') | |
170 | }) | |
171 | ||
172 | it('Should filter on category without a search', async function () { | |
173 | const query = { | |
174 | categoryOneOf: [ 3 ] | |
175 | } | |
176 | const res = await advancedVideosSearch(server.url, query) | |
177 | ||
178 | expect(res.body.total).to.equal(1) | |
179 | ||
180 | const videos = res.body.data | |
181 | expect(videos).to.have.lengthOf(1) | |
182 | ||
183 | expect(videos[0].name).to.equal('6666 7777 8888') | |
184 | }) | |
185 | ||
d525fc39 C |
186 | it('Should search by tags (one of)', async function () { |
187 | const query = { | |
188 | search: '9999', | |
189 | categoryOneOf: [ 1 ], | |
190 | tagsOneOf: [ 'aaaa', 'ffff' ] | |
191 | } | |
192 | const res1 = await advancedVideosSearch(server.url, query) | |
193 | expect(res1.body.total).to.equal(2) | |
194 | ||
195 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] })) | |
196 | expect(res2.body.total).to.equal(0) | |
197 | }) | |
198 | ||
199 | it('Should search by tags (all of)', async function () { | |
200 | const query = { | |
201 | search: '9999', | |
202 | categoryOneOf: [ 1 ], | |
203 | tagsAllOf: [ 'cccc' ] | |
204 | } | |
205 | const res1 = await advancedVideosSearch(server.url, query) | |
206 | expect(res1.body.total).to.equal(2) | |
207 | ||
208 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blabla' ] })) | |
209 | expect(res2.body.total).to.equal(0) | |
210 | ||
211 | const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'cccc' ] })) | |
212 | expect(res3.body.total).to.equal(1) | |
213 | }) | |
214 | ||
215 | it('Should search by category', async function () { | |
216 | const query = { | |
217 | search: '6666', | |
218 | categoryOneOf: [ 3 ] | |
219 | } | |
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') | |
223 | ||
224 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] })) | |
225 | expect(res2.body.total).to.equal(0) | |
226 | }) | |
227 | ||
228 | it('Should search by licence', async function () { | |
229 | const query = { | |
230 | search: '4444 5555', | |
231 | licenceOneOf: [ 2 ] | |
232 | } | |
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') | |
237 | ||
238 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] })) | |
239 | expect(res2.body.total).to.equal(0) | |
240 | }) | |
241 | ||
242 | it('Should search by languages', async function () { | |
243 | const query = { | |
244 | search: '1111 2222 3333', | |
245 | languageOneOf: [ 'pl', 'en' ] | |
246 | } | |
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') | |
251 | ||
252 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] })) | |
253 | expect(res2.body.total).to.equal(0) | |
254 | }) | |
255 | ||
256 | it('Should search by start date', async function () { | |
257 | const query = { | |
258 | search: '1111 2222 3333', | |
259 | startDate | |
260 | } | |
261 | ||
262 | const res = await advancedVideosSearch(server.url, query) | |
263 | expect(res.body.total).to.equal(4) | |
264 | ||
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') | |
270 | }) | |
271 | ||
272 | it('Should make an advanced search', async function () { | |
273 | const query = { | |
274 | search: '1111 2222 3333', | |
275 | languageOneOf: [ 'pl', 'fr' ], | |
276 | durationMax: 4, | |
0b18f4aa | 277 | nsfw: 'false' as 'false', |
d525fc39 C |
278 | licenceOneOf: [ 1, 4 ] |
279 | } | |
280 | ||
281 | const res = await advancedVideosSearch(server.url, query) | |
282 | expect(res.body.total).to.equal(4) | |
283 | ||
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') | |
289 | }) | |
290 | ||
291 | it('Should make an advanced search and sort results', async function () { | |
292 | const query = { | |
293 | search: '1111 2222 3333', | |
294 | languageOneOf: [ 'pl', 'fr' ], | |
295 | durationMax: 4, | |
0b18f4aa | 296 | nsfw: 'false' as 'false', |
d525fc39 C |
297 | licenceOneOf: [ 1, 4 ], |
298 | sort: '-name' | |
299 | } | |
300 | ||
301 | const res = await advancedVideosSearch(server.url, query) | |
302 | expect(res.body.total).to.equal(4) | |
303 | ||
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') | |
309 | }) | |
310 | ||
311 | it('Should make an advanced search and only show the first result', async function () { | |
312 | const query = { | |
313 | search: '1111 2222 3333', | |
314 | languageOneOf: [ 'pl', 'fr' ], | |
315 | durationMax: 4, | |
0b18f4aa | 316 | nsfw: 'false' as 'false', |
d525fc39 C |
317 | licenceOneOf: [ 1, 4 ], |
318 | sort: '-name', | |
319 | start: 0, | |
320 | count: 1 | |
321 | } | |
322 | ||
323 | const res = await advancedVideosSearch(server.url, query) | |
324 | expect(res.body.total).to.equal(4) | |
325 | ||
326 | const videos = res.body.data | |
327 | expect(videos[0].name).to.equal('1111 2222 3333 - 8') | |
328 | }) | |
329 | ||
330 | it('Should make an advanced search and only show the last result', async function () { | |
331 | const query = { | |
332 | search: '1111 2222 3333', | |
333 | languageOneOf: [ 'pl', 'fr' ], | |
334 | durationMax: 4, | |
0b18f4aa | 335 | nsfw: 'false' as 'false', |
d525fc39 C |
336 | licenceOneOf: [ 1, 4 ], |
337 | sort: '-name', | |
338 | start: 3, | |
339 | count: 1 | |
340 | } | |
341 | ||
342 | const res = await advancedVideosSearch(server.url, query) | |
343 | expect(res.body.total).to.equal(4) | |
344 | ||
345 | const videos = res.body.data | |
346 | expect(videos[0].name).to.equal('1111 2222 3333') | |
347 | }) | |
348 | ||
31d065cc AM |
349 | it('Should search on originally published date', async function () { |
350 | const baseQuery = { | |
351 | search: '1111 2222 3333', | |
352 | languageOneOf: [ 'pl', 'fr' ], | |
353 | durationMax: 4, | |
354 | nsfw: 'false' as 'false', | |
355 | licenceOneOf: [ 1, 4 ] | |
356 | } | |
357 | ||
358 | { | |
359 | const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) | |
360 | const res = await advancedVideosSearch(server.url, query) | |
361 | ||
362 | expect(res.body.total).to.equal(1) | |
363 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | |
364 | } | |
365 | ||
366 | { | |
367 | const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) | |
368 | const res = await advancedVideosSearch(server.url, query) | |
369 | ||
370 | expect(res.body.total).to.equal(1) | |
371 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | |
372 | } | |
373 | ||
374 | { | |
375 | const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) | |
376 | const res = await advancedVideosSearch(server.url, query) | |
377 | ||
378 | expect(res.body.total).to.equal(0) | |
379 | } | |
380 | ||
381 | { | |
382 | const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) | |
383 | const res = await advancedVideosSearch(server.url, query) | |
384 | ||
385 | expect(res.body.total).to.equal(0) | |
386 | } | |
387 | ||
388 | { | |
389 | const query = immutableAssign(baseQuery, { | |
390 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', | |
391 | originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' | |
392 | }) | |
393 | const res = await advancedVideosSearch(server.url, query) | |
394 | ||
395 | expect(res.body.total).to.equal(0) | |
396 | } | |
397 | ||
398 | { | |
399 | const query = immutableAssign(baseQuery, { | |
400 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', | |
401 | originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' | |
402 | }) | |
403 | const res = await advancedVideosSearch(server.url, query) | |
404 | ||
405 | expect(res.body.total).to.equal(1) | |
406 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | |
407 | } | |
408 | }) | |
409 | ||
d525fc39 C |
410 | after(async function () { |
411 | killallServers([ server ]) | |
412 | ||
413 | // Keep the logs if the test failed | |
414 | if (this['ok']) { | |
415 | await flushTests() | |
416 | } | |
417 | }) | |
418 | }) |