]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-index.ts
Force stop remote live transcoding
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-index.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import {
5 BooleanBothQuery,
6 VideoChannelsSearchQuery,
7 VideoPlaylistPrivacy,
8 VideoPlaylistsSearchQuery,
9 VideoPlaylistType,
10 VideosSearchQuery
11 } from '@shared/models'
12 import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/server-commands'
13
14 describe('Test index search', function () {
15 const localVideoName = 'local video' + new Date().toISOString()
16
17 let server: PeerTubeServer = null
18 let command: SearchCommand
19
20 before(async function () {
21 this.timeout(30000)
22
23 server = await createSingleServer(1)
24
25 await setAccessTokensToServers([ server ])
26
27 await server.videos.upload({ attributes: { name: localVideoName } })
28
29 command = server.search
30 })
31
32 describe('Default search', async function () {
33
34 it('Should make a local videos search by default', async function () {
35 await server.config.updateCustomSubConfig({
36 newConfig: {
37 search: {
38 searchIndex: {
39 enabled: true,
40 isDefaultSearch: false,
41 disableLocalSearch: false
42 }
43 }
44 }
45 })
46
47 const body = await command.searchVideos({ search: 'local video' })
48
49 expect(body.total).to.equal(1)
50 expect(body.data[0].name).to.equal(localVideoName)
51 })
52
53 it('Should make a local channels search by default', async function () {
54 const body = await command.searchChannels({ search: 'root' })
55
56 expect(body.total).to.equal(1)
57 expect(body.data[0].name).to.equal('root_channel')
58 expect(body.data[0].host).to.equal(server.host)
59 })
60
61 it('Should make an index videos search by default', async function () {
62 await server.config.updateCustomSubConfig({
63 newConfig: {
64 search: {
65 searchIndex: {
66 enabled: true,
67 isDefaultSearch: true,
68 disableLocalSearch: false
69 }
70 }
71 }
72 })
73
74 const body = await command.searchVideos({ search: 'local video' })
75 expect(body.total).to.be.greaterThan(2)
76 })
77
78 it('Should make an index channels search by default', async function () {
79 const body = await command.searchChannels({ search: 'root' })
80 expect(body.total).to.be.greaterThan(2)
81 })
82 })
83
84 describe('Videos search', async function () {
85
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')
110 // TODO: remove, deprecated in 4.2
111 expect(video.account.avatar).to.exist
112 expect(video.account.avatars.length).to.equal(2, 'Account should have one avatar image')
113
114 expect(video.channel.host).to.equal('framatube.org')
115 expect(video.channel.name).to.equal('joinpeertube')
116 expect(video.channel.url).to.equal('https://framatube.org/video-channels/joinpeertube')
117 // TODO: remove, deprecated in 4.2
118 expect(video.channel.avatar).to.exist
119 expect(video.channel.avatars.length).to.equal(2, 'Channel should have one avatar image')
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
133 it('Should make a simple search and not have results', async function () {
134 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
135
136 expect(body.total).to.equal(0)
137 expect(body.data).to.have.lengthOf(0)
138 })
139
140 it('Should make a simple search and have results', async function () {
141 const body = await command.searchVideos({ search: 'What is PeerTube' })
142
143 expect(body.total).to.be.greaterThan(1)
144 })
145
146 it('Should make a simple search', async function () {
147 await check(baseSearch)
148 })
149
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 })
154
155 it('Should search by tags', async function () {
156 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
157 await check(search, false)
158 })
159
160 it('Should search by duration', async function () {
161 const search = { ...baseSearch, durationMin: 2000 }
162 await check(search, false)
163 })
164
165 it('Should search by nsfw attribute', async function () {
166 {
167 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
168 await check(search, false)
169 }
170
171 {
172 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
173 await check(search, true)
174 }
175
176 {
177 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
178 await check(search, true)
179 }
180 })
181
182 it('Should search by host', async function () {
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 }
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'
199
200 {
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)
211 }
212 }
213
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)
223 }
224 }
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
234 const body = await command.advancedVideoSearch({ search })
235
236 expect(body.total).to.be.greaterThan(5)
237 expect(body.data).to.have.lengthOf(5)
238 })
239
240 it('Should use the nsfw instance policy as default', async function () {
241 let nsfwUUID: string
242
243 {
244 await server.config.updateCustomSubConfig({
245 newConfig: {
246 instance: { defaultNSFWPolicy: 'display' }
247 }
248 })
249
250 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
251 expect(body.data).to.have.length.greaterThan(0)
252
253 const video = body.data[0]
254 expect(video.nsfw).to.be.true
255
256 nsfwUUID = video.uuid
257 }
258
259 {
260 await server.config.updateCustomSubConfig({
261 newConfig: {
262 instance: { defaultNSFWPolicy: 'do_not_list' }
263 }
264 })
265
266 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
267
268 try {
269 expect(body.data).to.have.lengthOf(0)
270 } catch {
271 const video = body.data[0]
272
273 expect(video.uuid).not.equal(nsfwUUID)
274 }
275 }
276 })
277 })
278
279 describe('Channels search', async function () {
280
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')
296 // TODO: remove, deprecated in 4.2
297 expect(videoChannel.avatar).to.exist
298 expect(videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
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')
304 // TODO: remove, deprecated in 4.2
305 expect(videoChannel.ownerAccount.avatar).to.exist
306 expect(videoChannel.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
307 }
308
309 it('Should make a simple search and not have results', async function () {
310 const body = await command.searchChannels({ search: 'a'.repeat(500) })
311
312 expect(body.total).to.equal(0)
313 expect(body.data).to.have.lengthOf(0)
314 })
315
316 it('Should make a search and have results', async function () {
317 await check({ search: 'Framasoft', sort: 'createdAt' }, true)
318 })
319
320 it('Should make host search and have appropriate results', async function () {
321 await check({ search: 'Framasoft videos', host: 'example.com' }, false)
322 await check({ search: 'Framasoft videos', host: 'framatube.org' }, true)
323 })
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 })
330
331 it('Should have a correct pagination', async function () {
332 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
333
334 expect(body.total).to.be.greaterThan(2)
335 expect(body.data).to.have.lengthOf(2)
336 })
337 })
338
339 describe('Playlists search', async function () {
340
341 async function check (search: VideoPlaylistsSearchQuery, exists = true) {
342 const body = await command.advancedPlaylistSearch({ search })
343
344 if (exists === false) {
345 expect(body.total).to.equal(0)
346 expect(body.data).to.have.lengthOf(0)
347 return
348 }
349
350 expect(body.total).to.be.greaterThan(0)
351 expect(body.data).to.have.length.greaterThan(0)
352
353 const videoPlaylist = body.data[0]
354
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')
358
359 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
360 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
361 expect(videoPlaylist.videosLength).to.exist
362
363 expect(videoPlaylist.createdAt).to.exist
364 expect(videoPlaylist.updatedAt).to.exist
365
366 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
367 expect(videoPlaylist.displayName).to.exist
368
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')
372 // TODO: remove, deprecated in 4.2
373 expect(videoPlaylist.ownerAccount.avatar).to.exist
374 expect(videoPlaylist.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
375
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')
379 // TODO: remove, deprecated in 4.2
380 expect(videoPlaylist.videoChannel.avatar).to.exist
381 expect(videoPlaylist.videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
382 }
383
384 it('Should make a simple search and not have results', async function () {
385 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
386
387 expect(body.total).to.equal(0)
388 expect(body.data).to.have.lengthOf(0)
389 })
390
391 it('Should make a search and have results', async function () {
392 await check({ search: 'E2E playlist', sort: '-match' }, true)
393 })
394
395 it('Should make host search and have appropriate results', async function () {
396 await check({ search: 'E2E playlist', host: 'example.com' }, false)
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 }
431 })
432
433 it('Should have a correct pagination', async function () {
434 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
435
436 expect(body.total).to.be.greaterThan(2)
437 expect(body.data).to.have.lengthOf(2)
438 })
439 })
440
441 after(async function () {
442 await cleanupTests([ server ])
443 })
444 })