Skip to content

Instantly share code, notes, and snippets.

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 complyWith (input, restrictions) {
const formattedRestrictions = substituteOperators(restrictions)
return Array.isArray(input)
? input.every(element => formattedRestrictions.every(applyOperator(element)))
: formattedRestrictions.every(applyOperator(input))
}
function complyWith (input, restrictions) {
const formattedRestrictions = substituteOperators(restrictions)
return formattedRestrictions.every(applyOperator(input))
}
function applyOperator (input) {
return restriction => {
const value = input[restriction.property]
return restriction.operator(value, restriction.value)
}
function substituteOperators (restrictions) {
const operators = {
'less than': (a, b) => a < b
}
return restrictions.map(substituteOperator(operators))
}
function substituteOperator (operators) {
return restriction => {
restriction.operator = operators[restriction.operator]
function substituteOperators (restrictions) {
const operators = {
'less than': (a, b) => a < b
}
return restrictions.map(restriction => {
restriction.operator = operators[restriction.operator]
return restriction
})
}
test('substituteOperators() should map operator property with the correct method', function ({ deepEqual, end }) {
const restrictions = [{ property: 'distance', operator: 'less than', value: '200' }]
const restriction = substituteOperators(restrictions)[0]
{
const actual = restriction.operator(1, 2) // Start with one assertion
const expected = true
deepEqual(actual, expected)
}
{
const actual = restriction.operator(2, 2) // keep making assertions
test('complyWith() should take an input object and some restrictions and check that the input complies with those', function ({ deepEqual, end }) {
const restrictions = [{ property: 'distance', operator: 'less than', value: '200' }]
const data = {
distance: 100
}
const actual = complyWith(data, restrictions)
const expected = true
deepEqual(actual, expected)
end()
})
defineStep('every element on {string} property has {string}', async function (property, option, table) {
const propFromResponse = get(this.response, property, {})
if (option === 'interface') {
const model = table.rowsHash() // to format a table of 2 columns
const actual = isValidInterface(propFromResponse, model)
const expected = true
deepStrictEqual(actual, expected)
function isValidInterface (input, model) {
return Array.isArray(input)
? input.every(element => isObjectValidInterface(element, model))
: isObjectValidInterface(input, model)
}
function isObjectValidInterface (input, model) {
return Object.keys(input).every(checkTypeWith(input, model))
}
function isValidInterface (input, model) {
return Array.isArray(input)
? input.every(element => Object.keys(element).every(checkTypeWith(element, model)))
: Object.keys(input).every(checkTypeWith(input, model))
}