From 500b0678c4e1610bc67199abe4f89b487a09f733 Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Tue, 7 Mar 2023 19:55:08 +0000 Subject: [PATCH] feat: added support for response headers --- features/support/support.js | 18 +++++++++++++++++- features/support/util.js | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/features/support/support.js b/features/support/support.js index fed1594..5a2ba76 100644 --- a/features/support/support.js +++ b/features/support/support.js @@ -62,7 +62,7 @@ When( ); When( - /calling the method ([a-zA-Z]*) and the server responds with/, + /calling the method ([a-zA-Z]*) and the server responds with$/, async (methodName, response) => { mock.serverResponseObject = JSON.parse(response); apiResponse = await api[methodName](); @@ -96,6 +96,22 @@ When("selecting the server at index {int}", (index) => { api = createApi(index); }); +When( + /calling the method ([a-zA-Z]*) and the server responds with headers$/, + async (methodName, headers) => { + mock.serverResponseObject = {}; + mock.serverResponseHeaders = JSON.parse(headers); + apiResponse = await api[methodName](); + } +); + +Then( + /the response should have a header (.*) with value (.*)/, + (prop, value) => { + assert.equal(apiResponse.headers[prop], value); + } +); + Then(/the request method should be of type (.*)/, (type) => { assert.equal(mock.requestParams.method, type); }); diff --git a/features/support/util.js b/features/support/util.js index 4863029..09a0edd 100644 --- a/features/support/util.js +++ b/features/support/util.js @@ -20,6 +20,7 @@ async function generateApi(schema) { let mock = { serverResponse: undefined, + serverResponseHeaders: undefined, }; function createApi(serverIndex = 0) { @@ -29,7 +30,8 @@ function createApi(serverIndex = 0) { const mockTransport = async (params) => { mock.requestParams = params; return { - data: mock.serverResponseObject + data: mock.serverResponseObject, + headers: mock.serverResponseHeaders, }; };