homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge
86 lines (68 loc) • 1.74 kB
JavaScript
const test = require('tap').test
const validator = require('is-my-json-valid')
const proxyquire = require('proxyquire')
const build = proxyquire('..', { long: null })
test('render an integer as JSON', (t) => {
t.plan(2)
const schema = {
title: 'integer',
type: 'integer'
}
const validate = validator(schema)
const stringify = build(schema)
const output = stringify(1615)
t.equal(output, '1615')
t.ok(validate(JSON.parse(output)), 'valid schema')
})
test('render an object with an integer as JSON', (t) => {
t.plan(2)
const schema = {
title: 'object with integer',
type: 'object',
properties: {
id: {
type: 'integer'
}
}
}
const validate = validator(schema)
const stringify = build(schema)
const output = stringify({
id: 1615
})
t.equal(output, '{"id":1615}')
t.ok(validate(JSON.parse(output)), 'valid schema')
})
test('render an array with an integer as JSON', (t) => {
t.plan(2)
const schema = {
title: 'array with integer',
type: 'array',
items: {
type: 'integer'
}
}
const validate = validator(schema)
const stringify = build(schema)
const output = stringify([1615])
t.equal(output, '[1615]')
t.ok(validate(JSON.parse(output)), 'valid schema')
})
test('render an object with an additionalProperty of type integer as JSON', (t) => {
t.plan(2)
const schema = {
title: 'object with integer',
type: 'object',
additionalProperties: {
type: 'integer'
}
}
const validate = validator(schema)
const stringify = build(schema)
const output = stringify({
num: 1615
})
t.equal(output, '{"num":1615}')
t.ok(validate(JSON.parse(output)), 'valid schema')
})