X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fsearch.ts;h=72c25ba331e735bf81c9778d9c9754867b608cad;hb=0a8a79552cf59c800011c9f63eaa8658230acddc;hp=a3da54e1f32dad7d7b8b746eb6703a1e63dc74f7;hpb=a24bd1ed41b43790bab6ba789580bb4e85f07d85;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index a3da54e1f..72c25ba33 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -1,17 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, - cleanupTests, - createSingleServer, - makeGetRequest, - PeerTubeServer, - setAccessTokensToServers -} from '@shared/extra-utils' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) { return server.config.updateCustomSubConfig({ @@ -57,7 +48,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 +127,34 @@ 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 }) + }) + + it('Should fail with invalid uuids', async function () { + const customQuery = { ...query, uuids: [ '6565', 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + }) + + it('Should succeed with valid uuids', async function () { + const customQuery = { ...query, uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } + 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 +169,16 @@ 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 fail with invalid uuids', async function () { + const customQuery = { ...query, uuids: [ '6565', 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } + await makeGetRequest({ url: server.url, path, query: customQuery, 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 +187,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 +203,15 @@ 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 fail with invalid handles', async function () { + await makeGetRequest({ url: server.url, path, query: { ...query, handles: [ '' ] }, 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 }) }) }) @@ -221,11 +251,6 @@ describe('Test videos API validator', function () { await updateSearchIndex(server, true, true) - { - const customQuery = { ...query, searchTarget: 'local' } - await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - } - { const customQuery = { ...query, searchTarget: 'search-index' } await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })