Skip to content

Instantly share code, notes, and snippets.

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',
And every element on "body.data" property has "interface"
| type | string |
| description | string |
| location | string |
| distance | number |
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)
})
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',
function checkTypeWith (input, model) {
return key => {
const expectedType = model[key]
return /^array$/.test(expectedType)
? Array.isArray(input[key])
: typeof input[key] === model[key]
}
}
function checkTypeWith (input, model) {
return key => {
if (/^array$/.test(model[key])) {
return Array.isArray(input[key])
} else {
return typeof input[key] === model[key]
}
}
}
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',
function isValidInterface (input, model) {
return Object.keys(input).every(checkTypeWith(input, model))
}
function checkTypeWith (input, model) {
return key => typeof input[key] === model[key]
}
function isValidInterface (input, model) {
const keys = Object.keys(input)
const isValid = keys.every((key) => typeof input[key] === model[key])
return isValid
}
module.exports = {
isValidInterface
}
function isValidInterface () {
}