1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 setAccessTokensToServers,
11 setDefaultVideoChannel,
14 } from '@shared/extra-utils'
15 import { VideoPrivacy } from '@shared/models'
17 const expect = chai.expect
19 describe('Test videos search', function () {
20 let server: PeerTubeServer = null
24 let command: SearchCommand
26 before(async function () {
29 server = await createSingleServer(1)
31 await setAccessTokensToServers([ server ])
32 await setDefaultVideoChannel([ server ])
36 name: '1111 2222 3333',
37 fixture: '60fps_720p_small.mp4', // 2 seconds
43 await server.videos.upload({ attributes: attributes1 })
45 const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
46 await server.videos.upload({ attributes: attributes2 })
49 const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
50 const { id, uuid } = await server.videos.upload({ attributes: attributes3 })
53 await server.captions.add({
56 fixture: 'subtitle-good2.vtt',
57 mimeType: 'application/octet-stream'
60 await server.captions.add({
63 fixture: 'subtitle-good2.vtt',
64 mimeType: 'application/octet-stream'
68 const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
69 await server.videos.upload({ attributes: attributes4 })
73 startDate = new Date().toISOString()
75 const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
76 await server.videos.upload({ attributes: attributes5 })
78 const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
79 await server.videos.upload({ attributes: attributes6 })
81 const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
82 await server.videos.upload({ attributes: attributes7 })
84 const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
85 await server.videos.upload({ attributes: attributes8 })
90 name: '3333 4444 5555',
91 fixture: 'video_short.mp4',
96 await server.videos.upload({ attributes: attributes })
98 await server.videos.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } })
103 name: '6666 7777 8888',
104 fixture: 'video_short.mp4',
109 await server.videos.upload({ attributes: attributes })
113 const attributes1 = {
115 tags: [ 'aaaa', 'bbbb', 'cccc' ],
118 await server.videos.upload({ attributes: attributes1 })
119 await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
121 await server.videos.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } })
122 await server.videos.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } })
126 const attributes1 = {
130 await server.videos.upload({ attributes: attributes1 })
131 await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
134 command = server.search
137 it('Should make a simple search and not have results', async function () {
138 const body = await command.searchVideos({ search: 'abc' })
140 expect(body.total).to.equal(0)
141 expect(body.data).to.have.lengthOf(0)
144 it('Should make a simple search and have results', async function () {
145 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
147 expect(body.total).to.equal(2)
149 const videos = body.data
150 expect(videos).to.have.lengthOf(2)
153 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
154 expect(videos[1].name).to.equal('3333 4444 5555')
157 it('Should make a search on tags too, and have results', async function () {
162 const body = await command.advancedVideoSearch({ search })
164 expect(body.total).to.equal(2)
166 const videos = body.data
167 expect(videos).to.have.lengthOf(2)
170 expect(videos[0].name).to.equal('aaaa 2')
171 expect(videos[1].name).to.equal('9999')
174 it('Should filter on tags without a search', async function () {
176 tagsAllOf: [ 'bbbb' ]
178 const body = await command.advancedVideoSearch({ search })
180 expect(body.total).to.equal(2)
182 const videos = body.data
183 expect(videos).to.have.lengthOf(2)
185 expect(videos[0].name).to.equal('9999')
186 expect(videos[1].name).to.equal('9999')
189 it('Should filter on category without a search', async function () {
193 const body = await command.advancedVideoSearch({ search: search })
195 expect(body.total).to.equal(1)
197 const videos = body.data
198 expect(videos).to.have.lengthOf(1)
200 expect(videos[0].name).to.equal('6666 7777 8888')
203 it('Should search by tags (one of)', async function () {
206 categoryOneOf: [ 1 ],
207 tagsOneOf: [ 'aAaa', 'ffff' ]
211 const body = await command.advancedVideoSearch({ search: query })
212 expect(body.total).to.equal(2)
216 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
217 expect(body.total).to.equal(0)
221 it('Should search by tags (all of)', async function () {
224 categoryOneOf: [ 1 ],
225 tagsAllOf: [ 'CCcc' ]
229 const body = await command.advancedVideoSearch({ search: query })
230 expect(body.total).to.equal(2)
234 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
235 expect(body.total).to.equal(0)
239 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
240 expect(body.total).to.equal(1)
244 it('Should search by category', async function () {
251 const body = await command.advancedVideoSearch({ search: query })
252 expect(body.total).to.equal(1)
253 expect(body.data[0].name).to.equal('6666 7777 8888')
257 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
258 expect(body.total).to.equal(0)
262 it('Should search by licence', async function () {
269 const body = await command.advancedVideoSearch({ search: query })
270 expect(body.total).to.equal(2)
271 expect(body.data[0].name).to.equal('3333 4444 5555')
272 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
276 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
277 expect(body.total).to.equal(0)
281 it('Should search by languages', async function () {
283 search: '1111 2222 3333',
284 languageOneOf: [ 'pl', 'en' ]
288 const body = await command.advancedVideoSearch({ search: query })
289 expect(body.total).to.equal(2)
290 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
291 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
295 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
296 expect(body.total).to.equal(3)
297 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
298 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
299 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
303 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
304 expect(body.total).to.equal(0)
308 it('Should search by start date', async function () {
310 search: '1111 2222 3333',
314 const body = await command.advancedVideoSearch({ search: query })
315 expect(body.total).to.equal(4)
317 const videos = body.data
318 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
319 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
320 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
321 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
324 it('Should make an advanced search', async function () {
326 search: '1111 2222 3333',
327 languageOneOf: [ 'pl', 'fr' ],
329 nsfw: 'false' as 'false',
330 licenceOneOf: [ 1, 4 ]
333 const body = await command.advancedVideoSearch({ search: query })
334 expect(body.total).to.equal(4)
336 const videos = body.data
337 expect(videos[0].name).to.equal('1111 2222 3333')
338 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
339 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
340 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
343 it('Should make an advanced search and sort results', async function () {
345 search: '1111 2222 3333',
346 languageOneOf: [ 'pl', 'fr' ],
348 nsfw: 'false' as 'false',
349 licenceOneOf: [ 1, 4 ],
353 const body = await command.advancedVideoSearch({ search: query })
354 expect(body.total).to.equal(4)
356 const videos = body.data
357 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
358 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
359 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
360 expect(videos[3].name).to.equal('1111 2222 3333')
363 it('Should make an advanced search and only show the first result', async function () {
365 search: '1111 2222 3333',
366 languageOneOf: [ 'pl', 'fr' ],
368 nsfw: 'false' as 'false',
369 licenceOneOf: [ 1, 4 ],
375 const body = await command.advancedVideoSearch({ search: query })
376 expect(body.total).to.equal(4)
378 const videos = body.data
379 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
382 it('Should make an advanced search and only show the last result', async function () {
384 search: '1111 2222 3333',
385 languageOneOf: [ 'pl', 'fr' ],
387 nsfw: 'false' as 'false',
388 licenceOneOf: [ 1, 4 ],
394 const body = await command.advancedVideoSearch({ search: query })
395 expect(body.total).to.equal(4)
397 const videos = body.data
398 expect(videos[0].name).to.equal('1111 2222 3333')
401 it('Should search on originally published date', async function () {
403 search: '1111 2222 3333',
404 languageOneOf: [ 'pl', 'fr' ],
406 nsfw: 'false' as 'false',
407 licenceOneOf: [ 1, 4 ]
411 const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }
412 const body = await command.advancedVideoSearch({ search: query })
414 expect(body.total).to.equal(1)
415 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
419 const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }
420 const body = await command.advancedVideoSearch({ search: query })
422 expect(body.total).to.equal(1)
423 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
427 const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }
428 const body = await command.advancedVideoSearch({ search: query })
430 expect(body.total).to.equal(0)
434 const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }
435 const body = await command.advancedVideoSearch({ search: query })
437 expect(body.total).to.equal(0)
443 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
444 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
446 const body = await command.advancedVideoSearch({ search: query })
448 expect(body.total).to.equal(0)
454 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
455 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
457 const body = await command.advancedVideoSearch({ search: query })
459 expect(body.total).to.equal(1)
460 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
464 it('Should search by UUID', async function () {
465 const search = videoUUID
466 const body = await command.advancedVideoSearch({ search: { search } })
468 expect(body.total).to.equal(1)
469 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
472 it('Should search by live', async function () {
478 searchIndex: { enabled: false }
480 live: { enabled: true }
482 await server.config.updateCustomSubConfig({ newConfig })
486 const body = await command.advancedVideoSearch({ search: { isLive: true } })
488 expect(body.total).to.equal(0)
489 expect(body.data).to.have.lengthOf(0)
493 const liveCommand = server.live
495 const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.store.channel.id }
496 const live = await liveCommand.create({ fields: liveAttributes })
498 const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id })
499 await liveCommand.waitUntilPublished({ videoId: live.id })
501 const body = await command.advancedVideoSearch({ search: { isLive: true } })
503 expect(body.total).to.equal(1)
504 expect(body.data[0].name).to.equal('live')
506 await stopFfmpeg(ffmpegCommand)
510 after(async function () {
511 await cleanupTests([ server ])