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