From 164c8d46cf5c948a28b4ac0e596fad9b83b2c229 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 28 Jul 2021 13:40:26 +0200 Subject: Update search index tests --- server/tests/api/check-params/search.ts | 30 +++++++-- server/tests/api/search/search-index.ts | 113 ++++++++++++++++++++++---------- 2 files changed, 103 insertions(+), 40 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index a3da54e1f..72ad6c842 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -57,7 +57,7 @@ describe('Test videos API validator', function () { await checkBadSortPagination(server.url, path, null, query) }) - it('Should success with the correct parameters', async function () { + it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) }) @@ -136,13 +136,24 @@ describe('Test videos API validator', function () { const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) + + it('Should fail with an invalid host', async function () { + const customQuery = { ...query, host: '6565' } + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + }) + + it('Should succeed with a host', async function () { + const customQuery = { ...query, host: 'example.com' } + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) + }) }) describe('When searching video playlists', function () { const path = '/api/v1/search/video-playlists/' const query = { - search: 'coucou' + search: 'coucou', + host: 'example.com' } it('Should fail with a bad start pagination', async function () { @@ -157,7 +168,11 @@ describe('Test videos API validator', function () { await checkBadSortPagination(server.url, path, null, query) }) - it('Should success with the correct parameters', async function () { + it('Should fail with an invalid host', async function () { + await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + }) + + it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -166,7 +181,8 @@ describe('Test videos API validator', function () { const path = '/api/v1/search/video-channels/' const query = { - search: 'coucou' + search: 'coucou', + host: 'example.com' } it('Should fail with a bad start pagination', async function () { @@ -181,7 +197,11 @@ describe('Test videos API validator', function () { await checkBadSortPagination(server.url, path, null, query) }) - it('Should success with the correct parameters', async function () { + it('Should fail with an invalid host', async function () { + await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + }) + + it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) }) }) 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 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' -import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' +import { + BooleanBothQuery, + VideoChannelsSearchQuery, + VideoPlaylistPrivacy, + VideoPlaylistsSearchQuery, + VideoPlaylistType, + VideosSearchQuery +} from '@shared/models' const expect = chai.expect @@ -194,6 +201,16 @@ describe('Test videos search', function () { const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } await check(search, true) } + + { + const search = { ...baseSearch, host: 'example.com' } + await check(search, false) + } + + { + const search = { ...baseSearch, host: 'framatube.org' } + await check(search, true) + } }) it('Should have a correct pagination', async function () { @@ -258,21 +275,34 @@ describe('Test videos search', function () { }) it('Should make a search and have results', async function () { - const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } }) - expect(body.total).to.be.greaterThan(0) - expect(body.data).to.have.length.greaterThan(0) + async function check (search: VideoChannelsSearchQuery, exists = true) { + const body = await command.advancedChannelSearch({ search }) + + if (exists === false) { + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + return + } + + expect(body.total).to.be.greaterThan(0) + expect(body.data).to.have.length.greaterThan(0) + + const videoChannel = body.data[0] + expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') + expect(videoChannel.host).to.equal('framatube.org') + expect(videoChannel.avatar).to.exist + expect(videoChannel.displayName).to.exist - const videoChannel = body.data[0] - expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') - expect(videoChannel.host).to.equal('framatube.org') - expect(videoChannel.avatar).to.exist - expect(videoChannel.displayName).to.exist + expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft') + expect(videoChannel.ownerAccount.name).to.equal('framasoft') + expect(videoChannel.ownerAccount.host).to.equal('framatube.org') + expect(videoChannel.ownerAccount.avatar).to.exist + } - expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft') - expect(videoChannel.ownerAccount.name).to.equal('framasoft') - expect(videoChannel.ownerAccount.host).to.equal('framatube.org') - expect(videoChannel.ownerAccount.avatar).to.exist + await check({ search: 'Framasoft', sort: 'createdAt' }, true) + await check({ search: 'Framasoft', host: 'example.com' }, false) + await check({ search: 'Framasoft', host: 'framatube.org' }, true) }) it('Should have a correct pagination', async function () { @@ -293,36 +323,49 @@ describe('Test videos search', function () { }) it('Should make a search and have results', async function () { - const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } }) - expect(body.total).to.be.greaterThan(0) - expect(body.data).to.have.length.greaterThan(0) + async function check (search: VideoPlaylistsSearchQuery, exists = true) { + const body = await command.advancedPlaylistSearch({ search }) + + if (exists === false) { + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + return + } + + expect(body.total).to.be.greaterThan(0) + expect(body.data).to.have.length.greaterThan(0) + + const videoPlaylist = body.data[0] - const videoPlaylist = body.data[0] + expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') + expect(videoPlaylist.thumbnailUrl).to.exist + expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') - expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') - expect(videoPlaylist.thumbnailUrl).to.exist - expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') + expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) + expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) + expect(videoPlaylist.videosLength).to.exist - expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) - expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) - expect(videoPlaylist.videosLength).to.exist + expect(videoPlaylist.createdAt).to.exist + expect(videoPlaylist.updatedAt).to.exist - expect(videoPlaylist.createdAt).to.exist - expect(videoPlaylist.updatedAt).to.exist + expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') + expect(videoPlaylist.displayName).to.exist - expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') - expect(videoPlaylist.displayName).to.exist + expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') + expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') + expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') + expect(videoPlaylist.ownerAccount.avatar).to.exist - expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') - expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') - expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') - expect(videoPlaylist.ownerAccount.avatar).to.exist + expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') + expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') + expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') + expect(videoPlaylist.videoChannel.avatar).to.exist + } - expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') - expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') - expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') - expect(videoPlaylist.videoChannel.avatar).to.exist + await check({ search: 'E2E playlist', sort: '-match' }, true) + await check({ search: 'E2E playlist', host: 'example.com' }, false) + await check({ search: 'E2E playlist', host: 'peertube2.cpy.re' }, true) }) it('Should have a correct pagination', async function () { -- cgit v1.2.3