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