|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const test = require('tap').test |
| 4 | +const validator = require('is-my-json-valid') |
| 5 | +const proxyquire = require('proxyquire') |
| 6 | +const build = proxyquire('..', { long: null }) |
| 7 | + |
| 8 | +test(`render an integer as JSON`, (t) => { |
| 9 | + t.plan(2) |
| 10 | + |
| 11 | + const schema = { |
| 12 | + title: 'integer', |
| 13 | + type: 'integer' |
| 14 | + } |
| 15 | + |
| 16 | + const validate = validator(schema) |
| 17 | + const stringify = build(schema) |
| 18 | + const output = stringify(1615) |
| 19 | + |
| 20 | + t.equal(output, '1615') |
| 21 | + t.ok(validate(JSON.parse(output)), 'valid schema') |
| 22 | +}) |
| 23 | + |
| 24 | +test(`render an object with an integer as JSON`, (t) => { |
| 25 | + t.plan(2) |
| 26 | + |
| 27 | + const schema = { |
| 28 | + title: 'object with integer', |
| 29 | + type: 'object', |
| 30 | + properties: { |
| 31 | + id: { |
| 32 | + type: 'integer' |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + const validate = validator(schema) |
| 38 | + const stringify = build(schema) |
| 39 | + const output = stringify({ |
| 40 | + id: 1615 |
| 41 | + }) |
| 42 | + |
| 43 | + t.equal(output, '{"id":1615}') |
| 44 | + t.ok(validate(JSON.parse(output)), 'valid schema') |
| 45 | +}) |
| 46 | + |
| 47 | +test(`render an array with an integer as JSON`, (t) => { |
| 48 | + t.plan(2) |
| 49 | + |
| 50 | + const schema = { |
| 51 | + title: 'array with integer', |
| 52 | + type: 'array', |
| 53 | + items: { |
| 54 | + type: 'integer' |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + const validate = validator(schema) |
| 59 | + const stringify = build(schema) |
| 60 | + const output = stringify([1615]) |
| 61 | + |
| 62 | + t.equal(output, '[1615]') |
| 63 | + t.ok(validate(JSON.parse(output)), 'valid schema') |
| 64 | +}) |
| 65 | + |
| 66 | +test(`render an object with an additionalProperty of type integer as JSON`, (t) => { |
| 67 | + t.plan(2) |
| 68 | + |
| 69 | + const schema = { |
| 70 | + title: 'object with integer', |
| 71 | + type: 'object', |
| 72 | + additionalProperties: { |
| 73 | + type: 'integer' |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + const validate = validator(schema) |
| 78 | + const stringify = build(schema) |
| 79 | + const output = stringify({ |
| 80 | + num: 1615 |
| 81 | + }) |
| 82 | + |
| 83 | + t.equal(output, '{"num":1615}') |
| 84 | + t.ok(validate(JSON.parse(output)), 'valid schema') |
| 85 | +}) |
0 commit comments