aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorFlorent <florent.git@zeteo.me>2022-08-11 17:24:23 +0200
committerChocobozzz <chocobozzz@cpy.re>2022-08-16 10:00:04 +0200
commitcbdbee807ddc202901fd61f1af4ca2988d2268b5 (patch)
tree455d6005b5b4d01389cd8a33926a36cc52aa9f26 /shared
parent76ab0208dba043d837db835cf5ed390f718fd956 (diff)
downloadPeerTube-cbdbee807ddc202901fd61f1af4ca2988d2268b5.tar.gz
PeerTube-cbdbee807ddc202901fd61f1af4ca2988d2268b5.tar.zst
PeerTube-cbdbee807ddc202901fd61f1af4ca2988d2268b5.zip
Tests: Add response error along with unexpected status in report
Diffstat (limited to 'shared')
-rw-r--r--shared/server-commands/requests/requests.ts11
1 files changed, 9 insertions, 2 deletions
diff --git a/shared/server-commands/requests/requests.ts b/shared/server-commands/requests/requests.ts
index a08a6e0b9..85cbc9be9 100644
--- a/shared/server-commands/requests/requests.ts
+++ b/shared/server-commands/requests/requests.ts
@@ -172,7 +172,6 @@ function buildRequest (req: request.Test, options: CommonRequestParams) {
172 if (options.accept) req.set('Accept', options.accept) 172 if (options.accept) req.set('Accept', options.accept)
173 if (options.host) req.set('Host', options.host) 173 if (options.host) req.set('Host', options.host)
174 if (options.redirects) req.redirects(options.redirects) 174 if (options.redirects) req.redirects(options.redirects)
175 if (options.expectedStatus) req.expect(options.expectedStatus)
176 if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor) 175 if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor)
177 if (options.type) req.type(options.type) 176 if (options.type) req.type(options.type)
178 177
@@ -180,7 +179,15 @@ function buildRequest (req: request.Test, options: CommonRequestParams) {
180 req.set(name, options.headers[name]) 179 req.set(name, options.headers[name])
181 }) 180 })
182 181
183 return req 182 return req.expect((res) => {
183 if (options.expectedStatus && res.status !== options.expectedStatus) {
184 throw new Error(`Expected status ${options.expectedStatus}, got ${res.status}. ` +
185 `\nThe server responded this error: "${res.body?.error ?? res.text}".\n` +
186 'You may take a closer look at the logs. To see how to do so, check out this page: ' +
187 'https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/development/tests.md#debug-server-logs')
188 }
189 return res
190 })
184} 191}
185 192
186function buildFields (req: request.Test, fields: { [ fieldName: string ]: any }, namespace?: string) { 193function buildFields (req: request.Test, fields: { [ fieldName: string ]: any }, namespace?: string) {