This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defineStep('I make a {string} request to {string}', async function (method, endpoint) { | |
| const headers = this.headers | |
| const uri = new URL(endpoint, process.env.HOST) | |
| const options = { headers, method } | |
| this.response = await got(uri, options) | |
| this.response.body = JSON.parse(get(this.response, 'body', '{}')) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function applyFilters (filters) { | |
| return data => data.filter(element => filters.every(filter => filter(element))) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { result } = await pipe( | |
| composeRequest, | |
| makeRequest, | |
| mapResponse, | |
| setWith('data.mappedResponse', applyFilters(config.filters)), | |
| createResult | |
| )(lift(config)) | |
| test('applyFilters() should apply filters to every element in the array passed', async function ({ deepEqual, end }) { | |
| const filters = [(element) => element.x < 4] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setWith (path, modifier) { | |
| return payload => { | |
| const newPayload = cloneDeep(payload) | |
| const data = get(newPayload, path) | |
| return set(newPayload, path, modifier(data)) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test('setWith() takes a path and a function', async function ({ deepEqual, end }) { | |
| const payload = { | |
| event: { | |
| body: '{"a": 1, "foo": "bar"}' | |
| } | |
| } | |
| const result = setWith('event.body', JSON.parse)(deepFreeze(payload)) | |
| const actual = result.event.body | |
| const expected = { a: 1, foo: 'bar' } | |
| deepEqual(actual, expected, 'applies JSON.parse to the value assigned to that path') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test('filterResponse() should apply filters specified in config object to mappedResponse', async function ({ deepEqual, end }) { | |
| const payload = { | |
| data: { | |
| config: { | |
| filters: [ | |
| (element) => element.x < 4 | |
| ] | |
| }, | |
| mappedResponse: [ | |
| { x: 1, y: 2 }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function doSomething (payload) { | |
| const newPayload = cloneDeep(payload) // cloning to avoid mutations on source | |
| const result = composeResult(newPayload) // doing something | |
| // set the result in a path | |
| return set(newPayload, 'my.path', result) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature: Stores | |
| As a consumer of the API, | |
| I want to be able to perform CRUD operations on stores endpoints | |
| Scenario: Successfully get a list of stores near me | |
| Given request headers | |
| | content-type | application/json | | |
| When I make a "GET" request to "stores" | |
| Then I receive a 200 status code response | |
| And every element on "body" property has "interface" | |
| | metadata | object | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function filterResponse (payload) { | |
| const newPayload = cloneDeep(payload) | |
| const data = get(newPayload, 'data.mappedResponse', []) | |
| const filters = get(newPayload, 'data.config.filters', []) | |
| const filtered = data.filter(element => filters.every(filter => filter(element))) | |
| return set(newPayload, 'data.mappedResponse', filtered) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test('filterResponse() should apply filters specified in config object to mappedResponse', async function ({ deepEqual, end }) { | |
| const payload = { | |
| data: { | |
| config: { | |
| filters: [ | |
| (element) => element.x < 4 | |
| ] | |
| }, | |
| mappedResponse: [ | |
| { x: 1, y: 2 }, |
NewerOlder