1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { advancedVideoChannelSearch, searchVideoChannel } from '@shared/extra-utils/search/video-channels'
6 import { Video, VideoChannel, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
8 advancedVideoPlaylistSearch,
16 setAccessTokensToServers,
17 updateCustomSubConfig,
19 } from '../../../../shared/extra-utils'
21 const expect = chai.expect
23 describe('Test videos search', function () {
24 let server: ServerInfo = null
25 const localVideoName = 'local video' + new Date().toISOString()
27 before(async function () {
30 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
34 await uploadVideo(server.url, server.accessToken, { name: localVideoName })
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 res = await searchVideo(server.url, 'local video')
54 expect(res.body.total).to.equal(1)
55 expect(res.body.data[0].name).to.equal(localVideoName)
58 it('Should make a local channels search by default', async function () {
59 const res = await searchVideoChannel(server.url, 'root')
61 expect(res.body.total).to.equal(1)
62 expect(res.body.data[0].name).to.equal('root_channel')
63 expect(res.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 res = await searchVideo(server.url, 'local video')
78 expect(res.body.total).to.be.greaterThan(2)
81 it('Should make an index channels search by default', async function () {
82 const res = await searchVideoChannel(server.url, 'root')
83 expect(res.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 res = await searchVideo(server.url, 'local video')
98 expect(res.body.total).to.be.greaterThan(2)
101 it('Should make an index channels search if local search is disabled', async function () {
102 const res = await searchVideoChannel(server.url, 'root')
103 expect(res.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 res = await searchVideo(server.url, 'djidane'.repeat(50))
112 expect(res.body.total).to.equal(0)
113 expect(res.body.data).to.have.lengthOf(0)
116 it('Should make a simple search and have results', async function () {
117 const res = await searchVideo(server.url, 'What is PeerTube')
119 expect(res.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 res = await advancedVideosSearch(server.url, search)
127 if (exists === false) {
128 expect(res.body.total).to.equal(0)
129 expect(res.body.data).to.have.lengthOf(0)
133 expect(res.body.total).to.equal(1)
134 expect(res.body.data).to.have.lengthOf(1)
136 const video: Video = res.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 res = await advancedVideosSearch(server.url, search)
211 expect(res.body.total).to.be.greaterThan(5)
212 expect(res.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 res = await searchVideo(server.url, 'NSFW search index', '-match')
222 const video = res.body.data[0] as Video
224 expect(res.body.data).to.have.length.greaterThan(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 res = await searchVideo(server.url, 'NSFW search index', '-match')
236 expect(res.body.data).to.have.lengthOf(0)
239 const video = res.body.data[0] as Video
241 expect(video.uuid).not.equal(nsfwUUID)
247 describe('Channels search', async function () {
249 it('Should make a simple search and not have results', async function () {
250 const res = await searchVideoChannel(server.url, 'a'.repeat(500))
252 expect(res.body.total).to.equal(0)
253 expect(res.body.data).to.have.lengthOf(0)
256 it('Should make a search and have results', async function () {
257 const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' })
259 expect(res.body.total).to.be.greaterThan(0)
260 expect(res.body.data).to.have.length.greaterThan(0)
262 const videoChannel: VideoChannel = res.body.data[0]
263 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
264 expect(videoChannel.host).to.equal('framatube.org')
265 expect(videoChannel.avatar).to.exist
266 expect(videoChannel.displayName).to.exist
268 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
269 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
270 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
271 expect(videoChannel.ownerAccount.avatar).to.exist
274 it('Should have a correct pagination', async function () {
275 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 })
277 expect(res.body.total).to.be.greaterThan(2)
278 expect(res.body.data).to.have.lengthOf(2)
282 describe('Playlists search', async function () {
284 it('Should make a simple search and not have results', async function () {
285 const res = await searchVideoPlaylists(server.url, 'a'.repeat(500))
287 expect(res.body.total).to.equal(0)
288 expect(res.body.data).to.have.lengthOf(0)
291 it('Should make a search and have results', async function () {
292 const res = await advancedVideoPlaylistSearch(server.url, { search: 'E2E playlist', sort: '-match' })
294 expect(res.body.total).to.be.greaterThan(0)
295 expect(res.body.data).to.have.length.greaterThan(0)
297 const videoPlaylist: VideoPlaylist = res.body.data[0]
299 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
300 expect(videoPlaylist.thumbnailUrl).to.exist
301 expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
303 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
304 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
305 expect(videoPlaylist.videosLength).to.exist
307 expect(videoPlaylist.createdAt).to.exist
308 expect(videoPlaylist.updatedAt).to.exist
310 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
311 expect(videoPlaylist.displayName).to.exist
313 expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz')
314 expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz')
315 expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re')
316 expect(videoPlaylist.ownerAccount.avatar).to.exist
318 expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel')
319 expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
320 expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
321 expect(videoPlaylist.videoChannel.avatar).to.exist
324 it('Should have a correct pagination', async function () {
325 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 })
327 expect(res.body.total).to.be.greaterThan(2)
328 expect(res.body.data).to.have.lengthOf(2)
332 after(async function () {
333 await cleanupTests([ server ])