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