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('isValidInterface() should take an interface model and an input Array and check for type matching for each element', function ({ deepEqual, end }) { | |
const model = { | |
a: 'string', | |
b: 'object', | |
c: 'boolean', | |
d: 'number', | |
e: 'array' | |
} | |
const data = [{ | |
a: 'foo', |
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
And every element on "body.data" property has "interface" | |
| type | string | | |
| description | string | | |
| location | string | | |
| distance | number | |
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 get = require('lodash.get') | |
defineStep('{string} property has more than {int} element', async function (property, number) { | |
const propFromResponse = get(this.response, property, []) | |
const actual = propFromResponse.length > number | |
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
test('isValidInterface() should take an interface model and an input object and check for type matching', function ({ deepEqual, end }) { | |
const model = { | |
a: 'string', | |
b: 'object', | |
c: 'boolean', | |
d: 'number', | |
e: 'array' | |
} | |
const data = { | |
a: 'foo', |
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 checkTypeWith (input, model) { | |
return key => { | |
const expectedType = model[key] | |
return /^array$/.test(expectedType) | |
? Array.isArray(input[key]) | |
: typeof input[key] === model[key] | |
} | |
} |
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 checkTypeWith (input, model) { | |
return key => { | |
if (/^array$/.test(model[key])) { | |
return Array.isArray(input[key]) | |
} else { | |
return typeof input[key] === model[key] | |
} | |
} | |
} |
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('isValidInterface() should take an interface model and an input object and check for type matching, with arrays', function ({ deepEqual, end }) { | |
const model = { | |
a: 'string', | |
b: 'object', | |
c: 'boolean', | |
d: 'number', | |
e: 'array' | |
} | |
const data = { | |
a: 'foo', |
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 Object.keys(input).every(checkTypeWith(input, model)) | |
} | |
function checkTypeWith (input, model) { | |
return key => typeof input[key] === model[key] | |
} |
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) { | |
const keys = Object.keys(input) | |
const isValid = keys.every((key) => typeof input[key] === model[key]) | |
return isValid | |
} |
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
module.exports = { | |
isValidInterface | |
} | |
function isValidInterface () { | |
} |