Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

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', '{}'))
})
function applyFilters (filters) {
return data => data.filter(element => filters.every(filter => filter(element)))
}
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]
function setWith (path, modifier) {
return payload => {
const newPayload = cloneDeep(payload)
const data = get(newPayload, path)
return set(newPayload, path, modifier(data))
}
}
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')
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 },
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)
}
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 |
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)
}
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 },