]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/search/search-videos.ts
Fix E2E tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-videos.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
d525fc39 2
d525fc39 3import 'mocha'
1fd61899
C
4import * as chai from 'chai'
5import { VideoPrivacy } from '@shared/models'
d525fc39
C
6import {
7 advancedVideosSearch,
7243f84d 8 cleanupTests,
1fd61899 9 createLive,
210feb6c 10 flushAndRunServer,
7243f84d 11 immutableAssign,
d525fc39 12 searchVideo,
1fd61899 13 sendRTMPStreamInVideo,
d525fc39
C
14 ServerInfo,
15 setAccessTokensToServers,
1fd61899
C
16 setDefaultVideoChannel,
17 stopFfmpeg,
18 updateCustomSubConfig,
d525fc39 19 uploadVideo,
1fd61899
C
20 wait,
21 waitUntilLivePublished
94565d52 22} from '../../../../shared/extra-utils'
3caf77d3 23import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
d525fc39
C
24
25const expect = chai.expect
26
da3a3ab6 27describe('Test videos search', function () {
d525fc39
C
28 let server: ServerInfo = null
29 let startDate: string
3cf53828 30 let videoUUID: string
d525fc39
C
31
32 before(async function () {
3e3ae966 33 this.timeout(60000)
d525fc39 34
210feb6c 35 server = await flushAndRunServer(1)
d525fc39
C
36
37 await setAccessTokensToServers([ server ])
1fd61899 38 await setDefaultVideoChannel([ server ])
d525fc39
C
39
40 {
41 const attributes1 = {
42 name: '1111 2222 3333',
43 fixture: '60fps_720p_small.mp4', // 2 seconds
44 category: 1,
45 licence: 1,
46 nsfw: false,
47 language: 'fr'
48 }
49 await uploadVideo(server.url, server.accessToken, attributes1)
50
51 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
52 await uploadVideo(server.url, server.accessToken, attributes2)
53
3caf77d3
C
54 {
55 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined })
56 const res = await uploadVideo(server.url, server.accessToken, attributes3)
57 const videoId = res.body.video.id
3cf53828 58 videoUUID = res.body.video.uuid
3caf77d3
C
59
60 await createVideoCaption({
61 url: server.url,
62 accessToken: server.accessToken,
63 language: 'en',
64 videoId,
65 fixture: 'subtitle-good2.vtt',
66 mimeType: 'application/octet-stream'
67 })
68
69 await createVideoCaption({
70 url: server.url,
71 accessToken: server.accessToken,
72 language: 'aa',
73 videoId,
74 fixture: 'subtitle-good2.vtt',
75 mimeType: 'application/octet-stream'
76 })
77 }
d525fc39
C
78
79 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
80 await uploadVideo(server.url, server.accessToken, attributes4)
81
82 await wait(1000)
83
84 startDate = new Date().toISOString()
85
3caf77d3 86 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined })
d525fc39
C
87 await uploadVideo(server.url, server.accessToken, attributes5)
88
a1587156 89 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] })
d525fc39
C
90 await uploadVideo(server.url, server.accessToken, attributes6)
91
31d065cc
AM
92 const attributes7 = immutableAssign(attributes1, {
93 name: attributes1.name + ' - 7',
94 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
95 })
d525fc39
C
96 await uploadVideo(server.url, server.accessToken, attributes7)
97
98 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
99 await uploadVideo(server.url, server.accessToken, attributes8)
100 }
101
102 {
103 const attributes = {
104 name: '3333 4444 5555',
105 fixture: 'video_short.mp4',
106 category: 2,
107 licence: 2,
108 language: 'en'
109 }
110 await uploadVideo(server.url, server.accessToken, attributes)
111
112 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
113 }
114
115 {
116 const attributes = {
117 name: '6666 7777 8888',
118 fixture: 'video_short.mp4',
119 category: 3,
120 licence: 3,
121 language: 'pl'
122 }
123 await uploadVideo(server.url, server.accessToken, attributes)
124 }
125
126 {
127 const attributes1 = {
128 name: '9999',
129 tags: [ 'aaaa', 'bbbb', 'cccc' ],
130 category: 1
131 }
132 await uploadVideo(server.url, server.accessToken, attributes1)
133 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
134
135 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
136 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
137 }
d4112450
C
138
139 {
140 const attributes1 = {
141 name: 'aaaa 2',
142 category: 1
143 }
144 await uploadVideo(server.url, server.accessToken, attributes1)
145 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
146 }
d525fc39
C
147 })
148
149 it('Should make a simple search and not have results', async function () {
150 const res = await searchVideo(server.url, 'abc')
151
152 expect(res.body.total).to.equal(0)
153 expect(res.body.data).to.have.lengthOf(0)
154 })
155
156 it('Should make a simple search and have results', async function () {
157 const res = await searchVideo(server.url, '4444 5555 duplicate')
158
159 expect(res.body.total).to.equal(2)
160
161 const videos = res.body.data
162 expect(videos).to.have.lengthOf(2)
163
164 // bestmatch
165 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
166 expect(videos[1].name).to.equal('3333 4444 5555')
167 })
168
d4112450
C
169 it('Should make a search on tags too, and have results', async function () {
170 const query = {
171 search: 'aaaa',
172 categoryOneOf: [ 1 ]
173 }
174 const res = await advancedVideosSearch(server.url, query)
175
176 expect(res.body.total).to.equal(2)
177
178 const videos = res.body.data
179 expect(videos).to.have.lengthOf(2)
180
181 // bestmatch
182 expect(videos[0].name).to.equal('aaaa 2')
183 expect(videos[1].name).to.equal('9999')
184 })
185
186 it('Should filter on tags without a search', async function () {
187 const query = {
188 tagsAllOf: [ 'bbbb' ]
189 }
190 const res = await advancedVideosSearch(server.url, query)
191
192 expect(res.body.total).to.equal(2)
193
194 const videos = res.body.data
195 expect(videos).to.have.lengthOf(2)
196
197 expect(videos[0].name).to.equal('9999')
198 expect(videos[1].name).to.equal('9999')
199 })
200
201 it('Should filter on category without a search', async function () {
202 const query = {
203 categoryOneOf: [ 3 ]
204 }
205 const res = await advancedVideosSearch(server.url, query)
206
207 expect(res.body.total).to.equal(1)
208
209 const videos = res.body.data
210 expect(videos).to.have.lengthOf(1)
211
212 expect(videos[0].name).to.equal('6666 7777 8888')
213 })
214
d525fc39
C
215 it('Should search by tags (one of)', async function () {
216 const query = {
217 search: '9999',
218 categoryOneOf: [ 1 ],
4b1f1b81 219 tagsOneOf: [ 'aAaa', 'ffff' ]
d525fc39
C
220 }
221 const res1 = await advancedVideosSearch(server.url, query)
222 expect(res1.body.total).to.equal(2)
223
224 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
225 expect(res2.body.total).to.equal(0)
226 })
227
228 it('Should search by tags (all of)', async function () {
229 const query = {
230 search: '9999',
231 categoryOneOf: [ 1 ],
4b1f1b81 232 tagsAllOf: [ 'CCcc' ]
d525fc39
C
233 }
234 const res1 = await advancedVideosSearch(server.url, query)
235 expect(res1.body.total).to.equal(2)
236
4b1f1b81 237 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blAbla' ] }))
d525fc39
C
238 expect(res2.body.total).to.equal(0)
239
4b1f1b81 240 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'CCCC' ] }))
d525fc39
C
241 expect(res3.body.total).to.equal(1)
242 })
243
244 it('Should search by category', async function () {
245 const query = {
246 search: '6666',
247 categoryOneOf: [ 3 ]
248 }
249 const res1 = await advancedVideosSearch(server.url, query)
250 expect(res1.body.total).to.equal(1)
251 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
252
253 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
254 expect(res2.body.total).to.equal(0)
255 })
256
257 it('Should search by licence', async function () {
258 const query = {
259 search: '4444 5555',
260 licenceOneOf: [ 2 ]
261 }
262 const res1 = await advancedVideosSearch(server.url, query)
263 expect(res1.body.total).to.equal(2)
264 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
265 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
266
267 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
268 expect(res2.body.total).to.equal(0)
269 })
270
271 it('Should search by languages', async function () {
272 const query = {
273 search: '1111 2222 3333',
274 languageOneOf: [ 'pl', 'en' ]
275 }
d525fc39 276
3caf77d3
C
277 {
278 const res = await advancedVideosSearch(server.url, query)
279 expect(res.body.total).to.equal(2)
a1587156
C
280 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
281 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4')
3caf77d3
C
282 }
283
284 {
285 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] }))
286 expect(res.body.total).to.equal(3)
a1587156
C
287 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
288 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4')
289 expect(res.body.data[2].name).to.equal('1111 2222 3333 - 5')
3caf77d3
C
290 }
291
292 {
293 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
294 expect(res.body.total).to.equal(0)
295 }
d525fc39
C
296 })
297
298 it('Should search by start date', async function () {
299 const query = {
300 search: '1111 2222 3333',
301 startDate
302 }
303
304 const res = await advancedVideosSearch(server.url, query)
305 expect(res.body.total).to.equal(4)
306
307 const videos = res.body.data
308 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
309 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
310 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
311 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
312 })
313
314 it('Should make an advanced search', async function () {
315 const query = {
316 search: '1111 2222 3333',
317 languageOneOf: [ 'pl', 'fr' ],
318 durationMax: 4,
0b18f4aa 319 nsfw: 'false' as 'false',
d525fc39
C
320 licenceOneOf: [ 1, 4 ]
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')
328 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
329 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
330 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
331 })
332
333 it('Should make an advanced search and sort results', async function () {
334 const query = {
335 search: '1111 2222 3333',
336 languageOneOf: [ 'pl', 'fr' ],
337 durationMax: 4,
0b18f4aa 338 nsfw: 'false' as 'false',
d525fc39
C
339 licenceOneOf: [ 1, 4 ],
340 sort: '-name'
341 }
342
343 const res = await advancedVideosSearch(server.url, query)
344 expect(res.body.total).to.equal(4)
345
346 const videos = res.body.data
347 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
348 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
349 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
350 expect(videos[3].name).to.equal('1111 2222 3333')
351 })
352
353 it('Should make an advanced search and only show the first result', async function () {
354 const query = {
355 search: '1111 2222 3333',
356 languageOneOf: [ 'pl', 'fr' ],
357 durationMax: 4,
0b18f4aa 358 nsfw: 'false' as 'false',
d525fc39
C
359 licenceOneOf: [ 1, 4 ],
360 sort: '-name',
361 start: 0,
362 count: 1
363 }
364
365 const res = await advancedVideosSearch(server.url, query)
366 expect(res.body.total).to.equal(4)
367
368 const videos = res.body.data
369 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
370 })
371
372 it('Should make an advanced search and only show the last result', async function () {
373 const query = {
374 search: '1111 2222 3333',
375 languageOneOf: [ 'pl', 'fr' ],
376 durationMax: 4,
0b18f4aa 377 nsfw: 'false' as 'false',
d525fc39
C
378 licenceOneOf: [ 1, 4 ],
379 sort: '-name',
380 start: 3,
381 count: 1
382 }
383
384 const res = await advancedVideosSearch(server.url, query)
385 expect(res.body.total).to.equal(4)
386
387 const videos = res.body.data
388 expect(videos[0].name).to.equal('1111 2222 3333')
389 })
390
31d065cc
AM
391 it('Should search on originally published date', async function () {
392 const baseQuery = {
393 search: '1111 2222 3333',
394 languageOneOf: [ 'pl', 'fr' ],
395 durationMax: 4,
396 nsfw: 'false' as 'false',
397 licenceOneOf: [ 1, 4 ]
398 }
399
400 {
401 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
402 const res = await advancedVideosSearch(server.url, query)
403
404 expect(res.body.total).to.equal(1)
405 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
406 }
407
408 {
409 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
410 const res = await advancedVideosSearch(server.url, query)
411
412 expect(res.body.total).to.equal(1)
413 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
414 }
415
416 {
417 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
418 const res = await advancedVideosSearch(server.url, query)
419
420 expect(res.body.total).to.equal(0)
421 }
422
423 {
424 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
425 const res = await advancedVideosSearch(server.url, query)
426
427 expect(res.body.total).to.equal(0)
428 }
429
430 {
431 const query = immutableAssign(baseQuery, {
432 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
433 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
434 })
435 const res = await advancedVideosSearch(server.url, query)
436
437 expect(res.body.total).to.equal(0)
438 }
439
440 {
441 const query = immutableAssign(baseQuery, {
442 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
443 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
444 })
445 const res = await advancedVideosSearch(server.url, query)
446
447 expect(res.body.total).to.equal(1)
448 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
449 }
450 })
451
3cf53828
C
452 it('Should search by UUID', async function () {
453 const search = videoUUID
454 const res = await advancedVideosSearch(server.url, { search })
455
456 expect(res.body.total).to.equal(1)
457 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3')
458 })
459
1fd61899
C
460 it('Should search by live', async function () {
461 this.timeout(30000)
462
463 {
464 const options = {
465 search: {
466 searchIndex: { enabled: false }
467 },
468 live: { enabled: true }
469 }
470 await updateCustomSubConfig(server.url, server.accessToken, options)
471 }
472
473 {
474 const res = await advancedVideosSearch(server.url, { isLive: true })
475
476 expect(res.body.total).to.equal(0)
477 expect(res.body.data).to.have.lengthOf(0)
478 }
479
480 {
481 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id }
482 const resLive = await createLive(server.url, server.accessToken, liveOptions)
483 const liveVideoId = resLive.body.video.uuid
484
485 const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId)
486 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId)
487
488 const res = await advancedVideosSearch(server.url, { isLive: true })
489
490 expect(res.body.total).to.equal(1)
491 expect(res.body.data[0].name).to.equal('live')
492
493 await stopFfmpeg(command)
494 }
495 })
496
7c3b7976
C
497 after(async function () {
498 await cleanupTests([ server ])
d525fc39
C
499 })
500})