1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 setAccessTokensToServers,
11 updateCustomSubConfig,
15 } from '../../../../shared/extra-utils'
16 import { searchVideoChannel, advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels'
17 import { VideosSearchQuery, Video, VideoChannel } from '@shared/models'
19 const expect = chai.expect
21 describe('Test videos search', function () {
22 let server: ServerInfo = null
23 const localVideoName = 'local video' + new Date().toISOString()
25 before(async function () {
28 server = await flushAndRunServer(1)
30 await setAccessTokensToServers([ server ])
32 await uploadVideo(server.url, server.accessToken, { name: localVideoName })
35 describe('Default search', async function () {
37 it('Should make a local videos search by default', async function () {
40 await updateCustomSubConfig(server.url, server.accessToken, {
44 isDefaultSearch: false,
45 disableLocalSearch: false
50 const res = await searchVideo(server.url, 'local video')
52 expect(res.body.total).to.equal(1)
53 expect(res.body.data[0].name).to.equal(localVideoName)
56 it('Should make a local channels search by default', async function () {
57 const res = await searchVideoChannel(server.url, 'root')
59 expect(res.body.total).to.equal(1)
60 expect(res.body.data[0].name).to.equal('root_channel')
61 expect(res.body.data[0].host).to.equal('localhost:' + server.port)
64 it('Should make an index videos search by default', async function () {
65 await updateCustomSubConfig(server.url, server.accessToken, {
69 isDefaultSearch: true,
70 disableLocalSearch: false
75 const res = await searchVideo(server.url, 'local video')
76 expect(res.body.total).to.be.greaterThan(2)
79 it('Should make an index channels search by default', async function () {
80 const res = await searchVideoChannel(server.url, 'root')
81 expect(res.body.total).to.be.greaterThan(2)
84 it('Should make an index videos search if local search is disabled', async function () {
85 await updateCustomSubConfig(server.url, server.accessToken, {
89 isDefaultSearch: false,
90 disableLocalSearch: true
95 const res = await searchVideo(server.url, 'local video')
96 expect(res.body.total).to.be.greaterThan(2)
99 it('Should make an index channels search if local search is disabled', async function () {
100 const res = await searchVideoChannel(server.url, 'root')
101 expect(res.body.total).to.be.greaterThan(2)
105 describe('Videos search', async function () {
107 it('Should make a simple search and not have results', async function () {
108 const res = await searchVideo(server.url, 'a'.repeat(500))
110 expect(res.body.total).to.equal(0)
111 expect(res.body.data).to.have.lengthOf(0)
114 it('Should make a simple search and have results', async function () {
115 const res = await searchVideo(server.url, 'What is PeerTube')
117 expect(res.body.total).to.be.greaterThan(1)
120 it('Should make a complex search', async function () {
122 async function check (search: VideosSearchQuery, exists = true) {
123 const res = await advancedVideosSearch(server.url, search)
125 if (exists === false) {
126 expect(res.body.total).to.equal(0)
127 expect(res.body.data).to.have.lengthOf(0)
131 expect(res.body.total).to.equal(1)
132 expect(res.body.data).to.have.lengthOf(1)
134 const video: Video = res.body.data[0]
136 expect(video.name).to.equal('What is PeerTube?')
137 expect(video.category.label).to.equal('Science & Technology')
138 expect(video.licence.label).to.equal('Attribution - Share Alike')
139 expect(video.privacy.label).to.equal('Public')
140 expect(video.duration).to.equal(113)
141 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
143 expect(video.account.host).to.equal('framatube.org')
144 expect(video.account.name).to.equal('framasoft')
145 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
146 expect(video.account.avatar).to.exist
148 expect(video.channel.host).to.equal('framatube.org')
149 expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8')
150 expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
151 expect(video.channel.avatar).to.exist
154 const baseSearch: VideosSearchQuery = {
155 search: 'what is peertube',
158 categoryOneOf: [ 15 ],
160 tagsAllOf: [ 'framasoft', 'peertube' ],
161 startDate: '2018-10-01T10:50:46.396Z',
162 endDate: '2018-10-01T10:55:46.396Z'
166 await check(baseSearch)
170 const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' })
171 await check(search, false)
175 const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] })
176 await check(search, false)
180 const search = immutableAssign(baseSearch, { durationMin: 2000 })
181 await check(search, false)
185 const search = immutableAssign(baseSearch, { nsfw: 'true' })
186 await check(search, false)
190 const search = immutableAssign(baseSearch, { nsfw: 'false' })
191 await check(search, true)
195 const search = immutableAssign(baseSearch, { nsfw: 'both' })
196 await check(search, true)
200 it('Should have a correct pagination', async function () {
207 const res = await advancedVideosSearch(server.url, search)
209 expect(res.body.total).to.be.greaterThan(5)
210 expect(res.body.data).to.have.lengthOf(5)
214 describe('Channels search', async function () {
216 it('Should make a simple search and not have results', async function () {
217 const res = await searchVideoChannel(server.url, 'a'.repeat(500))
219 expect(res.body.total).to.equal(0)
220 expect(res.body.data).to.have.lengthOf(0)
223 it('Should make a search and have results', async function () {
224 const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' })
226 expect(res.body.total).to.be.greaterThan(0)
227 expect(res.body.data).to.have.length.greaterThan(0)
229 const videoChannel: VideoChannel = res.body.data[0]
230 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
231 expect(videoChannel.host).to.equal('framatube.org')
232 expect(videoChannel.avatar).to.exist
233 expect(videoChannel.displayName).to.exist
235 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
236 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
237 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
238 expect(videoChannel.ownerAccount.avatar).to.exist
241 it('Should have a correct pagination', async function () {
242 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 })
244 expect(res.body.total).to.be.greaterThan(2)
245 expect(res.body.data).to.have.lengthOf(2)
249 after(async function () {
250 await cleanupTests([ server ])