Skip to content

Commit 500b067

Browse files
feat: added support for response headers
1 parent 7d00685 commit 500b067

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

features/support/support.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ When(
6262
);
6363

6464
When(
65-
/calling the method ([a-zA-Z]*) and the server responds with/,
65+
/calling the method ([a-zA-Z]*) and the server responds with$/,
6666
async (methodName, response) => {
6767
mock.serverResponseObject = JSON.parse(response);
6868
apiResponse = await api[methodName]();
@@ -96,6 +96,22 @@ When("selecting the server at index {int}", (index) => {
9696
api = createApi(index);
9797
});
9898

99+
When(
100+
/calling the method ([a-zA-Z]*) and the server responds with headers$/,
101+
async (methodName, headers) => {
102+
mock.serverResponseObject = {};
103+
mock.serverResponseHeaders = JSON.parse(headers);
104+
apiResponse = await api[methodName]();
105+
}
106+
);
107+
108+
Then(
109+
/the response should have a header (.*) with value (.*)/,
110+
(prop, value) => {
111+
assert.equal(apiResponse.headers[prop], value);
112+
}
113+
);
114+
99115
Then(/the request method should be of type (.*)/, (type) => {
100116
assert.equal(mock.requestParams.method, type);
101117
});

features/support/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async function generateApi(schema) {
2020

2121
let mock = {
2222
serverResponse: undefined,
23+
serverResponseHeaders: undefined,
2324
};
2425

2526
function createApi(serverIndex = 0) {
@@ -29,7 +30,8 @@ function createApi(serverIndex = 0) {
2930
const mockTransport = async (params) => {
3031
mock.requestParams = params;
3132
return {
32-
data: mock.serverResponseObject
33+
data: mock.serverResponseObject,
34+
headers: mock.serverResponseHeaders,
3335
};
3436
};
3537

0 commit comments

Comments
 (0)