diff options
Diffstat (limited to 'server/tests/api/check-params/search.ts')
-rw-r--r-- | server/tests/api/check-params/search.ts | 201 |
1 files changed, 119 insertions, 82 deletions
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 20ad46cff..cc15d2593 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts | |||
@@ -2,41 +2,39 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { | 4 | import { |
5 | checkBadCountPagination, | ||
6 | checkBadSortPagination, | ||
7 | checkBadStartPagination, | ||
5 | cleanupTests, | 8 | cleanupTests, |
6 | flushAndRunServer, | 9 | createSingleServer, |
7 | immutableAssign, | ||
8 | makeGetRequest, | 10 | makeGetRequest, |
9 | ServerInfo, | 11 | PeerTubeServer, |
10 | updateCustomSubConfig, | ||
11 | setAccessTokensToServers | 12 | setAccessTokensToServers |
12 | } from '../../../../shared/extra-utils' | 13 | } from '@shared/extra-utils' |
13 | import { | 14 | import { HttpStatusCode } from '@shared/models' |
14 | checkBadCountPagination, | 15 | |
15 | checkBadSortPagination, | 16 | function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) { |
16 | checkBadStartPagination | 17 | return server.config.updateCustomSubConfig({ |
17 | } from '../../../../shared/extra-utils/requests/check-api-params' | 18 | newConfig: { |
18 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 19 | search: { |
19 | 20 | searchIndex: { | |
20 | function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { | 21 | enabled, |
21 | return updateCustomSubConfig(server.url, server.accessToken, { | 22 | disableLocalSearch |
22 | search: { | 23 | } |
23 | searchIndex: { | ||
24 | enabled, | ||
25 | disableLocalSearch | ||
26 | } | 24 | } |
27 | } | 25 | } |
28 | }) | 26 | }) |
29 | } | 27 | } |
30 | 28 | ||
31 | describe('Test videos API validator', function () { | 29 | describe('Test videos API validator', function () { |
32 | let server: ServerInfo | 30 | let server: PeerTubeServer |
33 | 31 | ||
34 | // --------------------------------------------------------------- | 32 | // --------------------------------------------------------------- |
35 | 33 | ||
36 | before(async function () { | 34 | before(async function () { |
37 | this.timeout(30000) | 35 | this.timeout(30000) |
38 | 36 | ||
39 | server = await flushAndRunServer(1) | 37 | server = await createSingleServer(1) |
40 | await setAccessTokensToServers([ server ]) | 38 | await setAccessTokensToServers([ server ]) |
41 | }) | 39 | }) |
42 | 40 | ||
@@ -59,84 +57,104 @@ describe('Test videos API validator', function () { | |||
59 | await checkBadSortPagination(server.url, path, null, query) | 57 | await checkBadSortPagination(server.url, path, null, query) |
60 | }) | 58 | }) |
61 | 59 | ||
62 | it('Should success with the correct parameters', async function () { | 60 | it('Should succeed with the correct parameters', async function () { |
63 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) | 61 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) |
64 | }) | 62 | }) |
65 | 63 | ||
66 | it('Should fail with an invalid category', async function () { | 64 | it('Should fail with an invalid category', async function () { |
67 | const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) | 65 | const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] } |
68 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 66 | await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
69 | 67 | ||
70 | const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) | 68 | const customQuery2 = { ...query, categoryOneOf: 'a' } |
71 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 69 | await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
72 | }) | 70 | }) |
73 | 71 | ||
74 | it('Should succeed with a valid category', async function () { | 72 | it('Should succeed with a valid category', async function () { |
75 | const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) | 73 | const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] } |
76 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) | 74 | await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 }) |
77 | 75 | ||
78 | const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) | 76 | const customQuery2 = { ...query, categoryOneOf: 1 } |
79 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) | 77 | await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 }) |
80 | }) | 78 | }) |
81 | 79 | ||
82 | it('Should fail with an invalid licence', async function () { | 80 | it('Should fail with an invalid licence', async function () { |
83 | const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) | 81 | const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] } |
84 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 82 | await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
85 | 83 | ||
86 | const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) | 84 | const customQuery2 = { ...query, licenceOneOf: 'a' } |
87 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 85 | await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
88 | }) | 86 | }) |
89 | 87 | ||
90 | it('Should succeed with a valid licence', async function () { | 88 | it('Should succeed with a valid licence', async function () { |
91 | const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) | 89 | const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] } |
92 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) | 90 | await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 }) |
93 | 91 | ||
94 | const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) | 92 | const customQuery2 = { ...query, licenceOneOf: 1 } |
95 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) | 93 | await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 }) |
96 | }) | 94 | }) |
97 | 95 | ||
98 | it('Should succeed with a valid language', async function () { | 96 | it('Should succeed with a valid language', async function () { |
99 | const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) | 97 | const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] } |
100 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) | 98 | await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 }) |
101 | 99 | ||
102 | const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) | 100 | const customQuery2 = { ...query, languageOneOf: 'fr' } |
103 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) | 101 | await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 }) |
104 | }) | 102 | }) |
105 | 103 | ||
106 | it('Should succeed with valid tags', async function () { | 104 | it('Should succeed with valid tags', async function () { |
107 | const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) | 105 | const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] } |
108 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) | 106 | await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 }) |
109 | 107 | ||
110 | const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) | 108 | const customQuery2 = { ...query, tagsOneOf: 'tag1' } |
111 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) | 109 | await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 }) |
112 | 110 | ||
113 | const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) | 111 | const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] } |
114 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) | 112 | await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.OK_200 }) |
115 | 113 | ||
116 | const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) | 114 | const customQuery4 = { ...query, tagsAllOf: 'tag1' } |
117 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) | 115 | await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.OK_200 }) |
118 | }) | 116 | }) |
119 | 117 | ||
120 | it('Should fail with invalid durations', async function () { | 118 | it('Should fail with invalid durations', async function () { |
121 | const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) | 119 | const customQuery1 = { ...query, durationMin: 'hello' } |
122 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 120 | await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
123 | 121 | ||
124 | const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) | 122 | const customQuery2 = { ...query, durationMax: 'hello' } |
125 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 123 | await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
126 | }) | 124 | }) |
127 | 125 | ||
128 | it('Should fail with invalid dates', async function () { | 126 | it('Should fail with invalid dates', async function () { |
129 | const customQuery1 = immutableAssign(query, { startDate: 'hello' }) | 127 | const customQuery1 = { ...query, startDate: 'hello' } |
130 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 128 | await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
129 | |||
130 | const customQuery2 = { ...query, endDate: 'hello' } | ||
131 | await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
132 | |||
133 | const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' } | ||
134 | await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
135 | |||
136 | const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' } | ||
137 | await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
138 | }) | ||
139 | |||
140 | it('Should fail with an invalid host', async function () { | ||
141 | const customQuery = { ...query, host: '6565' } | ||
142 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
143 | }) | ||
131 | 144 | ||
132 | const customQuery2 = immutableAssign(query, { endDate: 'hello' }) | 145 | it('Should succeed with a host', async function () { |
133 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 146 | const customQuery = { ...query, host: 'example.com' } |
147 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) | ||
148 | }) | ||
134 | 149 | ||
135 | const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) | 150 | it('Should fail with invalid uuids', async function () { |
136 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 151 | const customQuery = { ...query, uuids: [ '6565', 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } |
152 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
153 | }) | ||
137 | 154 | ||
138 | const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) | 155 | it('Should succeed with valid uuids', async function () { |
139 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 156 | const customQuery = { ...query, uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } |
157 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) | ||
140 | }) | 158 | }) |
141 | }) | 159 | }) |
142 | 160 | ||
@@ -144,7 +162,8 @@ describe('Test videos API validator', function () { | |||
144 | const path = '/api/v1/search/video-playlists/' | 162 | const path = '/api/v1/search/video-playlists/' |
145 | 163 | ||
146 | const query = { | 164 | const query = { |
147 | search: 'coucou' | 165 | search: 'coucou', |
166 | host: 'example.com' | ||
148 | } | 167 | } |
149 | 168 | ||
150 | it('Should fail with a bad start pagination', async function () { | 169 | it('Should fail with a bad start pagination', async function () { |
@@ -159,8 +178,17 @@ describe('Test videos API validator', function () { | |||
159 | await checkBadSortPagination(server.url, path, null, query) | 178 | await checkBadSortPagination(server.url, path, null, query) |
160 | }) | 179 | }) |
161 | 180 | ||
162 | it('Should success with the correct parameters', async function () { | 181 | it('Should fail with an invalid host', async function () { |
163 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) | 182 | await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
183 | }) | ||
184 | |||
185 | it('Should fail with invalid uuids', async function () { | ||
186 | const customQuery = { ...query, uuids: [ '6565', 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } | ||
187 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
188 | }) | ||
189 | |||
190 | it('Should succeed with the correct parameters', async function () { | ||
191 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) | ||
164 | }) | 192 | }) |
165 | }) | 193 | }) |
166 | 194 | ||
@@ -168,7 +196,8 @@ describe('Test videos API validator', function () { | |||
168 | const path = '/api/v1/search/video-channels/' | 196 | const path = '/api/v1/search/video-channels/' |
169 | 197 | ||
170 | const query = { | 198 | const query = { |
171 | search: 'coucou' | 199 | search: 'coucou', |
200 | host: 'example.com' | ||
172 | } | 201 | } |
173 | 202 | ||
174 | it('Should fail with a bad start pagination', async function () { | 203 | it('Should fail with a bad start pagination', async function () { |
@@ -183,8 +212,16 @@ describe('Test videos API validator', function () { | |||
183 | await checkBadSortPagination(server.url, path, null, query) | 212 | await checkBadSortPagination(server.url, path, null, query) |
184 | }) | 213 | }) |
185 | 214 | ||
186 | it('Should success with the correct parameters', async function () { | 215 | it('Should fail with an invalid host', async function () { |
187 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) | 216 | await makeGetRequest({ url: server.url, path, query: { ...query, host: '6565' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
217 | }) | ||
218 | |||
219 | it('Should fail with invalid handles', async function () { | ||
220 | await makeGetRequest({ url: server.url, path, query: { ...query, handles: [ '' ] }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
221 | }) | ||
222 | |||
223 | it('Should succeed with the correct parameters', async function () { | ||
224 | await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) | ||
188 | }) | 225 | }) |
189 | }) | 226 | }) |
190 | 227 | ||
@@ -202,42 +239,42 @@ describe('Test videos API validator', function () { | |||
202 | 239 | ||
203 | for (const path of paths) { | 240 | for (const path of paths) { |
204 | { | 241 | { |
205 | const customQuery = immutableAssign(query, { searchTarget: 'hello' }) | 242 | const customQuery = { ...query, searchTarget: 'hello' } |
206 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 243 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
207 | } | 244 | } |
208 | 245 | ||
209 | { | 246 | { |
210 | const customQuery = immutableAssign(query, { searchTarget: undefined }) | 247 | const customQuery = { ...query, searchTarget: undefined } |
211 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) | 248 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) |
212 | } | 249 | } |
213 | 250 | ||
214 | { | 251 | { |
215 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | 252 | const customQuery = { ...query, searchTarget: 'local' } |
216 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) | 253 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) |
217 | } | 254 | } |
218 | 255 | ||
219 | { | 256 | { |
220 | const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) | 257 | const customQuery = { ...query, searchTarget: 'search-index' } |
221 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 258 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
222 | } | 259 | } |
223 | 260 | ||
224 | await updateSearchIndex(server, true, true) | 261 | await updateSearchIndex(server, true, true) |
225 | 262 | ||
226 | { | 263 | { |
227 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | 264 | const customQuery = { ...query, searchTarget: 'local' } |
228 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | 265 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
229 | } | 266 | } |
230 | 267 | ||
231 | { | 268 | { |
232 | const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) | 269 | const customQuery = { ...query, searchTarget: 'search-index' } |
233 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) | 270 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) |
234 | } | 271 | } |
235 | 272 | ||
236 | await updateSearchIndex(server, true, false) | 273 | await updateSearchIndex(server, true, false) |
237 | 274 | ||
238 | { | 275 | { |
239 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | 276 | const customQuery = { ...query, searchTarget: 'local' } |
240 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) | 277 | await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) |
241 | } | 278 | } |
242 | 279 | ||
243 | await updateSearchIndex(server, false, false) | 280 | await updateSearchIndex(server, false, false) |