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