Skip to content

Commit

Permalink
feat(http): allow headers with underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
fthouraud committed Aug 24, 2020
1 parent d6953b3 commit c91ef51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/extensions/http_api/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exports.install = ({ baseUrl = '' } = {}) => {
/**
* Setting a single http header
*/
Given(/^(?:I )?set ([a-zA-Z0-9-]+) request header to (.+)$/, function (key, value) {
Given(/^(?:I )?set ([a-zA-Z0-9-_]+) request header to (.+)$/, function (key, value) {
this.httpApiClient.setHeader(key, Cast.value(this.state.populate(value)))
})

Expand Down
30 changes: 30 additions & 0 deletions tests/extensions/http_api/definitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,36 @@ test('set a single request header', () => {
expect(clientMock.httpApiClient.setHeader).toHaveBeenCalledWith('Accept', 'test')
})

test('set a single request header with a dash', () => {
const context = helper.getContext() // Extension context

const def = context.getDefinitionByMatcher('request header to')
def.shouldMatch('I set X-Custom request header to test', ['X-Custom', 'test'])
def.shouldMatch('set X-Custom request header to test', ['X-Custom', 'test'])

const clientMock = {
httpApiClient: { setHeader: jest.fn() },
state: { populate: (v) => v },
}
def.exec(clientMock, 'X-Custom', 'test')
expect(clientMock.httpApiClient.setHeader).toHaveBeenCalledWith('X-Custom', 'test')
})

test('set a single request header with an underscore', () => {
const context = helper.getContext() // Extension context

const def = context.getDefinitionByMatcher('request header to')
def.shouldMatch('I set X_Custom request header to test', ['X_Custom', 'test'])
def.shouldMatch('set X_Custom request header to test', ['X_Custom', 'test'])

const clientMock = {
httpApiClient: { setHeader: jest.fn() },
state: { populate: (v) => v },
}
def.exec(clientMock, 'X_Custom', 'test')
expect(clientMock.httpApiClient.setHeader).toHaveBeenCalledWith('X_Custom', 'test')
})

test('clear request headers', () => {
const context = helper.getContext() // Extension context

Expand Down

0 comments on commit c91ef51

Please sign in to comment.