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 () {
37 await server.config.updateCustomSubConfig({
42 isDefaultSearch: false,
43 disableLocalSearch: false
49 const body = await command.searchVideos({ search: 'local video' })
51 expect(body.total).to.equal(1)
52 expect(body.data[0].name).to.equal(localVideoName)
55 it('Should make a local channels search by default', async function () {
56 const body = await command.searchChannels({ search: 'root' })
58 expect(body.total).to.equal(1)
59 expect(body.data[0].name).to.equal('root_channel')
60 expect(body.data[0].host).to.equal(server.host)
63 it('Should make an index videos search by default', async function () {
64 await server.config.updateCustomSubConfig({
69 isDefaultSearch: true,
70 disableLocalSearch: false
76 const body = await command.searchVideos({ search: 'local video' })
77 expect(body.total).to.be.greaterThan(2)
80 it('Should make an index channels search by default', async function () {
81 const body = await command.searchChannels({ search: 'root' })
82 expect(body.total).to.be.greaterThan(2)
86 describe('Videos search', async function () {
88 async function check (search: VideosSearchQuery, exists = true) {
89 const body = await command.advancedVideoSearch({ search })
91 if (exists === false) {
92 expect(body.total).to.equal(0)
93 expect(body.data).to.have.lengthOf(0)
97 expect(body.total).to.equal(1)
98 expect(body.data).to.have.lengthOf(1)
100 const video = body.data[0]
102 expect(video.name).to.equal('What is PeerTube?')
103 expect(video.category.label).to.equal('Science & Technology')
104 expect(video.licence.label).to.equal('Attribution - Share Alike')
105 expect(video.privacy.label).to.equal('Public')
106 expect(video.duration).to.equal(113)
107 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
109 expect(video.account.host).to.equal('framatube.org')
110 expect(video.account.name).to.equal('framasoft')
111 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
112 // TODO: remove, deprecated in 4.2
113 expect(video.account.avatar).to.exist
114 expect(video.account.avatars.length).to.equal(2, 'Account should have one avatar image')
116 expect(video.channel.host).to.equal('framatube.org')
117 expect(video.channel.name).to.equal('joinpeertube')
118 expect(video.channel.url).to.equal('https://framatube.org/video-channels/joinpeertube')
119 // TODO: remove, deprecated in 4.2
120 expect(video.channel.avatar).to.exist
121 expect(video.channel.avatars.length).to.equal(2, 'Channel should have one avatar image')
124 const baseSearch: VideosSearchQuery = {
125 search: 'what is peertube',
128 categoryOneOf: [ 15 ],
130 tagsAllOf: [ 'framasoft', 'peertube' ],
131 startDate: '2018-10-01T10:50:46.396Z',
132 endDate: '2018-10-01T10:55:46.396Z'
135 it('Should make a simple search and not have results', async function () {
136 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
138 expect(body.total).to.equal(0)
139 expect(body.data).to.have.lengthOf(0)
142 it('Should make a simple search and have results', async function () {
143 const body = await command.searchVideos({ search: 'What is PeerTube' })
145 expect(body.total).to.be.greaterThan(1)
148 it('Should make a simple search', async function () {
149 await check(baseSearch)
152 it('Should search by start date', async function () {
153 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
154 await check(search, false)
157 it('Should search by tags', async function () {
158 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
159 await check(search, false)
162 it('Should search by duration', async function () {
163 const search = { ...baseSearch, durationMin: 2000 }
164 await check(search, false)
167 it('Should search by nsfw attribute', async function () {
169 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
170 await check(search, false)
174 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
175 await check(search, true)
179 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
180 await check(search, true)
184 it('Should search by host', async function () {
186 const search = { ...baseSearch, host: 'example.com' }
187 await check(search, false)
191 const search = { ...baseSearch, host: 'framatube.org' }
192 await check(search, true)
196 it('Should search by uuids', async function () {
197 const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d'
198 const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv'
199 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
200 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
203 const uuidsMatrix = [
205 [ goodUUID, badShortUUID ],
206 [ badShortUUID, goodShortUUID ],
207 [ goodUUID, goodShortUUID ]
210 for (const uuids of uuidsMatrix) {
211 const search = { ...baseSearch, uuids }
212 await check(search, true)
217 const uuidsMatrix = [
222 for (const uuids of uuidsMatrix) {
223 const search = { ...baseSearch, uuids }
224 await check(search, false)
229 it('Should have a correct pagination', async function () {
236 const body = await command.advancedVideoSearch({ search })
238 expect(body.total).to.be.greaterThan(5)
239 expect(body.data).to.have.lengthOf(5)
242 it('Should use the nsfw instance policy as default', async function () {
246 await server.config.updateCustomSubConfig({
248 instance: { defaultNSFWPolicy: 'display' }
252 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
253 expect(body.data).to.have.length.greaterThan(0)
255 const video = body.data[0]
256 expect(video.nsfw).to.be.true
258 nsfwUUID = video.uuid
262 await server.config.updateCustomSubConfig({
264 instance: { defaultNSFWPolicy: 'do_not_list' }
268 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
271 expect(body.data).to.have.lengthOf(0)
273 const video = body.data[0]
275 expect(video.uuid).not.equal(nsfwUUID)
281 describe('Channels search', async function () {
283 async function check (search: VideoChannelsSearchQuery, exists = true) {
284 const body = await command.advancedChannelSearch({ search })
286 if (exists === false) {
287 expect(body.total).to.equal(0)
288 expect(body.data).to.have.lengthOf(0)
292 expect(body.total).to.be.greaterThan(0)
293 expect(body.data).to.have.length.greaterThan(0)
295 const videoChannel = body.data[0]
296 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
297 expect(videoChannel.host).to.equal('framatube.org')
298 // TODO: remove, deprecated in 4.2
299 expect(videoChannel.avatar).to.exist
300 expect(videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
301 expect(videoChannel.displayName).to.exist
303 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
304 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
305 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
306 // TODO: remove, deprecated in 4.2
307 expect(videoChannel.ownerAccount.avatar).to.exist
308 expect(videoChannel.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
311 it('Should make a simple search and not have results', async function () {
312 const body = await command.searchChannels({ search: 'a'.repeat(500) })
314 expect(body.total).to.equal(0)
315 expect(body.data).to.have.lengthOf(0)
318 it('Should make a search and have results', async function () {
319 await check({ search: 'Framasoft', sort: 'createdAt' }, true)
322 it('Should make host search and have appropriate results', async function () {
323 await check({ search: 'Framasoft videos', host: 'example.com' }, false)
324 await check({ search: 'Framasoft videos', host: 'framatube.org' }, true)
327 it('Should make handles search and have appropriate results', async function () {
328 await check({ handles: [ 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
329 await check({ handles: [ 'jeanine', 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
330 await check({ handles: [ 'jeanine', 'chocobozzz_channel2@peertube2.cpy.re' ] }, false)
333 it('Should have a correct pagination', async function () {
334 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
336 expect(body.total).to.be.greaterThan(2)
337 expect(body.data).to.have.lengthOf(2)
341 describe('Playlists search', async function () {
343 async function check (search: VideoPlaylistsSearchQuery, exists = true) {
344 const body = await command.advancedPlaylistSearch({ search })
346 if (exists === false) {
347 expect(body.total).to.equal(0)
348 expect(body.data).to.have.lengthOf(0)
352 expect(body.total).to.be.greaterThan(0)
353 expect(body.data).to.have.length.greaterThan(0)
355 const videoPlaylist = body.data[0]
357 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
358 expect(videoPlaylist.thumbnailUrl).to.exist
359 expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
361 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
362 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
363 expect(videoPlaylist.videosLength).to.exist
365 expect(videoPlaylist.createdAt).to.exist
366 expect(videoPlaylist.updatedAt).to.exist
368 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
369 expect(videoPlaylist.displayName).to.exist
371 expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz')
372 expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz')
373 expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re')
374 // TODO: remove, deprecated in 4.2
375 expect(videoPlaylist.ownerAccount.avatar).to.exist
376 expect(videoPlaylist.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
378 expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel')
379 expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
380 expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
381 // TODO: remove, deprecated in 4.2
382 expect(videoPlaylist.videoChannel.avatar).to.exist
383 expect(videoPlaylist.videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
386 it('Should make a simple search and not have results', async function () {
387 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
389 expect(body.total).to.equal(0)
390 expect(body.data).to.have.lengthOf(0)
393 it('Should make a search and have results', async function () {
394 await check({ search: 'E2E playlist', sort: '-match' }, true)
397 it('Should make host search and have appropriate results', async function () {
398 await check({ search: 'E2E playlist', host: 'example.com' }, false)
399 await check({ search: 'E2E playlist', host: 'peertube2.cpy.re', sort: '-match' }, true)
402 it('Should make a search by uuids and have appropriate results', async function () {
403 const goodUUID = '73804a40-da9a-40c2-b1eb-2c6d9eec8f0a'
404 const goodShortUUID = 'fgei1ws1oa6FCaJ2qZPG29'
405 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
406 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
409 const uuidsMatrix = [
411 [ goodUUID, badShortUUID ],
412 [ badShortUUID, goodShortUUID ],
413 [ goodUUID, goodShortUUID ]
416 for (const uuids of uuidsMatrix) {
417 const search = { search: 'E2E playlist', sort: '-match', uuids }
418 await check(search, true)
423 const uuidsMatrix = [
428 for (const uuids of uuidsMatrix) {
429 const search = { search: 'E2E playlist', sort: '-match', uuids }
430 await check(search, false)
435 it('Should have a correct pagination', async function () {
436 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
438 expect(body.total).to.be.greaterThan(2)
439 expect(body.data).to.have.lengthOf(2)
443 after(async function () {
444 await cleanupTests([ server ])