diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-09 16:39:45 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-10 14:02:41 +0200 |
commit | 3b0bd70aa05ab82fa30fe67ed4899d44652c703a (patch) | |
tree | 662655e40f0a4263f1d3ab457d9970c344e8bbb0 /server/tests/api/check-params/search.ts | |
parent | 7c87746e4b336e547b1917f274c9a0bdc4d1d3df (diff) | |
download | PeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.tar.gz PeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.tar.zst PeerTube-3b0bd70aa05ab82fa30fe67ed4899d44652c703a.zip |
Add search target check params
Diffstat (limited to 'server/tests/api/check-params/search.ts')
-rw-r--r-- | server/tests/api/check-params/search.ts | 79 |
1 files changed, 77 insertions, 2 deletions
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 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | import { | |
5 | import { cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo } from '../../../../shared/extra-utils' | 5 | cleanupTests, |
6 | flushAndRunServer, | ||
7 | immutableAssign, | ||
8 | makeGetRequest, | ||
9 | ServerInfo, | ||
10 | updateCustomSubConfig, | ||
11 | setAccessTokensToServers | ||
12 | } from '../../../../shared/extra-utils' | ||
6 | import { | 13 | import { |
7 | checkBadCountPagination, | 14 | checkBadCountPagination, |
8 | checkBadSortPagination, | 15 | checkBadSortPagination, |
9 | checkBadStartPagination | 16 | checkBadStartPagination |
10 | } from '../../../../shared/extra-utils/requests/check-api-params' | 17 | } from '../../../../shared/extra-utils/requests/check-api-params' |
11 | 18 | ||
19 | function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { | ||
20 | return updateCustomSubConfig(server.url, server.accessToken, { | ||
21 | search: { | ||
22 | searchIndex: { | ||
23 | enabled, | ||
24 | disableLocalSearch | ||
25 | } | ||
26 | } | ||
27 | }) | ||
28 | } | ||
29 | |||
12 | describe('Test videos API validator', function () { | 30 | describe('Test videos API validator', function () { |
13 | let server: ServerInfo | 31 | let server: ServerInfo |
14 | 32 | ||
@@ -18,6 +36,7 @@ describe('Test videos API validator', function () { | |||
18 | this.timeout(30000) | 36 | this.timeout(30000) |
19 | 37 | ||
20 | server = await flushAndRunServer(1) | 38 | server = await flushAndRunServer(1) |
39 | await setAccessTokensToServers([ server ]) | ||
21 | }) | 40 | }) |
22 | 41 | ||
23 | describe('When searching videos', function () { | 42 | describe('When searching videos', function () { |
@@ -144,6 +163,62 @@ describe('Test videos API validator', function () { | |||
144 | }) | 163 | }) |
145 | }) | 164 | }) |
146 | 165 | ||
166 | describe('Search target', function () { | ||
167 | |||
168 | it('Should fail/succeed depending on the search target', async function () { | ||
169 | this.timeout(10000) | ||
170 | |||
171 | const query = { search: 'coucou' } | ||
172 | const paths = [ | ||
173 | '/api/v1/search/video-channels/', | ||
174 | '/api/v1/search/videos/' | ||
175 | ] | ||
176 | |||
177 | for (const path of paths) { | ||
178 | { | ||
179 | const customQuery = immutableAssign(query, { searchTarget: 'hello' }) | ||
180 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) | ||
181 | } | ||
182 | |||
183 | { | ||
184 | const customQuery = immutableAssign(query, { searchTarget: undefined }) | ||
185 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) | ||
186 | } | ||
187 | |||
188 | { | ||
189 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | ||
190 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) | ||
191 | } | ||
192 | |||
193 | { | ||
194 | const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) | ||
195 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) | ||
196 | } | ||
197 | |||
198 | await updateSearchIndex(server, true, true) | ||
199 | |||
200 | { | ||
201 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | ||
202 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) | ||
203 | } | ||
204 | |||
205 | { | ||
206 | const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) | ||
207 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) | ||
208 | } | ||
209 | |||
210 | await updateSearchIndex(server, true, false) | ||
211 | |||
212 | { | ||
213 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | ||
214 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) | ||
215 | } | ||
216 | |||
217 | await updateSearchIndex(server, false, false) | ||
218 | } | ||
219 | }) | ||
220 | }) | ||
221 | |||
147 | after(async function () { | 222 | after(async function () { |
148 | await cleanupTests([ server ]) | 223 | await cleanupTests([ server ]) |
149 | }) | 224 | }) |