diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-29 11:54:38 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-29 11:54:38 +0200 |
commit | d6886027109af42be2e3ec5d14ad166199add11d (patch) | |
tree | 3a7603d36ff35a2d623d863f14ab93a2e1e6b7f2 /server/tests/api | |
parent | b033851fb54241bb703f86add025229e68cc6f59 (diff) | |
download | PeerTube-d6886027109af42be2e3ec5d14ad166199add11d.tar.gz PeerTube-d6886027109af42be2e3ec5d14ad166199add11d.tar.zst PeerTube-d6886027109af42be2e3ec5d14ad166199add11d.zip |
Refactor search query options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/search/search-index.ts | 142 |
1 files changed, 105 insertions, 37 deletions
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index cc841a6ff..d1aa5ef41 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts | |||
@@ -211,6 +211,39 @@ describe('Test videos search', function () { | |||
211 | const search = { ...baseSearch, host: 'framatube.org' } | 211 | const search = { ...baseSearch, host: 'framatube.org' } |
212 | await check(search, true) | 212 | await check(search, true) |
213 | } | 213 | } |
214 | |||
215 | { | ||
216 | const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d' | ||
217 | const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv' | ||
218 | const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0' | ||
219 | const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej' | ||
220 | |||
221 | { | ||
222 | const uuidsMatrix = [ | ||
223 | [ goodUUID ], | ||
224 | [ goodUUID, badShortUUID ], | ||
225 | [ badShortUUID, goodShortUUID ], | ||
226 | [ goodUUID, goodShortUUID ] | ||
227 | ] | ||
228 | |||
229 | for (const uuids of uuidsMatrix) { | ||
230 | const search = { ...baseSearch, uuids } | ||
231 | await check(search, true) | ||
232 | } | ||
233 | } | ||
234 | |||
235 | { | ||
236 | const uuidsMatrix = [ | ||
237 | [ badUUID ], | ||
238 | [ badShortUUID ] | ||
239 | ] | ||
240 | |||
241 | for (const uuids of uuidsMatrix) { | ||
242 | const search = { ...baseSearch, uuids } | ||
243 | await check(search, false) | ||
244 | } | ||
245 | } | ||
246 | } | ||
214 | }) | 247 | }) |
215 | 248 | ||
216 | it('Should have a correct pagination', async function () { | 249 | it('Should have a correct pagination', async function () { |
@@ -315,57 +348,92 @@ describe('Test videos search', function () { | |||
315 | 348 | ||
316 | describe('Playlists search', async function () { | 349 | describe('Playlists search', async function () { |
317 | 350 | ||
318 | it('Should make a simple search and not have results', async function () { | 351 | async function check (search: VideoPlaylistsSearchQuery, exists = true) { |
319 | const body = await command.searchPlaylists({ search: 'a'.repeat(500) }) | 352 | const body = await command.advancedPlaylistSearch({ search }) |
320 | 353 | ||
321 | expect(body.total).to.equal(0) | 354 | if (exists === false) { |
322 | expect(body.data).to.have.lengthOf(0) | 355 | expect(body.total).to.equal(0) |
323 | }) | 356 | expect(body.data).to.have.lengthOf(0) |
357 | return | ||
358 | } | ||
324 | 359 | ||
325 | it('Should make a search and have results', async function () { | 360 | expect(body.total).to.be.greaterThan(0) |
361 | expect(body.data).to.have.length.greaterThan(0) | ||
326 | 362 | ||
327 | async function check (search: VideoPlaylistsSearchQuery, exists = true) { | 363 | const videoPlaylist = body.data[0] |
328 | const body = await command.advancedPlaylistSearch({ search }) | ||
329 | 364 | ||
330 | if (exists === false) { | 365 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') |
331 | expect(body.total).to.equal(0) | 366 | expect(videoPlaylist.thumbnailUrl).to.exist |
332 | expect(body.data).to.have.lengthOf(0) | 367 | expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') |
333 | return | ||
334 | } | ||
335 | 368 | ||
336 | expect(body.total).to.be.greaterThan(0) | 369 | expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) |
337 | expect(body.data).to.have.length.greaterThan(0) | 370 | expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) |
338 | 371 | expect(videoPlaylist.videosLength).to.exist | |
339 | const videoPlaylist = body.data[0] | ||
340 | 372 | ||
341 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 373 | expect(videoPlaylist.createdAt).to.exist |
342 | expect(videoPlaylist.thumbnailUrl).to.exist | 374 | expect(videoPlaylist.updatedAt).to.exist |
343 | expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | ||
344 | 375 | ||
345 | expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) | 376 | expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') |
346 | expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) | 377 | expect(videoPlaylist.displayName).to.exist |
347 | expect(videoPlaylist.videosLength).to.exist | ||
348 | 378 | ||
349 | expect(videoPlaylist.createdAt).to.exist | 379 | expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') |
350 | expect(videoPlaylist.updatedAt).to.exist | 380 | expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') |
381 | expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') | ||
382 | expect(videoPlaylist.ownerAccount.avatar).to.exist | ||
351 | 383 | ||
352 | expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 384 | expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') |
353 | expect(videoPlaylist.displayName).to.exist | 385 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') |
386 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') | ||
387 | expect(videoPlaylist.videoChannel.avatar).to.exist | ||
388 | } | ||
354 | 389 | ||
355 | expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') | 390 | it('Should make a simple search and not have results', async function () { |
356 | expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') | 391 | const body = await command.searchPlaylists({ search: 'a'.repeat(500) }) |
357 | expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') | ||
358 | expect(videoPlaylist.ownerAccount.avatar).to.exist | ||
359 | 392 | ||
360 | expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') | 393 | expect(body.total).to.equal(0) |
361 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') | 394 | expect(body.data).to.have.lengthOf(0) |
362 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') | 395 | }) |
363 | expect(videoPlaylist.videoChannel.avatar).to.exist | ||
364 | } | ||
365 | 396 | ||
397 | it('Should make a search and have results', async function () { | ||
366 | await check({ search: 'E2E playlist', sort: '-match' }, true) | 398 | await check({ search: 'E2E playlist', sort: '-match' }, true) |
399 | }) | ||
400 | |||
401 | it('Should make host search and have appropriate results', async function () { | ||
367 | await check({ search: 'E2E playlist', host: 'example.com' }, false) | 402 | await check({ search: 'E2E playlist', host: 'example.com' }, false) |
368 | await check({ search: 'E2E playlist', host: 'peertube2.cpy.re' }, true) | 403 | await check({ search: 'E2E playlist', host: 'peertube2.cpy.re', sort: '-match' }, true) |
404 | }) | ||
405 | |||
406 | it('Should make a search by uuids and have appropriate results', async function () { | ||
407 | const goodUUID = '73804a40-da9a-40c2-b1eb-2c6d9eec8f0a' | ||
408 | const goodShortUUID = 'fgei1ws1oa6FCaJ2qZPG29' | ||
409 | const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0' | ||
410 | const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej' | ||
411 | |||
412 | { | ||
413 | const uuidsMatrix = [ | ||
414 | [ goodUUID ], | ||
415 | [ goodUUID, badShortUUID ], | ||
416 | [ badShortUUID, goodShortUUID ], | ||
417 | [ goodUUID, goodShortUUID ] | ||
418 | ] | ||
419 | |||
420 | for (const uuids of uuidsMatrix) { | ||
421 | const search = { search: 'E2E playlist', sort: '-match', uuids } | ||
422 | await check(search, true) | ||
423 | } | ||
424 | } | ||
425 | |||
426 | { | ||
427 | const uuidsMatrix = [ | ||
428 | [ badUUID ], | ||
429 | [ badShortUUID ] | ||
430 | ] | ||
431 | |||
432 | for (const uuids of uuidsMatrix) { | ||
433 | const search = { search: 'E2E playlist', sort: '-match', uuids } | ||
434 | await check(search, false) | ||
435 | } | ||
436 | } | ||
369 | }) | 437 | }) |
370 | 438 | ||
371 | it('Should have a correct pagination', async function () { | 439 | it('Should have a correct pagination', async function () { |