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