Skip to content

Commit

Permalink
fix(http-api): fix http api extension step definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Apr 12, 2018
1 parent f968b3b commit a353710
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ httpApi.install({
```yaml
Given:
- /^(?:I )?set request headers$/
- /^(?:I )? do not follow redirect$/
- /^(?:I )? follow redirect$/
- /^(?:I )?do not follow redirect$/
- /^(?:I )?follow redirect$/
- /^(?:I )?assign request headers$/
- /^(?:I )?set ([a-zA-Z0-9-]+) request header to (.+)$/
- /^(?:I )?clear request headers/
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/http_api/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ module.exports = ({ baseUrl = '' } = {}) => ({ Given, When, Then }) => {
/**
* Setting http option followRedirect to false
*/
Given(/^(?:I )? do not follow redirect$/, function() {
Given(/^(?:I )?do not follow redirect$/, function() {
this.httpApiClient.setFollowRedirect(false)
})

/**
* Setting http option followRedirect to true
*/
Given(/^(?:I )? follow redirect$/, function() {
Given(/^(?:I )?follow redirect$/, function() {
this.httpApiClient.setFollowRedirect(true)
})

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 @@ -211,6 +211,36 @@ test('set request query', () => {
expect(clientMock.httpApiClient.setQuery).toHaveBeenCalledWith(query)
})

test('follow redirect', () => {
const context = helper.define(definitions)

const def = context.getDefinitionByMatcher('?follow redirect')
def.shouldHaveType('Given')
def.shouldMatch('I follow redirect')
def.shouldMatch('follow redirect')

const clientMock = {
httpApiClient: { setFollowRedirect: jest.fn() }
}
def.exec(clientMock)
expect(clientMock.httpApiClient.setFollowRedirect).toHaveBeenCalledWith(true)
})

test('do not follow redirect', () => {
const context = helper.define(definitions)

const def = context.getDefinitionByMatcher('do not follow redirect')
def.shouldHaveType('Given')
def.shouldMatch('I do not follow redirect')
def.shouldMatch('do not follow redirect')

const clientMock = {
httpApiClient: { setFollowRedirect: jest.fn() }
}
def.exec(clientMock)
expect(clientMock.httpApiClient.setFollowRedirect).toHaveBeenCalledWith(false)
})

test('pick response json property', () => {
const context = helper.define(definitions)

Expand Down

0 comments on commit a353710

Please sign in to comment.