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