1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
13 } from '@shared/extra-utils'
14 import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
16 const expect = chai.expect
18 describe('Test videos search', function () {
19 const localVideoName = 'local video' + new Date().toISOString()
21 let server: ServerInfo = null
22 let command: SearchCommand
24 before(async function () {
27 server = await flushAndRunServer(1)
29 await setAccessTokensToServers([ server ])
31 await uploadVideo(server.url, server.accessToken, { name: localVideoName })
33 command = server.searchCommand
36 describe('Default search', async function () {
38 it('Should make a local videos search by default', async function () {
41 await server.configCommand.updateCustomSubConfig({
46 isDefaultSearch: false,
47 disableLocalSearch: false
53 const body = await command.searchVideos({ search: 'local video' })
55 expect(body.total).to.equal(1)
56 expect(body.data[0].name).to.equal(localVideoName)
59 it('Should make a local channels search by default', async function () {
60 const body = await command.searchChannels({ search: 'root' })
62 expect(body.total).to.equal(1)
63 expect(body.data[0].name).to.equal('root_channel')
64 expect(body.data[0].host).to.equal('localhost:' + server.port)
67 it('Should make an index videos search by default', async function () {
68 await server.configCommand.updateCustomSubConfig({
73 isDefaultSearch: true,
74 disableLocalSearch: false
80 const body = await command.searchVideos({ search: 'local video' })
81 expect(body.total).to.be.greaterThan(2)
84 it('Should make an index channels search by default', async function () {
85 const body = await command.searchChannels({ search: 'root' })
86 expect(body.total).to.be.greaterThan(2)
89 it('Should make an index videos search if local search is disabled', async function () {
90 await server.configCommand.updateCustomSubConfig({
95 isDefaultSearch: false,
96 disableLocalSearch: true
102 const body = await command.searchVideos({ search: 'local video' })
103 expect(body.total).to.be.greaterThan(2)
106 it('Should make an index channels search if local search is disabled', async function () {
107 const body = await command.searchChannels({ search: 'root' })
108 expect(body.total).to.be.greaterThan(2)
112 describe('Videos search', async function () {
114 it('Should make a simple search and not have results', async function () {
115 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
117 expect(body.total).to.equal(0)
118 expect(body.data).to.have.lengthOf(0)
121 it('Should make a simple search and have results', async function () {
122 const body = await command.searchVideos({ search: 'What is PeerTube' })
124 expect(body.total).to.be.greaterThan(1)
127 it('Should make a complex search', async function () {
129 async function check (search: VideosSearchQuery, exists = true) {
130 const body = await command.advancedVideoSearch({ search })
132 if (exists === false) {
133 expect(body.total).to.equal(0)
134 expect(body.data).to.have.lengthOf(0)
138 expect(body.total).to.equal(1)
139 expect(body.data).to.have.lengthOf(1)
141 const video = body.data[0]
143 expect(video.name).to.equal('What is PeerTube?')
144 expect(video.category.label).to.equal('Science & Technology')
145 expect(video.licence.label).to.equal('Attribution - Share Alike')
146 expect(video.privacy.label).to.equal('Public')
147 expect(video.duration).to.equal(113)
148 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
150 expect(video.account.host).to.equal('framatube.org')
151 expect(video.account.name).to.equal('framasoft')
152 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
153 expect(video.account.avatar).to.exist
155 expect(video.channel.host).to.equal('framatube.org')
156 expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8')
157 expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
158 expect(video.channel.avatar).to.exist
161 const baseSearch: VideosSearchQuery = {
162 search: 'what is peertube',
165 categoryOneOf: [ 15 ],
167 tagsAllOf: [ 'framasoft', 'peertube' ],
168 startDate: '2018-10-01T10:50:46.396Z',
169 endDate: '2018-10-01T10:55:46.396Z'
173 await check(baseSearch)
177 const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' })
178 await check(search, false)
182 const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] })
183 await check(search, false)
187 const search = immutableAssign(baseSearch, { durationMin: 2000 })
188 await check(search, false)
192 const search = immutableAssign(baseSearch, { nsfw: 'true' })
193 await check(search, false)
197 const search = immutableAssign(baseSearch, { nsfw: 'false' })
198 await check(search, true)
202 const search = immutableAssign(baseSearch, { nsfw: 'both' })
203 await check(search, true)
207 it('Should have a correct pagination', async function () {
214 const body = await command.advancedVideoSearch({ search })
216 expect(body.total).to.be.greaterThan(5)
217 expect(body.data).to.have.lengthOf(5)
220 it('Should use the nsfw instance policy as default', async function () {
224 await server.configCommand.updateCustomSubConfig({
226 instance: { defaultNSFWPolicy: 'display' }
230 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
231 expect(body.data).to.have.length.greaterThan(0)
233 const video = body.data[0]
234 expect(video.nsfw).to.be.true
236 nsfwUUID = video.uuid
240 await server.configCommand.updateCustomSubConfig({
242 instance: { defaultNSFWPolicy: 'do_not_list' }
246 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
249 expect(body.data).to.have.lengthOf(0)
251 const video = body.data[0]
253 expect(video.uuid).not.equal(nsfwUUID)
259 describe('Channels search', async function () {
261 it('Should make a simple search and not have results', async function () {
262 const body = await command.searchChannels({ search: 'a'.repeat(500) })
264 expect(body.total).to.equal(0)
265 expect(body.data).to.have.lengthOf(0)
268 it('Should make a search and have results', async function () {
269 const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } })
271 expect(body.total).to.be.greaterThan(0)
272 expect(body.data).to.have.length.greaterThan(0)
274 const videoChannel = body.data[0]
275 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
276 expect(videoChannel.host).to.equal('framatube.org')
277 expect(videoChannel.avatar).to.exist
278 expect(videoChannel.displayName).to.exist
280 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
281 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
282 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
283 expect(videoChannel.ownerAccount.avatar).to.exist
286 it('Should have a correct pagination', async function () {
287 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
289 expect(body.total).to.be.greaterThan(2)
290 expect(body.data).to.have.lengthOf(2)
294 describe('Playlists search', async function () {
296 it('Should make a simple search and not have results', async function () {
297 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
299 expect(body.total).to.equal(0)
300 expect(body.data).to.have.lengthOf(0)
303 it('Should make a search and have results', async function () {
304 const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } })
306 expect(body.total).to.be.greaterThan(0)
307 expect(body.data).to.have.length.greaterThan(0)
309 const videoPlaylist = body.data[0]
311 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
312 expect(videoPlaylist.thumbnailUrl).to.exist
313 expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
315 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
316 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
317 expect(videoPlaylist.videosLength).to.exist
319 expect(videoPlaylist.createdAt).to.exist
320 expect(videoPlaylist.updatedAt).to.exist
322 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
323 expect(videoPlaylist.displayName).to.exist
325 expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz')
326 expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz')
327 expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re')
328 expect(videoPlaylist.ownerAccount.avatar).to.exist
330 expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel')
331 expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
332 expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
333 expect(videoPlaylist.videoChannel.avatar).to.exist
336 it('Should have a correct pagination', async function () {
337 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
339 expect(body.total).to.be.greaterThan(2)
340 expect(body.data).to.have.lengthOf(2)
344 after(async function () {
345 await cleanupTests([ server ])