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