1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
12 updateCustomSubConfig,
14 } from '@shared/extra-utils'
15 import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
17 const expect = chai.expect
19 describe('Test videos search', function () {
20 const localVideoName = 'local video' + new Date().toISOString()
22 let server: ServerInfo = null
23 let command: SearchCommand
25 before(async function () {
28 server = await flushAndRunServer(1)
30 await setAccessTokensToServers([ server ])
32 await uploadVideo(server.url, server.accessToken, { name: localVideoName })
34 command = server.searchCommand
37 describe('Default search', async function () {
39 it('Should make a local videos search by default', async function () {
42 await updateCustomSubConfig(server.url, server.accessToken, {
46 isDefaultSearch: false,
47 disableLocalSearch: false
52 const body = await command.searchVideos({ search: 'local video' })
54 expect(body.total).to.equal(1)
55 expect(body.data[0].name).to.equal(localVideoName)
58 it('Should make a local channels search by default', async function () {
59 const body = await command.searchChannels({ search: 'root' })
61 expect(body.total).to.equal(1)
62 expect(body.data[0].name).to.equal('root_channel')
63 expect(body.data[0].host).to.equal('localhost:' + server.port)
66 it('Should make an index videos search by default', async function () {
67 await updateCustomSubConfig(server.url, server.accessToken, {
71 isDefaultSearch: true,
72 disableLocalSearch: false
77 const body = await command.searchVideos({ search: 'local video' })
78 expect(body.total).to.be.greaterThan(2)
81 it('Should make an index channels search by default', async function () {
82 const body = await command.searchChannels({ search: 'root' })
83 expect(body.total).to.be.greaterThan(2)
86 it('Should make an index videos search if local search is disabled', async function () {
87 await updateCustomSubConfig(server.url, server.accessToken, {
91 isDefaultSearch: false,
92 disableLocalSearch: true
97 const body = await command.searchVideos({ search: 'local video' })
98 expect(body.total).to.be.greaterThan(2)
101 it('Should make an index channels search if local search is disabled', async function () {
102 const body = await command.searchChannels({ search: 'root' })
103 expect(body.total).to.be.greaterThan(2)
107 describe('Videos search', async function () {
109 it('Should make a simple search and not have results', async function () {
110 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
112 expect(body.total).to.equal(0)
113 expect(body.data).to.have.lengthOf(0)
116 it('Should make a simple search and have results', async function () {
117 const body = await command.searchVideos({ search: 'What is PeerTube' })
119 expect(body.total).to.be.greaterThan(1)
122 it('Should make a complex search', async function () {
124 async function check (search: VideosSearchQuery, exists = true) {
125 const body = await command.advancedVideoSearch({ search })
127 if (exists === false) {
128 expect(body.total).to.equal(0)
129 expect(body.data).to.have.lengthOf(0)
133 expect(body.total).to.equal(1)
134 expect(body.data).to.have.lengthOf(1)
136 const video = body.data[0]
138 expect(video.name).to.equal('What is PeerTube?')
139 expect(video.category.label).to.equal('Science & Technology')
140 expect(video.licence.label).to.equal('Attribution - Share Alike')
141 expect(video.privacy.label).to.equal('Public')
142 expect(video.duration).to.equal(113)
143 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
145 expect(video.account.host).to.equal('framatube.org')
146 expect(video.account.name).to.equal('framasoft')
147 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
148 expect(video.account.avatar).to.exist
150 expect(video.channel.host).to.equal('framatube.org')
151 expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8')
152 expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
153 expect(video.channel.avatar).to.exist
156 const baseSearch: VideosSearchQuery = {
157 search: 'what is peertube',
160 categoryOneOf: [ 15 ],
162 tagsAllOf: [ 'framasoft', 'peertube' ],
163 startDate: '2018-10-01T10:50:46.396Z',
164 endDate: '2018-10-01T10:55:46.396Z'
168 await check(baseSearch)
172 const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' })
173 await check(search, false)
177 const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] })
178 await check(search, false)
182 const search = immutableAssign(baseSearch, { durationMin: 2000 })
183 await check(search, false)
187 const search = immutableAssign(baseSearch, { nsfw: 'true' })
188 await check(search, false)
192 const search = immutableAssign(baseSearch, { nsfw: 'false' })
193 await check(search, true)
197 const search = immutableAssign(baseSearch, { nsfw: 'both' })
198 await check(search, true)
202 it('Should have a correct pagination', async function () {
209 const body = await command.advancedVideoSearch({ search })
211 expect(body.total).to.be.greaterThan(5)
212 expect(body.data).to.have.lengthOf(5)
215 it('Should use the nsfw instance policy as default', async function () {
219 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } })
221 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
222 expect(body.data).to.have.length.greaterThan(0)
224 const video = body.data[0]
225 expect(video.nsfw).to.be.true
227 nsfwUUID = video.uuid
231 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } })
233 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
236 expect(body.data).to.have.lengthOf(0)
238 const video = body.data[0]
240 expect(video.uuid).not.equal(nsfwUUID)
246 describe('Channels search', async function () {
248 it('Should make a simple search and not have results', async function () {
249 const body = await command.searchChannels({ search: 'a'.repeat(500) })
251 expect(body.total).to.equal(0)
252 expect(body.data).to.have.lengthOf(0)
255 it('Should make a search and have results', async function () {
256 const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } })
258 expect(body.total).to.be.greaterThan(0)
259 expect(body.data).to.have.length.greaterThan(0)
261 const videoChannel = body.data[0]
262 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
263 expect(videoChannel.host).to.equal('framatube.org')
264 expect(videoChannel.avatar).to.exist
265 expect(videoChannel.displayName).to.exist
267 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
268 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
269 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
270 expect(videoChannel.ownerAccount.avatar).to.exist
273 it('Should have a correct pagination', async function () {
274 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
276 expect(body.total).to.be.greaterThan(2)
277 expect(body.data).to.have.lengthOf(2)
281 describe('Playlists search', async function () {
283 it('Should make a simple search and not have results', async function () {
284 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
286 expect(body.total).to.equal(0)
287 expect(body.data).to.have.lengthOf(0)
290 it('Should make a search and have results', async function () {
291 const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } })
293 expect(body.total).to.be.greaterThan(0)
294 expect(body.data).to.have.length.greaterThan(0)
296 const videoPlaylist = body.data[0]
298 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
299 expect(videoPlaylist.thumbnailUrl).to.exist
300 expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
302 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
303 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
304 expect(videoPlaylist.videosLength).to.exist
306 expect(videoPlaylist.createdAt).to.exist
307 expect(videoPlaylist.updatedAt).to.exist
309 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
310 expect(videoPlaylist.displayName).to.exist
312 expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz')
313 expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz')
314 expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re')
315 expect(videoPlaylist.ownerAccount.avatar).to.exist
317 expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel')
318 expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
319 expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
320 expect(videoPlaylist.videoChannel.avatar).to.exist
323 it('Should have a correct pagination', async function () {
324 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
326 expect(body.total).to.be.greaterThan(2)
327 expect(body.data).to.have.lengthOf(2)
331 after(async function () {
332 await cleanupTests([ server ])