Skip to content

Commit e248cb2

Browse files
b808929 fix/response-status-property Add status property on ReponseType Add docs (#818)
Co-authored-by: Yaro <yaro@dream-it.es>
1 parent 945dea5 commit e248cb2

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
pull_request:
66
paths:
77
- '**/*.lua'
8+
- '**/*.ts'
89
branches:
910
- main
1011
- develop

docs/docs/scripts/response-reference.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ These helper functions are available in the response object in scripts.
44

55
## response.responseCode
66

7-
THe HTTP response code.
7+
The HTTP response code.
8+
9+
10+
## response.responseCode
11+
12+
The HTTP response code as status property
813

914
## response.body
1015

docs/docs/usage/testing-and-reporting.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ content-type: application/json
7676
client.test("Test suite name 2", function() {
7777
assert.hasString(json.occupation, "Develop", "Check if occupation contains Develop")
7878
assert.responseHas('responseCode', 200, "Check if response code is 200")
79+
assert.responseHas('status', 200, "Check if response status is 200")
7980
assert.headersHas('Content-Type', "application/json", "Check content type")
8081
});
8182
assert.jsonHas("json.data.occupation", "Developer", "Check json payload")

docs/static/import/demos/7.testing-and-reporting.http

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Content-Type: application/json
3232
client.test("Test suite 2", function() {
3333
assert.hasString(json.occupation, "Develop", "Check if occupation contains 'Develop'")
3434
assert.responseHas('responseCode', 200, "Check if response code is 200")
35+
assert.responseHas('status', 200, "Check if response status is 200")
3536
assert.headersHas('Content-Type', "application/json", "Check content type")
3637
});
3738

lua/kulala/parser/scripts/engines/javascript/lib/src/lib/PostRequestResponse.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ interface ResponseHeaders {
2828

2929
export interface ResponseType {
3030
responseCode: number;
31+
status: number;
3132
body: Body;
3233
headers: ResponseHeaders;
3334
contentType: object;
3435
}
3536

3637
let responseCode = 0;
38+
let status = 0;
3739
let body: Body = null;
3840
const headers: Headers = {};
3941

@@ -62,7 +64,9 @@ if (fs.existsSync(_RESPONSE_HEADERS_FILEPATH)) {
6264

6365
if (lines[0].length > 0) {
6466
const matches = lines[0].match(/HTTP\/\d(?:\.\d)?\s+(\d+)/);
65-
responseCode = ((matches?.[1]) != null) ? parseInt(matches[1], 10) : 0;
67+
const statusCode = ((matches?.[1]) != null) ? parseInt(matches[1], 10) : 0;
68+
responseCode = statusCode;
69+
status = statusCode;
6670
}
6771
}
6872

@@ -79,6 +83,7 @@ if (fs.existsSync(_RESPONSE_BODY_FILEPATH)) {
7983

8084
export const Response: ResponseType = {
8185
responseCode,
86+
status,
8287
body,
8388
headers: {
8489
valueOf: (headerName: string): string | null => {

0 commit comments

Comments
 (0)