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 complyWith (input, restrictions) { | |
const formattedRestrictions = substituteOperators(restrictions) | |
return Array.isArray(input) | |
? input.every(element => formattedRestrictions.every(applyOperator(element))) | |
: formattedRestrictions.every(applyOperator(input)) | |
} |
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 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) | |
} |
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 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] |
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 substituteOperators (restrictions) { | |
const operators = { | |
'less than': (a, b) => a < b | |
} | |
return restrictions.map(restriction => { | |
restriction.operator = operators[restriction.operator] | |
return restriction | |
}) | |
} |
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('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 |
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('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() | |
}) |
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('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) |
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 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)) | |
} |
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 isValidInterface (input, model) { | |
return Array.isArray(input) | |
? input.every(element => Object.keys(element).every(checkTypeWith(element, model))) | |
: Object.keys(input).every(checkTypeWith(input, model)) | |
} |