1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
15 } from '@shared/extra-utils'
16 import { VideoPrivacy } from '@shared/models'
18 const expect = chai.expect
20 describe('Test videos search', function () {
21 let server: PeerTubeServer
22 let remoteServer: PeerTubeServer
26 let command: SearchCommand
28 before(async function () {
31 server = await createSingleServer(1)
32 remoteServer = await createSingleServer(2)
34 await setAccessTokensToServers([ server, remoteServer ])
35 await setDefaultVideoChannel([ server, remoteServer ])
39 name: '1111 2222 3333',
40 fixture: '60fps_720p_small.mp4', // 2 seconds
46 await server.videos.upload({ attributes: attributes1 })
48 const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
49 await server.videos.upload({ attributes: attributes2 })
52 const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
53 const { id, uuid } = await server.videos.upload({ attributes: attributes3 })
56 await server.captions.add({
59 fixture: 'subtitle-good2.vtt',
60 mimeType: 'application/octet-stream'
63 await server.captions.add({
66 fixture: 'subtitle-good2.vtt',
67 mimeType: 'application/octet-stream'
71 const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
72 await server.videos.upload({ attributes: attributes4 })
76 startDate = new Date().toISOString()
78 const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
79 await server.videos.upload({ attributes: attributes5 })
81 const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
82 await server.videos.upload({ attributes: attributes6 })
84 const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
85 await server.videos.upload({ attributes: attributes7 })
87 const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
88 await server.videos.upload({ attributes: attributes8 })
93 name: '3333 4444 5555',
94 fixture: 'video_short.mp4',
99 await server.videos.upload({ attributes: attributes })
101 await server.videos.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } })
106 name: '6666 7777 8888',
107 fixture: 'video_short.mp4',
112 await server.videos.upload({ attributes: attributes })
116 const attributes1 = {
118 tags: [ 'aaaa', 'bbbb', 'cccc' ],
121 await server.videos.upload({ attributes: attributes1 })
122 await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
124 await server.videos.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } })
125 await server.videos.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } })
129 const attributes1 = {
133 await server.videos.upload({ attributes: attributes1 })
134 await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
138 await remoteServer.videos.upload({ attributes: { name: 'remote video 1' } })
139 await remoteServer.videos.upload({ attributes: { name: 'remote video 2' } })
142 await doubleFollow(server, remoteServer)
144 command = server.search
147 it('Should make a simple search and not have results', async function () {
148 const body = await command.searchVideos({ search: 'abc' })
150 expect(body.total).to.equal(0)
151 expect(body.data).to.have.lengthOf(0)
154 it('Should make a simple search and have results', async function () {
155 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
157 expect(body.total).to.equal(2)
159 const videos = body.data
160 expect(videos).to.have.lengthOf(2)
163 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
164 expect(videos[1].name).to.equal('3333 4444 5555')
167 it('Should make a search on tags too, and have results', async function () {
172 const body = await command.advancedVideoSearch({ search })
174 expect(body.total).to.equal(2)
176 const videos = body.data
177 expect(videos).to.have.lengthOf(2)
180 expect(videos[0].name).to.equal('aaaa 2')
181 expect(videos[1].name).to.equal('9999')
184 it('Should filter on tags without a search', async function () {
186 tagsAllOf: [ 'bbbb' ]
188 const body = await command.advancedVideoSearch({ search })
190 expect(body.total).to.equal(2)
192 const videos = body.data
193 expect(videos).to.have.lengthOf(2)
195 expect(videos[0].name).to.equal('9999')
196 expect(videos[1].name).to.equal('9999')
199 it('Should filter on category without a search', async function () {
203 const body = await command.advancedVideoSearch({ search: search })
205 expect(body.total).to.equal(1)
207 const videos = body.data
208 expect(videos).to.have.lengthOf(1)
210 expect(videos[0].name).to.equal('6666 7777 8888')
213 it('Should search by tags (one of)', async function () {
216 categoryOneOf: [ 1 ],
217 tagsOneOf: [ 'aAaa', 'ffff' ]
221 const body = await command.advancedVideoSearch({ search: query })
222 expect(body.total).to.equal(2)
226 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
227 expect(body.total).to.equal(0)
231 it('Should search by tags (all of)', async function () {
234 categoryOneOf: [ 1 ],
235 tagsAllOf: [ 'CCcc' ]
239 const body = await command.advancedVideoSearch({ search: query })
240 expect(body.total).to.equal(2)
244 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
245 expect(body.total).to.equal(0)
249 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
250 expect(body.total).to.equal(1)
254 it('Should search by category', async function () {
261 const body = await command.advancedVideoSearch({ search: query })
262 expect(body.total).to.equal(1)
263 expect(body.data[0].name).to.equal('6666 7777 8888')
267 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
268 expect(body.total).to.equal(0)
272 it('Should search by licence', async function () {
279 const body = await command.advancedVideoSearch({ search: query })
280 expect(body.total).to.equal(2)
281 expect(body.data[0].name).to.equal('3333 4444 5555')
282 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
286 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
287 expect(body.total).to.equal(0)
291 it('Should search by languages', async function () {
293 search: '1111 2222 3333',
294 languageOneOf: [ 'pl', 'en' ]
298 const body = await command.advancedVideoSearch({ search: query })
299 expect(body.total).to.equal(2)
300 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
301 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
305 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
306 expect(body.total).to.equal(3)
307 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
308 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
309 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
313 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
314 expect(body.total).to.equal(0)
318 it('Should search by start date', async function () {
320 search: '1111 2222 3333',
324 const body = await command.advancedVideoSearch({ search: query })
325 expect(body.total).to.equal(4)
327 const videos = body.data
328 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
329 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
330 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
331 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
334 it('Should make an advanced search', async function () {
336 search: '1111 2222 3333',
337 languageOneOf: [ 'pl', 'fr' ],
339 nsfw: 'false' as 'false',
340 licenceOneOf: [ 1, 4 ]
343 const body = await command.advancedVideoSearch({ search: query })
344 expect(body.total).to.equal(4)
346 const videos = body.data
347 expect(videos[0].name).to.equal('1111 2222 3333')
348 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
349 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
350 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
353 it('Should make an advanced search and sort results', async function () {
355 search: '1111 2222 3333',
356 languageOneOf: [ 'pl', 'fr' ],
358 nsfw: 'false' as 'false',
359 licenceOneOf: [ 1, 4 ],
363 const body = await command.advancedVideoSearch({ search: query })
364 expect(body.total).to.equal(4)
366 const videos = body.data
367 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
368 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
369 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
370 expect(videos[3].name).to.equal('1111 2222 3333')
373 it('Should make an advanced search and only show the first result', async function () {
375 search: '1111 2222 3333',
376 languageOneOf: [ 'pl', 'fr' ],
378 nsfw: 'false' as 'false',
379 licenceOneOf: [ 1, 4 ],
385 const body = await command.advancedVideoSearch({ search: query })
386 expect(body.total).to.equal(4)
388 const videos = body.data
389 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
392 it('Should make an advanced search and only show the last result', async function () {
394 search: '1111 2222 3333',
395 languageOneOf: [ 'pl', 'fr' ],
397 nsfw: 'false' as 'false',
398 licenceOneOf: [ 1, 4 ],
404 const body = await command.advancedVideoSearch({ search: query })
405 expect(body.total).to.equal(4)
407 const videos = body.data
408 expect(videos[0].name).to.equal('1111 2222 3333')
411 it('Should search on originally published date', async function () {
413 search: '1111 2222 3333',
414 languageOneOf: [ 'pl', 'fr' ],
416 nsfw: 'false' as 'false',
417 licenceOneOf: [ 1, 4 ]
421 const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }
422 const body = await command.advancedVideoSearch({ search: query })
424 expect(body.total).to.equal(1)
425 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
429 const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }
430 const body = await command.advancedVideoSearch({ search: query })
432 expect(body.total).to.equal(1)
433 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
437 const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }
438 const body = await command.advancedVideoSearch({ search: query })
440 expect(body.total).to.equal(0)
444 const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }
445 const body = await command.advancedVideoSearch({ search: query })
447 expect(body.total).to.equal(0)
453 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
454 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
456 const body = await command.advancedVideoSearch({ search: query })
458 expect(body.total).to.equal(0)
464 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
465 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
467 const body = await command.advancedVideoSearch({ search: query })
469 expect(body.total).to.equal(1)
470 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
474 it('Should search by UUID', async function () {
475 const search = videoUUID
476 const body = await command.advancedVideoSearch({ search: { search } })
478 expect(body.total).to.equal(1)
479 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
482 it('Should search by host', async function () {
484 const body = await command.advancedVideoSearch({ search: { search: '6666 7777 8888', host: server.host } })
485 expect(body.total).to.equal(1)
486 expect(body.data[0].name).to.equal('6666 7777 8888')
490 const body = await command.advancedVideoSearch({ search: { search: '1111', host: 'example.com' } })
491 expect(body.total).to.equal(0)
492 expect(body.data).to.have.lengthOf(0)
496 const body = await command.advancedVideoSearch({ search: { search: 'remote', host: remoteServer.host } })
497 expect(body.total).to.equal(2)
498 expect(body.data).to.have.lengthOf(2)
499 expect(body.data[0].name).to.equal('remote video 1')
500 expect(body.data[1].name).to.equal('remote video 2')
504 it('Should search by live', async function () {
510 searchIndex: { enabled: false }
512 live: { enabled: true }
514 await server.config.updateCustomSubConfig({ newConfig })
518 const body = await command.advancedVideoSearch({ search: { isLive: true } })
520 expect(body.total).to.equal(0)
521 expect(body.data).to.have.lengthOf(0)
525 const liveCommand = server.live
527 const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.store.channel.id }
528 const live = await liveCommand.create({ fields: liveAttributes })
530 const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id })
531 await liveCommand.waitUntilPublished({ videoId: live.id })
533 const body = await command.advancedVideoSearch({ search: { isLive: true } })
535 expect(body.total).to.equal(1)
536 expect(body.data[0].name).to.equal('live')
538 await stopFfmpeg(ffmpegCommand)
542 after(async function () {
543 await cleanupTests([ server ])