]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/search/search-index.ts
Remove low timeouts
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-index.ts
CommitLineData
3521ab8f
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
86347717 3import { expect } from 'chai'
164c8d46
C
4import {
5 BooleanBothQuery,
6 VideoChannelsSearchQuery,
7 VideoPlaylistPrivacy,
8 VideoPlaylistsSearchQuery,
9 VideoPlaylistType,
10 VideosSearchQuery
11} from '@shared/models'
e0faa8ad 12import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/server-commands'
3521ab8f 13
d0800f76 14describe('Test index search', function () {
3521ab8f
C
15 const localVideoName = 'local video' + new Date().toISOString()
16
254d3579 17 let server: PeerTubeServer = null
af971e06
C
18 let command: SearchCommand
19
3521ab8f
C
20 before(async function () {
21 this.timeout(30000)
22
254d3579 23 server = await createSingleServer(1)
3521ab8f
C
24
25 await setAccessTokensToServers([ server ])
26
89d241a7 27 await server.videos.upload({ attributes: { name: localVideoName } })
af971e06 28
89d241a7 29 command = server.search
3521ab8f
C
30 })
31
32 describe('Default search', async function () {
33
34 it('Should make a local videos search by default', async function () {
89d241a7 35 await server.config.updateCustomSubConfig({
65e6e260
C
36 newConfig: {
37 search: {
38 searchIndex: {
39 enabled: true,
40 isDefaultSearch: false,
41 disableLocalSearch: false
42 }
3521ab8f
C
43 }
44 }
45 })
46
af971e06 47 const body = await command.searchVideos({ search: 'local video' })
3521ab8f 48
af971e06
C
49 expect(body.total).to.equal(1)
50 expect(body.data[0].name).to.equal(localVideoName)
3521ab8f
C
51 })
52
53 it('Should make a local channels search by default', async function () {
af971e06 54 const body = await command.searchChannels({ search: 'root' })
3521ab8f 55
af971e06
C
56 expect(body.total).to.equal(1)
57 expect(body.data[0].name).to.equal('root_channel')
2732eeff 58 expect(body.data[0].host).to.equal(server.host)
3521ab8f
C
59 })
60
61 it('Should make an index videos search by default', async function () {
89d241a7 62 await server.config.updateCustomSubConfig({
65e6e260
C
63 newConfig: {
64 search: {
65 searchIndex: {
66 enabled: true,
67 isDefaultSearch: true,
68 disableLocalSearch: false
69 }
3521ab8f
C
70 }
71 }
72 })
73
af971e06
C
74 const body = await command.searchVideos({ search: 'local video' })
75 expect(body.total).to.be.greaterThan(2)
3521ab8f
C
76 })
77
78 it('Should make an index channels search by default', async function () {
af971e06
C
79 const body = await command.searchChannels({ search: 'root' })
80 expect(body.total).to.be.greaterThan(2)
3521ab8f 81 })
3521ab8f
C
82 })
83
84 describe('Videos search', async function () {
85
56d07460
C
86 async function check (search: VideosSearchQuery, exists = true) {
87 const body = await command.advancedVideoSearch({ search })
88
89 if (exists === false) {
90 expect(body.total).to.equal(0)
91 expect(body.data).to.have.lengthOf(0)
92 return
93 }
94
95 expect(body.total).to.equal(1)
96 expect(body.data).to.have.lengthOf(1)
97
98 const video = body.data[0]
99
100 expect(video.name).to.equal('What is PeerTube?')
101 expect(video.category.label).to.equal('Science & Technology')
102 expect(video.licence.label).to.equal('Attribution - Share Alike')
103 expect(video.privacy.label).to.equal('Public')
104 expect(video.duration).to.equal(113)
105 expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
106
107 expect(video.account.host).to.equal('framatube.org')
108 expect(video.account.name).to.equal('framasoft')
109 expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
d0800f76 110 // TODO: remove, deprecated in 4.2
56d07460 111 expect(video.account.avatar).to.exist
1a99dc64 112 expect(video.account.avatars.length).to.equal(2, 'Account should have one avatar image')
56d07460
C
113
114 expect(video.channel.host).to.equal('framatube.org')
5b075bc5
C
115 expect(video.channel.name).to.equal('joinpeertube')
116 expect(video.channel.url).to.equal('https://framatube.org/video-channels/joinpeertube')
d0800f76 117 // TODO: remove, deprecated in 4.2
56d07460 118 expect(video.channel.avatar).to.exist
1a99dc64 119 expect(video.channel.avatars.length).to.equal(2, 'Channel should have one avatar image')
56d07460
C
120 }
121
122 const baseSearch: VideosSearchQuery = {
123 search: 'what is peertube',
124 start: 0,
125 count: 2,
126 categoryOneOf: [ 15 ],
127 licenceOneOf: [ 2 ],
128 tagsAllOf: [ 'framasoft', 'peertube' ],
129 startDate: '2018-10-01T10:50:46.396Z',
130 endDate: '2018-10-01T10:55:46.396Z'
131 }
132
3521ab8f 133 it('Should make a simple search and not have results', async function () {
af971e06 134 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
3521ab8f 135
af971e06
C
136 expect(body.total).to.equal(0)
137 expect(body.data).to.have.lengthOf(0)
3521ab8f
C
138 })
139
140 it('Should make a simple search and have results', async function () {
af971e06 141 const body = await command.searchVideos({ search: 'What is PeerTube' })
3521ab8f 142
af971e06 143 expect(body.total).to.be.greaterThan(1)
3521ab8f
C
144 })
145
56d07460
C
146 it('Should make a simple search', async function () {
147 await check(baseSearch)
148 })
3521ab8f 149
56d07460
C
150 it('Should search by start date', async function () {
151 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
152 await check(search, false)
153 })
3521ab8f 154
56d07460
C
155 it('Should search by tags', async function () {
156 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
157 await check(search, false)
158 })
3521ab8f 159
56d07460
C
160 it('Should search by duration', async function () {
161 const search = { ...baseSearch, durationMin: 2000 }
162 await check(search, false)
163 })
3521ab8f 164
56d07460 165 it('Should search by nsfw attribute', async function () {
3521ab8f 166 {
6c5065a0 167 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
3521ab8f
C
168 await check(search, false)
169 }
170
171 {
6c5065a0 172 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
3521ab8f
C
173 await check(search, true)
174 }
175
176 {
6c5065a0 177 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
3521ab8f
C
178 await check(search, true)
179 }
56d07460 180 })
164c8d46 181
56d07460 182 it('Should search by host', async function () {
164c8d46
C
183 {
184 const search = { ...baseSearch, host: 'example.com' }
185 await check(search, false)
186 }
187
188 {
189 const search = { ...baseSearch, host: 'framatube.org' }
190 await check(search, true)
191 }
56d07460
C
192 })
193
194 it('Should search by uuids', async function () {
195 const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d'
196 const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv'
197 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
198 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
d6886027
C
199
200 {
56d07460
C
201 const uuidsMatrix = [
202 [ goodUUID ],
203 [ goodUUID, badShortUUID ],
204 [ badShortUUID, goodShortUUID ],
205 [ goodUUID, goodShortUUID ]
206 ]
207
208 for (const uuids of uuidsMatrix) {
209 const search = { ...baseSearch, uuids }
210 await check(search, true)
d6886027 211 }
56d07460 212 }
d6886027 213
56d07460
C
214 {
215 const uuidsMatrix = [
216 [ badUUID ],
217 [ badShortUUID ]
218 ]
219
220 for (const uuids of uuidsMatrix) {
221 const search = { ...baseSearch, uuids }
222 await check(search, false)
d6886027
C
223 }
224 }
3521ab8f
C
225 })
226
227 it('Should have a correct pagination', async function () {
228 const search = {
229 search: 'video',
230 start: 0,
231 count: 5
232 }
233
af971e06 234 const body = await command.advancedVideoSearch({ search })
3521ab8f 235
af971e06
C
236 expect(body.total).to.be.greaterThan(5)
237 expect(body.data).to.have.lengthOf(5)
3521ab8f 238 })
1a40132c
C
239
240 it('Should use the nsfw instance policy as default', async function () {
241 let nsfwUUID: string
242
243 {
89d241a7 244 await server.config.updateCustomSubConfig({
65e6e260
C
245 newConfig: {
246 instance: { defaultNSFWPolicy: 'display' }
247 }
248 })
1a40132c 249
af971e06
C
250 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
251 expect(body.data).to.have.length.greaterThan(0)
1a40132c 252
af971e06 253 const video = body.data[0]
1a40132c
C
254 expect(video.nsfw).to.be.true
255
256 nsfwUUID = video.uuid
257 }
258
259 {
89d241a7 260 await server.config.updateCustomSubConfig({
65e6e260
C
261 newConfig: {
262 instance: { defaultNSFWPolicy: 'do_not_list' }
263 }
264 })
1a40132c 265
af971e06 266 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
1a40132c
C
267
268 try {
af971e06
C
269 expect(body.data).to.have.lengthOf(0)
270 } catch {
271 const video = body.data[0]
1a40132c
C
272
273 expect(video.uuid).not.equal(nsfwUUID)
274 }
275 }
276 })
3521ab8f
C
277 })
278
279 describe('Channels search', async function () {
280
56d07460
C
281 async function check (search: VideoChannelsSearchQuery, exists = true) {
282 const body = await command.advancedChannelSearch({ search })
283
284 if (exists === false) {
285 expect(body.total).to.equal(0)
286 expect(body.data).to.have.lengthOf(0)
287 return
288 }
289
290 expect(body.total).to.be.greaterThan(0)
291 expect(body.data).to.have.length.greaterThan(0)
292
293 const videoChannel = body.data[0]
294 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
295 expect(videoChannel.host).to.equal('framatube.org')
d0800f76 296 // TODO: remove, deprecated in 4.2
56d07460 297 expect(videoChannel.avatar).to.exist
1a99dc64 298 expect(videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
56d07460
C
299 expect(videoChannel.displayName).to.exist
300
301 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
302 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
303 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
d0800f76 304 // TODO: remove, deprecated in 4.2
56d07460 305 expect(videoChannel.ownerAccount.avatar).to.exist
1a99dc64 306 expect(videoChannel.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
56d07460
C
307 }
308
3521ab8f 309 it('Should make a simple search and not have results', async function () {
af971e06 310 const body = await command.searchChannels({ search: 'a'.repeat(500) })
3521ab8f 311
af971e06
C
312 expect(body.total).to.equal(0)
313 expect(body.data).to.have.lengthOf(0)
3521ab8f
C
314 })
315
316 it('Should make a search and have results', async function () {
164c8d46 317 await check({ search: 'Framasoft', sort: 'createdAt' }, true)
56d07460
C
318 })
319
320 it('Should make host search and have appropriate results', async function () {
ceecd871
C
321 await check({ search: 'Framasoft videos', host: 'example.com' }, false)
322 await check({ search: 'Framasoft videos', host: 'framatube.org' }, true)
3521ab8f 323 })
56d07460
C
324
325 it('Should make handles search and have appropriate results', async function () {
326 await check({ handles: [ 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
327 await check({ handles: [ 'jeanine', 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
328 await check({ handles: [ 'jeanine', 'chocobozzz_channel2@peertube2.cpy.re' ] }, false)
329 })
3521ab8f
C
330
331 it('Should have a correct pagination', async function () {
af971e06 332 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
3521ab8f 333
af971e06
C
334 expect(body.total).to.be.greaterThan(2)
335 expect(body.data).to.have.lengthOf(2)
3521ab8f
C
336 })
337 })
338
37a44fc9
C
339 describe('Playlists search', async function () {
340
d6886027
C
341 async function check (search: VideoPlaylistsSearchQuery, exists = true) {
342 const body = await command.advancedPlaylistSearch({ search })
37a44fc9 343
d6886027
C
344 if (exists === false) {
345 expect(body.total).to.equal(0)
346 expect(body.data).to.have.lengthOf(0)
347 return
348 }
37a44fc9 349
d6886027
C
350 expect(body.total).to.be.greaterThan(0)
351 expect(body.data).to.have.length.greaterThan(0)
37a44fc9 352
d6886027 353 const videoPlaylist = body.data[0]
164c8d46 354
d6886027
C
355 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
356 expect(videoPlaylist.thumbnailUrl).to.exist
357 expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
164c8d46 358
d6886027
C
359 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
360 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
361 expect(videoPlaylist.videosLength).to.exist
37a44fc9 362
d6886027
C
363 expect(videoPlaylist.createdAt).to.exist
364 expect(videoPlaylist.updatedAt).to.exist
37a44fc9 365
d6886027
C
366 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
367 expect(videoPlaylist.displayName).to.exist
37a44fc9 368
d6886027
C
369 expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz')
370 expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz')
371 expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re')
d0800f76 372 // TODO: remove, deprecated in 4.2
d6886027 373 expect(videoPlaylist.ownerAccount.avatar).to.exist
135c38bb 374 expect(videoPlaylist.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
37a44fc9 375
d6886027
C
376 expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel')
377 expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
378 expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
d0800f76 379 // TODO: remove, deprecated in 4.2
d6886027 380 expect(videoPlaylist.videoChannel.avatar).to.exist
135c38bb 381 expect(videoPlaylist.videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
d6886027 382 }
37a44fc9 383
d6886027
C
384 it('Should make a simple search and not have results', async function () {
385 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
37a44fc9 386
d6886027
C
387 expect(body.total).to.equal(0)
388 expect(body.data).to.have.lengthOf(0)
389 })
37a44fc9 390
d6886027 391 it('Should make a search and have results', async function () {
164c8d46 392 await check({ search: 'E2E playlist', sort: '-match' }, true)
d6886027
C
393 })
394
395 it('Should make host search and have appropriate results', async function () {
164c8d46 396 await check({ search: 'E2E playlist', host: 'example.com' }, false)
d6886027
C
397 await check({ search: 'E2E playlist', host: 'peertube2.cpy.re', sort: '-match' }, true)
398 })
399
400 it('Should make a search by uuids and have appropriate results', async function () {
401 const goodUUID = '73804a40-da9a-40c2-b1eb-2c6d9eec8f0a'
402 const goodShortUUID = 'fgei1ws1oa6FCaJ2qZPG29'
403 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
404 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
405
406 {
407 const uuidsMatrix = [
408 [ goodUUID ],
409 [ goodUUID, badShortUUID ],
410 [ badShortUUID, goodShortUUID ],
411 [ goodUUID, goodShortUUID ]
412 ]
413
414 for (const uuids of uuidsMatrix) {
415 const search = { search: 'E2E playlist', sort: '-match', uuids }
416 await check(search, true)
417 }
418 }
419
420 {
421 const uuidsMatrix = [
422 [ badUUID ],
423 [ badShortUUID ]
424 ]
425
426 for (const uuids of uuidsMatrix) {
427 const search = { search: 'E2E playlist', sort: '-match', uuids }
428 await check(search, false)
429 }
430 }
37a44fc9
C
431 })
432
433 it('Should have a correct pagination', async function () {
af971e06 434 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
37a44fc9 435
af971e06
C
436 expect(body.total).to.be.greaterThan(2)
437 expect(body.data).to.have.lengthOf(2)
37a44fc9
C
438 })
439 })
440
3521ab8f
C
441 after(async function () {
442 await cleanupTests([ server ])
443 })
444})