aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/search/search-index.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/api/search/search-index.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/api/search/search-index.ts')
-rw-r--r--server/tests/api/search/search-index.ts432
1 files changed, 0 insertions, 432 deletions
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
deleted file mode 100644
index cbe628ccc..000000000
--- a/server/tests/api/search/search-index.ts
+++ /dev/null
@@ -1,432 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import {
5 BooleanBothQuery,
6 VideoChannelsSearchQuery,
7 VideoPlaylistPrivacy,
8 VideoPlaylistsSearchQuery,
9 VideoPlaylistType,
10 VideosSearchQuery
11} from '@shared/models'
12import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/server-commands'
13
14describe('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 expect(video.account.avatars.length).to.equal(2, 'Account should have one avatar image')
111
112 expect(video.channel.host).to.equal('framatube.org')
113 expect(video.channel.name).to.equal('joinpeertube')
114 expect(video.channel.url).to.equal('https://framatube.org/video-channels/joinpeertube')
115 expect(video.channel.avatars.length).to.equal(2, 'Channel should have one avatar image')
116 }
117
118 const baseSearch: VideosSearchQuery = {
119 search: 'what is peertube',
120 start: 0,
121 count: 2,
122 categoryOneOf: [ 15 ],
123 licenceOneOf: [ 2 ],
124 tagsAllOf: [ 'framasoft', 'peertube' ],
125 startDate: '2018-10-01T10:50:46.396Z',
126 endDate: '2018-10-01T10:55:46.396Z'
127 }
128
129 it('Should make a simple search and not have results', async function () {
130 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
131
132 expect(body.total).to.equal(0)
133 expect(body.data).to.have.lengthOf(0)
134 })
135
136 it('Should make a simple search and have results', async function () {
137 const body = await command.searchVideos({ search: 'What is PeerTube' })
138
139 expect(body.total).to.be.greaterThan(1)
140 })
141
142 it('Should make a simple search', async function () {
143 await check(baseSearch)
144 })
145
146 it('Should search by start date', async function () {
147 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
148 await check(search, false)
149 })
150
151 it('Should search by tags', async function () {
152 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
153 await check(search, false)
154 })
155
156 it('Should search by duration', async function () {
157 const search = { ...baseSearch, durationMin: 2000 }
158 await check(search, false)
159 })
160
161 it('Should search by nsfw attribute', async function () {
162 {
163 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
164 await check(search, false)
165 }
166
167 {
168 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
169 await check(search, true)
170 }
171
172 {
173 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
174 await check(search, true)
175 }
176 })
177
178 it('Should search by host', async function () {
179 {
180 const search = { ...baseSearch, host: 'example.com' }
181 await check(search, false)
182 }
183
184 {
185 const search = { ...baseSearch, host: 'framatube.org' }
186 await check(search, true)
187 }
188 })
189
190 it('Should search by uuids', async function () {
191 const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d'
192 const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv'
193 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
194 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
195
196 {
197 const uuidsMatrix = [
198 [ goodUUID ],
199 [ goodUUID, badShortUUID ],
200 [ badShortUUID, goodShortUUID ],
201 [ goodUUID, goodShortUUID ]
202 ]
203
204 for (const uuids of uuidsMatrix) {
205 const search = { ...baseSearch, uuids }
206 await check(search, true)
207 }
208 }
209
210 {
211 const uuidsMatrix = [
212 [ badUUID ],
213 [ badShortUUID ]
214 ]
215
216 for (const uuids of uuidsMatrix) {
217 const search = { ...baseSearch, uuids }
218 await check(search, false)
219 }
220 }
221 })
222
223 it('Should have a correct pagination', async function () {
224 const search = {
225 search: 'video',
226 start: 0,
227 count: 5
228 }
229
230 const body = await command.advancedVideoSearch({ search })
231
232 expect(body.total).to.be.greaterThan(5)
233 expect(body.data).to.have.lengthOf(5)
234 })
235
236 it('Should use the nsfw instance policy as default', async function () {
237 let nsfwUUID: string
238
239 {
240 await server.config.updateCustomSubConfig({
241 newConfig: {
242 instance: { defaultNSFWPolicy: 'display' }
243 }
244 })
245
246 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
247 expect(body.data).to.have.length.greaterThan(0)
248
249 const video = body.data[0]
250 expect(video.nsfw).to.be.true
251
252 nsfwUUID = video.uuid
253 }
254
255 {
256 await server.config.updateCustomSubConfig({
257 newConfig: {
258 instance: { defaultNSFWPolicy: 'do_not_list' }
259 }
260 })
261
262 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
263
264 try {
265 expect(body.data).to.have.lengthOf(0)
266 } catch {
267 const video = body.data[0]
268
269 expect(video.uuid).not.equal(nsfwUUID)
270 }
271 }
272 })
273 })
274
275 describe('Channels search', async function () {
276
277 async function check (search: VideoChannelsSearchQuery, exists = true) {
278 const body = await command.advancedChannelSearch({ search })
279
280 if (exists === false) {
281 expect(body.total).to.equal(0)
282 expect(body.data).to.have.lengthOf(0)
283 return
284 }
285
286 expect(body.total).to.be.greaterThan(0)
287 expect(body.data).to.have.length.greaterThan(0)
288
289 const videoChannel = body.data[0]
290 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
291 expect(videoChannel.host).to.equal('framatube.org')
292 expect(videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
293 expect(videoChannel.displayName).to.exist
294
295 expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
296 expect(videoChannel.ownerAccount.name).to.equal('framasoft')
297 expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
298 expect(videoChannel.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
299 }
300
301 it('Should make a simple search and not have results', async function () {
302 const body = await command.searchChannels({ search: 'a'.repeat(500) })
303
304 expect(body.total).to.equal(0)
305 expect(body.data).to.have.lengthOf(0)
306 })
307
308 it('Should make a search and have results', async function () {
309 await check({ search: 'Framasoft', sort: 'createdAt' }, true)
310 })
311
312 it('Should make host search and have appropriate results', async function () {
313 await check({ search: 'Framasoft videos', host: 'example.com' }, false)
314 await check({ search: 'Framasoft videos', host: 'framatube.org' }, true)
315 })
316
317 it('Should make handles search and have appropriate results', async function () {
318 await check({ handles: [ 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
319 await check({ handles: [ 'jeanine', 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true)
320 await check({ handles: [ 'jeanine', 'chocobozzz_channel2@peertube2.cpy.re' ] }, false)
321 })
322
323 it('Should have a correct pagination', async function () {
324 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
325
326 expect(body.total).to.be.greaterThan(2)
327 expect(body.data).to.have.lengthOf(2)
328 })
329 })
330
331 describe('Playlists search', async function () {
332
333 async function check (search: VideoPlaylistsSearchQuery, exists = true) {
334 const body = await command.advancedPlaylistSearch({ search })
335
336 if (exists === false) {
337 expect(body.total).to.equal(0)
338 expect(body.data).to.have.lengthOf(0)
339 return
340 }
341
342 expect(body.total).to.be.greaterThan(0)
343 expect(body.data).to.have.length.greaterThan(0)
344
345 const videoPlaylist = body.data[0]
346
347 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
348 expect(videoPlaylist.thumbnailUrl).to.exist
349 expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
350
351 expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR)
352 expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
353 expect(videoPlaylist.videosLength).to.exist
354
355 expect(videoPlaylist.createdAt).to.exist
356 expect(videoPlaylist.updatedAt).to.exist
357
358 expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
359 expect(videoPlaylist.displayName).to.exist
360
361 expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz')
362 expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz')
363 expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re')
364 expect(videoPlaylist.ownerAccount.avatars.length).to.equal(2, 'Account should have two avatar images')
365
366 expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel')
367 expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel')
368 expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re')
369 expect(videoPlaylist.videoChannel.avatars.length).to.equal(2, 'Channel should have two avatar images')
370 }
371
372 it('Should make a simple search and not have results', async function () {
373 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
374
375 expect(body.total).to.equal(0)
376 expect(body.data).to.have.lengthOf(0)
377 })
378
379 it('Should make a search and have results', async function () {
380 await check({ search: 'E2E playlist', sort: '-match' }, true)
381 })
382
383 it('Should make host search and have appropriate results', async function () {
384 await check({ search: 'E2E playlist', host: 'example.com' }, false)
385 await check({ search: 'E2E playlist', host: 'peertube2.cpy.re', sort: '-match' }, true)
386 })
387
388 it('Should make a search by uuids and have appropriate results', async function () {
389 const goodUUID = '73804a40-da9a-40c2-b1eb-2c6d9eec8f0a'
390 const goodShortUUID = 'fgei1ws1oa6FCaJ2qZPG29'
391 const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0'
392 const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej'
393
394 {
395 const uuidsMatrix = [
396 [ goodUUID ],
397 [ goodUUID, badShortUUID ],
398 [ badShortUUID, goodShortUUID ],
399 [ goodUUID, goodShortUUID ]
400 ]
401
402 for (const uuids of uuidsMatrix) {
403 const search = { search: 'E2E playlist', sort: '-match', uuids }
404 await check(search, true)
405 }
406 }
407
408 {
409 const uuidsMatrix = [
410 [ badUUID ],
411 [ badShortUUID ]
412 ]
413
414 for (const uuids of uuidsMatrix) {
415 const search = { search: 'E2E playlist', sort: '-match', uuids }
416 await check(search, false)
417 }
418 }
419 })
420
421 it('Should have a correct pagination', async function () {
422 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
423
424 expect(body.total).to.be.greaterThan(2)
425 expect(body.data).to.have.lengthOf(2)
426 })
427 })
428
429 after(async function () {
430 await cleanupTests([ server ])
431 })
432})