From 3b0bd70aa05ab82fa30fe67ed4899d44652c703a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Jun 2020 16:39:45 +0200 Subject: Add search target check params --- server/tests/api/check-params/search.ts | 79 ++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index f8d0cd4ec..1a8a7235e 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -1,14 +1,32 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - -import { cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo } from '../../../../shared/extra-utils' +import { + cleanupTests, + flushAndRunServer, + immutableAssign, + makeGetRequest, + ServerInfo, + updateCustomSubConfig, + setAccessTokensToServers +} from '../../../../shared/extra-utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' +function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { + return updateCustomSubConfig(server.url, server.accessToken, { + search: { + searchIndex: { + enabled, + disableLocalSearch + } + } + }) +} + describe('Test videos API validator', function () { let server: ServerInfo @@ -18,6 +36,7 @@ describe('Test videos API validator', function () { this.timeout(30000) server = await flushAndRunServer(1) + await setAccessTokensToServers([ server ]) }) describe('When searching videos', function () { @@ -144,6 +163,62 @@ describe('Test videos API validator', function () { }) }) + describe('Search target', function () { + + it('Should fail/succeed depending on the search target', async function () { + this.timeout(10000) + + const query = { search: 'coucou' } + const paths = [ + '/api/v1/search/video-channels/', + '/api/v1/search/videos/' + ] + + for (const path of paths) { + { + const customQuery = immutableAssign(query, { searchTarget: 'hello' }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) + } + + { + const customQuery = immutableAssign(query, { searchTarget: undefined }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) + } + + { + const customQuery = immutableAssign(query, { searchTarget: 'local' }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) + } + + { + const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) + } + + await updateSearchIndex(server, true, true) + + { + const customQuery = immutableAssign(query, { searchTarget: 'local' }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) + } + + { + const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) + } + + await updateSearchIndex(server, true, false) + + { + const customQuery = immutableAssign(query, { searchTarget: 'local' }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) + } + + await updateSearchIndex(server, false, false) + } + }) + }) + after(async function () { await cleanupTests([ server ]) }) -- cgit v1.2.3