diff options
Diffstat (limited to 'server/tests/api/search')
-rw-r--r-- | server/tests/api/search/search-index.ts | 113 |
1 files changed, 78 insertions, 35 deletions
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index feb35411f..cc841a6ff 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts | |||
@@ -3,7 +3,14 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' | 5 | import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' |
6 | import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' | 6 | import { |
7 | BooleanBothQuery, | ||
8 | VideoChannelsSearchQuery, | ||
9 | VideoPlaylistPrivacy, | ||
10 | VideoPlaylistsSearchQuery, | ||
11 | VideoPlaylistType, | ||
12 | VideosSearchQuery | ||
13 | } from '@shared/models' | ||
7 | 14 | ||
8 | const expect = chai.expect | 15 | const expect = chai.expect |
9 | 16 | ||
@@ -194,6 +201,16 @@ describe('Test videos search', function () { | |||
194 | const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } | 201 | const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } |
195 | await check(search, true) | 202 | await check(search, true) |
196 | } | 203 | } |
204 | |||
205 | { | ||
206 | const search = { ...baseSearch, host: 'example.com' } | ||
207 | await check(search, false) | ||
208 | } | ||
209 | |||
210 | { | ||
211 | const search = { ...baseSearch, host: 'framatube.org' } | ||
212 | await check(search, true) | ||
213 | } | ||
197 | }) | 214 | }) |
198 | 215 | ||
199 | it('Should have a correct pagination', async function () { | 216 | it('Should have a correct pagination', async function () { |
@@ -258,21 +275,34 @@ describe('Test videos search', function () { | |||
258 | }) | 275 | }) |
259 | 276 | ||
260 | it('Should make a search and have results', async function () { | 277 | it('Should make a search and have results', async function () { |
261 | const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } }) | ||
262 | 278 | ||
263 | expect(body.total).to.be.greaterThan(0) | 279 | async function check (search: VideoChannelsSearchQuery, exists = true) { |
264 | expect(body.data).to.have.length.greaterThan(0) | 280 | const body = await command.advancedChannelSearch({ search }) |
281 | |||
282 | if (exists === false) { | ||
283 | expect(body.total).to.equal(0) | ||
284 | expect(body.data).to.have.lengthOf(0) | ||
285 | return | ||
286 | } | ||
287 | |||
288 | expect(body.total).to.be.greaterThan(0) | ||
289 | expect(body.data).to.have.length.greaterThan(0) | ||
290 | |||
291 | const videoChannel = body.data[0] | ||
292 | expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') | ||
293 | expect(videoChannel.host).to.equal('framatube.org') | ||
294 | expect(videoChannel.avatar).to.exist | ||
295 | expect(videoChannel.displayName).to.exist | ||
265 | 296 | ||
266 | const videoChannel = body.data[0] | 297 | expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft') |
267 | expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') | 298 | expect(videoChannel.ownerAccount.name).to.equal('framasoft') |
268 | expect(videoChannel.host).to.equal('framatube.org') | 299 | expect(videoChannel.ownerAccount.host).to.equal('framatube.org') |
269 | expect(videoChannel.avatar).to.exist | 300 | expect(videoChannel.ownerAccount.avatar).to.exist |
270 | expect(videoChannel.displayName).to.exist | 301 | } |
271 | 302 | ||
272 | expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft') | 303 | await check({ search: 'Framasoft', sort: 'createdAt' }, true) |
273 | expect(videoChannel.ownerAccount.name).to.equal('framasoft') | 304 | await check({ search: 'Framasoft', host: 'example.com' }, false) |
274 | expect(videoChannel.ownerAccount.host).to.equal('framatube.org') | 305 | await check({ search: 'Framasoft', host: 'framatube.org' }, true) |
275 | expect(videoChannel.ownerAccount.avatar).to.exist | ||
276 | }) | 306 | }) |
277 | 307 | ||
278 | it('Should have a correct pagination', async function () { | 308 | it('Should have a correct pagination', async function () { |
@@ -293,36 +323,49 @@ describe('Test videos search', function () { | |||
293 | }) | 323 | }) |
294 | 324 | ||
295 | it('Should make a search and have results', async function () { | 325 | it('Should make a search and have results', async function () { |
296 | const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } }) | ||
297 | 326 | ||
298 | expect(body.total).to.be.greaterThan(0) | 327 | async function check (search: VideoPlaylistsSearchQuery, exists = true) { |
299 | expect(body.data).to.have.length.greaterThan(0) | 328 | const body = await command.advancedPlaylistSearch({ search }) |
329 | |||
330 | if (exists === false) { | ||
331 | expect(body.total).to.equal(0) | ||
332 | expect(body.data).to.have.lengthOf(0) | ||
333 | return | ||
334 | } | ||
335 | |||
336 | expect(body.total).to.be.greaterThan(0) | ||
337 | expect(body.data).to.have.length.greaterThan(0) | ||
338 | |||
339 | const videoPlaylist = body.data[0] | ||
300 | 340 | ||
301 | const videoPlaylist = body.data[0] | 341 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') |
342 | expect(videoPlaylist.thumbnailUrl).to.exist | ||
343 | expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | ||
302 | 344 | ||
303 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 345 | expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) |
304 | expect(videoPlaylist.thumbnailUrl).to.exist | 346 | expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) |
305 | expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 347 | expect(videoPlaylist.videosLength).to.exist |
306 | 348 | ||
307 | expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) | 349 | expect(videoPlaylist.createdAt).to.exist |
308 | expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) | 350 | expect(videoPlaylist.updatedAt).to.exist |
309 | expect(videoPlaylist.videosLength).to.exist | ||
310 | 351 | ||
311 | expect(videoPlaylist.createdAt).to.exist | 352 | expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') |
312 | expect(videoPlaylist.updatedAt).to.exist | 353 | expect(videoPlaylist.displayName).to.exist |
313 | 354 | ||
314 | expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 355 | expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') |
315 | expect(videoPlaylist.displayName).to.exist | 356 | expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') |
357 | expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') | ||
358 | expect(videoPlaylist.ownerAccount.avatar).to.exist | ||
316 | 359 | ||
317 | expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') | 360 | expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') |
318 | expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') | 361 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') |
319 | expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') | 362 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') |
320 | expect(videoPlaylist.ownerAccount.avatar).to.exist | 363 | expect(videoPlaylist.videoChannel.avatar).to.exist |
364 | } | ||
321 | 365 | ||
322 | expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') | 366 | await check({ search: 'E2E playlist', sort: '-match' }, true) |
323 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') | 367 | await check({ search: 'E2E playlist', host: 'example.com' }, false) |
324 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') | 368 | await check({ search: 'E2E playlist', host: 'peertube2.cpy.re' }, true) |
325 | expect(videoPlaylist.videoChannel.avatar).to.exist | ||
326 | }) | 369 | }) |
327 | 370 | ||
328 | it('Should have a correct pagination', async function () { | 371 | it('Should have a correct pagination', async function () { |