1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
6 VideoChannelsSearchQuery,
8 VideoPlaylistsSearchQuery,
11 } from '@shared/models'
12 import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/server-commands'
14 describe('Test index search', function () {
15 const localVideoName = 'local video' + new Date().toISOString()
17 let server: PeerTubeServer = null
18 let command: SearchCommand
20 before(async function () {
23 server = await createSingleServer(1)
25 await setAccessTokensToServers([ server ])
27 await server.videos.upload({ attributes: { name: localVideoName } })
29 command = server.search
32 describe('Default search', async function () {
34 it('Should make a local videos search by default', async function () {
35 await server.config.updateCustomSubConfig({
40 isDefaultSearch: false,
41 disableLocalSearch: false
47 const body = await command.searchVideos({ search: 'local video' })
49 expect(body.total).to.equal(1)
50 expect(body.data[0].name).to.equal(localVideoName)
53 it('Should make a local channels search by default', async function () {
54 const body = await command.searchChannels({ search: 'root' })
56 expect(body.total).to.equal(1)
57 expect(body.data[0].name).to.equal('root_channel')
58 expect(body.data[0].host).to.equal(server.host)
61 it('Should make an index videos search by default', async function () {
62 await server.config.updateCustomSubConfig({
67 isDefaultSearch: true,
68 disableLocalSearch: false
74 const body = await command.searchVideos({ search: 'local video' })
75 expect(body.total).to.be.greaterThan(2)
78 it('Should make an index channels search by default', async function () {
79 const body = await command.searchChannels({ search: 'root' })
80 expect(body.total).to.be.greaterThan(2)
84 describe('Videos search', async function () {
86 async function check (search: VideosSearchQuery, exists = true) {
87 const body = await command.advancedVideoSearch({ search })
89 if (exists === false) {
90 expect(body.total).to.equal(0)
91 expect(body.data).to.have.lengthOf(0)
95 expect(body.total).to.equal(1)
96 expect(body.data).to.have.lengthOf(1)
98 const video = body.data[0]
100 expect(video.name).to.equal('What is PeerTube?')
101 expect(video.category.label).to.equal('Science & Technology')
102 expect(video.licence.label).to.equal('Attribution - Share Alike')
103 expect(video.privacy.label).to.equal('Public')
104 expect(video.duration).to.equal(113)
105 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
107 expect(video.account.host).to.equal('framatube.org')
108 expect(video.account.name).to.equal('framasoft')
109 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
110 // TODO: remove, deprecated in 4.2
111 expect(video.account.avatar).to.exist
112 expect(video.account.avatars.length).to.equal(2, 'Account should have one avatar image')
114 expect(video.channel.host).to.equal('framatube.org')
115 expect(video.channel.name).to.equal('joinpeertube')
116 expect(video.channel.url).to.equal('https://framatube.org/video-channels/joinpeertube')
117 // TODO: remove, deprecated in 4.2
118 expect(video.channel.avatar).to.exist
119 expect(video.channel.avatars.length).to.equal(2, 'Channel should have one avatar image')
122 const baseSearch: VideosSearchQuery = {
123 search: 'what is peertube',
126 categoryOneOf: [ 15 ],
128 tagsAllOf: [ 'framasoft', 'peertube' ],
129 startDate: '2018-10-01T10:50:46.396Z',
130 endDate: '2018-10-01T10:55:46.396Z'
133 it('Should make a simple search and not have results', async function () {
134 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
136 expect(body.total).to.equal(0)
137 expect(body.data).to.have.lengthOf(0)
140 it('Should make a simple search and have results', async function () {
141 const body = await command.searchVideos({ search: 'What is PeerTube' })
143 expect(body.total).to.be.greaterThan(1)
146 it('Should make a simple search', async function () {
147 await check(baseSearch)
150 it('Should search by start date', async function () {
151 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
152 await check(search, false)
155 it('Should search by tags', async function () {
156 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
157 await check(search, false)
160 it('Should search by duration', async function () {
161 const search = { ...baseSearch, durationMin: 2000 }
162 await check(search, false)
165 it('Should search by nsfw attribute', async function () {
167 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
168 await check(search, false)
172 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
173 await check(search, true)
177 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
178 await check(search, true)
182 it('Should search by host', async function () {
184 const search = { ...baseSearch, host: 'example.com' }
185 await check(search, false)
189 const search = { ...baseSearch, host: 'framatube.org' }
190 await check(search, true)
194 it('Should search by uuids', async function () {
195 const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d'
196 const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv'
197 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
198 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
201 const uuidsMatrix = [
203 [ goodUUID, badShortUUID ],
204 [ badShortUUID, goodShortUUID ],
205 [ goodUUID, goodShortUUID ]
208 for (const uuids of uuidsMatrix) {
209 const search = { ...baseSearch, uuids }
210 await check(search, true)
215 const uuidsMatrix = [
220 for (const uuids of uuidsMatrix) {
221 const search = { ...baseSearch, uuids }
222 await check(search, false)
227 it('Should have a correct pagination', async function () {
234 const body = await command.advancedVideoSearch({ search })
236 expect(body.total).to.be.greaterThan(5)
237 expect(body.data).to.have.lengthOf(5)
240 it('Should use the nsfw instance policy as default', async function () {
244 await server.config.updateCustomSubConfig({
246 instance: { defaultNSFWPolicy: 'display' }
250 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
251 expect(body.data).to.have.length.greaterThan(0)
253 const video = body.data[0]
254 expect(video.nsfw).to.be.true
256 nsfwUUID = video.uuid
260 await server.config.updateCustomSubConfig({
262 instance: { defaultNSFWPolicy: 'do_not_list' }
266 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
269 expect(body.data).to.have.lengthOf(0)
271 const video = body.data[0]
273 expect(video.uuid).not.equal(nsfwUUID)
279 describe('Channels search', async function () {
281 async function check (search: VideoChannelsSearchQuery, exists = true) {
282 const body = await command.advancedChannelSearch({ search })
284 if (exists === false) {
285 expect(body.total).to.equal(0)
286 expect(body.data).to.have.lengthOf(0)
290 expect(body.total).to.be.greaterThan(0)
291 expect(body.data).to.have.length.greaterThan(0)
293 const videoChannel = body.data[0]
294 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
295 expect(videoChannel.host).to.equal('framatube.org')
296 // TODO: remove, deprecated in 4.2
297 expect(videoChannel.avatar).to.exist
298 expect(videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
299 expect(videoChannel.displayName).to.exist
301 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
302 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
303 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
304 // TODO: remove, deprecated in 4.2
305 expect(videoChannel.ownerAccount.avatar).to.exist
306 expect(videoChannel.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
309 it('Should make a simple search and not have results', async function () {
310 const body = await command.searchChannels({ search: 'a'.repeat(500) })
312 expect(body.total).to.equal(0)
313 expect(body.data).to.have.lengthOf(0)
316 it('Should make a search and have results', async function () {
317 await check({ search: 'Framasoft', sort: 'createdAt' }, true)
320 it('Should make host search and have appropriate results', async function () {
321 await check({ search: 'Framasoft videos', host: 'example.com' }, false)
322 await check({ search: 'Framasoft videos', host: 'framatube.org' }, true)
325 it('Should make handles search and have appropriate results', async function () {
326 await check({ handles: [ 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
327 await check({ handles: [ 'jeanine', 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
328 await check({ handles: [ 'jeanine', 'chocobozzz_channel2@peertube2.cpy.re' ] }, false)
331 it('Should have a correct pagination', async function () {
332 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
334 expect(body.total).to.be.greaterThan(2)
335 expect(body.data).to.have.lengthOf(2)
339 describe('Playlists search', async function () {
341 async function check (search: VideoPlaylistsSearchQuery, exists = true) {
342 const body = await command.advancedPlaylistSearch({ search })
344 if (exists === false) {
345 expect(body.total).to.equal(0)
346 expect(body.data).to.have.lengthOf(0)
350 expect(body.total).to.be.greaterThan(0)
351 expect(body.data).to.have.length.greaterThan(0)
353 const videoPlaylist = body.data[0]
355 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
356 expect(videoPlaylist.thumbnailUrl).to.exist
357 expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
359 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
360 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
361 expect(videoPlaylist.videosLength).to.exist
363 expect(videoPlaylist.createdAt).to.exist
364 expect(videoPlaylist.updatedAt).to.exist
366 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
367 expect(videoPlaylist.displayName).to.exist
369 expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz')
370 expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz')
371 expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re')
372 // TODO: remove, deprecated in 4.2
373 expect(videoPlaylist.ownerAccount.avatar).to.exist
374 expect(videoPlaylist.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
376 expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel')
377 expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
378 expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
379 // TODO: remove, deprecated in 4.2
380 expect(videoPlaylist.videoChannel.avatar).to.exist
381 expect(videoPlaylist.videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
384 it('Should make a simple search and not have results', async function () {
385 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
387 expect(body.total).to.equal(0)
388 expect(body.data).to.have.lengthOf(0)
391 it('Should make a search and have results', async function () {
392 await check({ search: 'E2E playlist', sort: '-match' }, true)
395 it('Should make host search and have appropriate results', async function () {
396 await check({ search: 'E2E playlist', host: 'example.com' }, false)
397 await check({ search: 'E2E playlist', host: 'peertube2.cpy.re', sort: '-match' }, true)
400 it('Should make a search by uuids and have appropriate results', async function () {
401 const goodUUID = '73804a40-da9a-40c2-b1eb-2c6d9eec8f0a'
402 const goodShortUUID = 'fgei1ws1oa6FCaJ2qZPG29'
403 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
404 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
407 const uuidsMatrix = [
409 [ goodUUID, badShortUUID ],
410 [ badShortUUID, goodShortUUID ],
411 [ goodUUID, goodShortUUID ]
414 for (const uuids of uuidsMatrix) {
415 const search = { search: 'E2E playlist', sort: '-match', uuids }
416 await check(search, true)
421 const uuidsMatrix = [
426 for (const uuids of uuidsMatrix) {
427 const search = { search: 'E2E playlist', sort: '-match', uuids }
428 await check(search, false)
433 it('Should have a correct pagination', async function () {
434 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
436 expect(body.total).to.be.greaterThan(2)
437 expect(body.data).to.have.lengthOf(2)
441 after(async function () {
442 await cleanupTests([ server ])