1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
6 VideoChannelsSearchQuery,
8 VideoPlaylistsSearchQuery,
11 } from '@shared/models'
12 import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/server-commands'
14 const expect = chai.expect
16 describe('Test index search', function () {
17 const localVideoName = 'local video' + new Date().toISOString()
19 let server: PeerTubeServer = null
20 let command: SearchCommand
22 before(async function () {
25 server = await createSingleServer(1)
27 await setAccessTokensToServers([ server ])
29 await server.videos.upload({ attributes: { name: localVideoName } })
31 command = server.search
34 describe('Default search', async function () {
36 it('Should make a local videos search by default', async function () {
39 await server.config.updateCustomSubConfig({
44 isDefaultSearch: false,
45 disableLocalSearch: false
51 const body = await command.searchVideos({ search: 'local video' })
53 expect(body.total).to.equal(1)
54 expect(body.data[0].name).to.equal(localVideoName)
57 it('Should make a local channels search by default', async function () {
58 const body = await command.searchChannels({ search: 'root' })
60 expect(body.total).to.equal(1)
61 expect(body.data[0].name).to.equal('root_channel')
62 expect(body.data[0].host).to.equal('localhost:' + server.port)
65 it('Should make an index videos search by default', async function () {
66 await server.config.updateCustomSubConfig({
71 isDefaultSearch: true,
72 disableLocalSearch: false
78 const body = await command.searchVideos({ search: 'local video' })
79 expect(body.total).to.be.greaterThan(2)
82 it('Should make an index channels search by default', async function () {
83 const body = await command.searchChannels({ search: 'root' })
84 expect(body.total).to.be.greaterThan(2)
87 it('Should make an index videos search if local search is disabled', async function () {
88 await server.config.updateCustomSubConfig({
93 isDefaultSearch: false,
94 disableLocalSearch: true
100 const body = await command.searchVideos({ search: 'local video' })
101 expect(body.total).to.be.greaterThan(2)
104 it('Should make an index channels search if local search is disabled', async function () {
105 const body = await command.searchChannels({ search: 'root' })
106 expect(body.total).to.be.greaterThan(2)
110 describe('Videos search', async function () {
112 async function check (search: VideosSearchQuery, exists = true) {
113 const body = await command.advancedVideoSearch({ search })
115 if (exists === false) {
116 expect(body.total).to.equal(0)
117 expect(body.data).to.have.lengthOf(0)
121 expect(body.total).to.equal(1)
122 expect(body.data).to.have.lengthOf(1)
124 const video = body.data[0]
126 expect(video.name).to.equal('What is PeerTube?')
127 expect(video.category.label).to.equal('Science & Technology')
128 expect(video.licence.label).to.equal('Attribution - Share Alike')
129 expect(video.privacy.label).to.equal('Public')
130 expect(video.duration).to.equal(113)
131 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
133 expect(video.account.host).to.equal('framatube.org')
134 expect(video.account.name).to.equal('framasoft')
135 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
136 // TODO: remove, deprecated in 4.2
137 expect(video.account.avatar).to.exist
138 expect(video.account.avatars.length).to.equal(2, 'Account should have one avatar image')
140 expect(video.channel.host).to.equal('framatube.org')
141 expect(video.channel.name).to.equal('joinpeertube')
142 expect(video.channel.url).to.equal('https://framatube.org/video-channels/joinpeertube')
143 // TODO: remove, deprecated in 4.2
144 expect(video.channel.avatar).to.exist
145 expect(video.channel.avatars.length).to.equal(2, 'Channel should have one avatar image')
148 const baseSearch: VideosSearchQuery = {
149 search: 'what is peertube',
152 categoryOneOf: [ 15 ],
154 tagsAllOf: [ 'framasoft', 'peertube' ],
155 startDate: '2018-10-01T10:50:46.396Z',
156 endDate: '2018-10-01T10:55:46.396Z'
159 it('Should make a simple search and not have results', async function () {
160 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
162 expect(body.total).to.equal(0)
163 expect(body.data).to.have.lengthOf(0)
166 it('Should make a simple search and have results', async function () {
167 const body = await command.searchVideos({ search: 'What is PeerTube' })
169 expect(body.total).to.be.greaterThan(1)
172 it('Should make a simple search', async function () {
173 await check(baseSearch)
176 it('Should search by start date', async function () {
177 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
178 await check(search, false)
181 it('Should search by tags', async function () {
182 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
183 await check(search, false)
186 it('Should search by duration', async function () {
187 const search = { ...baseSearch, durationMin: 2000 }
188 await check(search, false)
191 it('Should search by nsfw attribute', async function () {
193 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
194 await check(search, false)
198 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
199 await check(search, true)
203 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
204 await check(search, true)
208 it('Should search by host', async function () {
210 const search = { ...baseSearch, host: 'example.com' }
211 await check(search, false)
215 const search = { ...baseSearch, host: 'framatube.org' }
216 await check(search, true)
220 it('Should search by uuids', async function () {
221 const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d'
222 const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv'
223 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
224 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
227 const uuidsMatrix = [
229 [ goodUUID, badShortUUID ],
230 [ badShortUUID, goodShortUUID ],
231 [ goodUUID, goodShortUUID ]
234 for (const uuids of uuidsMatrix) {
235 const search = { ...baseSearch, uuids }
236 await check(search, true)
241 const uuidsMatrix = [
246 for (const uuids of uuidsMatrix) {
247 const search = { ...baseSearch, uuids }
248 await check(search, false)
253 it('Should have a correct pagination', async function () {
260 const body = await command.advancedVideoSearch({ search })
262 expect(body.total).to.be.greaterThan(5)
263 expect(body.data).to.have.lengthOf(5)
266 it('Should use the nsfw instance policy as default', async function () {
270 await server.config.updateCustomSubConfig({
272 instance: { defaultNSFWPolicy: 'display' }
276 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
277 expect(body.data).to.have.length.greaterThan(0)
279 const video = body.data[0]
280 expect(video.nsfw).to.be.true
282 nsfwUUID = video.uuid
286 await server.config.updateCustomSubConfig({
288 instance: { defaultNSFWPolicy: 'do_not_list' }
292 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
295 expect(body.data).to.have.lengthOf(0)
297 const video = body.data[0]
299 expect(video.uuid).not.equal(nsfwUUID)
305 describe('Channels search', async function () {
307 async function check (search: VideoChannelsSearchQuery, exists = true) {
308 const body = await command.advancedChannelSearch({ search })
310 if (exists === false) {
311 expect(body.total).to.equal(0)
312 expect(body.data).to.have.lengthOf(0)
316 expect(body.total).to.be.greaterThan(0)
317 expect(body.data).to.have.length.greaterThan(0)
319 const videoChannel = body.data[0]
320 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
321 expect(videoChannel.host).to.equal('framatube.org')
322 // TODO: remove, deprecated in 4.2
323 expect(videoChannel.avatar).to.exist
324 expect(videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
325 expect(videoChannel.displayName).to.exist
327 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
328 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
329 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
330 // TODO: remove, deprecated in 4.2
331 expect(videoChannel.ownerAccount.avatar).to.exist
332 expect(videoChannel.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
335 it('Should make a simple search and not have results', async function () {
336 const body = await command.searchChannels({ search: 'a'.repeat(500) })
338 expect(body.total).to.equal(0)
339 expect(body.data).to.have.lengthOf(0)
342 it('Should make a search and have results', async function () {
343 await check({ search: 'Framasoft', sort: 'createdAt' }, true)
346 it('Should make host search and have appropriate results', async function () {
347 await check({ search: 'Framasoft videos', host: 'example.com' }, false)
348 await check({ search: 'Framasoft videos', host: 'framatube.org' }, true)
351 it('Should make handles search and have appropriate results', async function () {
352 await check({ handles: [ 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
353 await check({ handles: [ 'jeanine', 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
354 await check({ handles: [ 'jeanine', 'chocobozzz_channel2@peertube2.cpy.re' ] }, false)
357 it('Should have a correct pagination', async function () {
358 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
360 expect(body.total).to.be.greaterThan(2)
361 expect(body.data).to.have.lengthOf(2)
365 describe('Playlists search', async function () {
367 async function check (search: VideoPlaylistsSearchQuery, exists = true) {
368 const body = await command.advancedPlaylistSearch({ search })
370 if (exists === false) {
371 expect(body.total).to.equal(0)
372 expect(body.data).to.have.lengthOf(0)
376 expect(body.total).to.be.greaterThan(0)
377 expect(body.data).to.have.length.greaterThan(0)
379 const videoPlaylist = body.data[0]
381 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
382 expect(videoPlaylist.thumbnailUrl).to.exist
383 expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
385 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
386 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
387 expect(videoPlaylist.videosLength).to.exist
389 expect(videoPlaylist.createdAt).to.exist
390 expect(videoPlaylist.updatedAt).to.exist
392 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
393 expect(videoPlaylist.displayName).to.exist
395 expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz')
396 expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz')
397 expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re')
398 // TODO: remove, deprecated in 4.2
399 expect(videoPlaylist.ownerAccount.avatar).to.exist
400 expect(videoPlaylist.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
402 expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel')
403 expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
404 expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
405 // TODO: remove, deprecated in 4.2
406 expect(videoPlaylist.videoChannel.avatar).to.exist
407 expect(videoPlaylist.videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
410 it('Should make a simple search and not have results', async function () {
411 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
413 expect(body.total).to.equal(0)
414 expect(body.data).to.have.lengthOf(0)
417 it('Should make a search and have results', async function () {
418 await check({ search: 'E2E playlist', sort: '-match' }, true)
421 it('Should make host search and have appropriate results', async function () {
422 await check({ search: 'E2E playlist', host: 'example.com' }, false)
423 await check({ search: 'E2E playlist', host: 'peertube2.cpy.re', sort: '-match' }, true)
426 it('Should make a search by uuids and have appropriate results', async function () {
427 const goodUUID = '73804a40-da9a-40c2-b1eb-2c6d9eec8f0a'
428 const goodShortUUID = 'fgei1ws1oa6FCaJ2qZPG29'
429 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
430 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
433 const uuidsMatrix = [
435 [ goodUUID, badShortUUID ],
436 [ badShortUUID, goodShortUUID ],
437 [ goodUUID, goodShortUUID ]
440 for (const uuids of uuidsMatrix) {
441 const search = { search: 'E2E playlist', sort: '-match', uuids }
442 await check(search, true)
447 const uuidsMatrix = [
452 for (const uuids of uuidsMatrix) {
453 const search = { search: 'E2E playlist', sort: '-match', uuids }
454 await check(search, false)
459 it('Should have a correct pagination', async function () {
460 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
462 expect(body.total).to.be.greaterThan(2)
463 expect(body.data).to.have.lengthOf(2)
467 after(async function () {
468 await cleanupTests([ server ])