|
| 1 | +var test = require('tape') |
| 2 | + , getSchema = require('./helpers').getSchema |
| 3 | + , convert = require('../') |
| 4 | +; |
| 5 | + |
| 6 | +test('invalid types', function(assert) { |
| 7 | + var schema, msg; |
| 8 | + |
| 9 | + assert.plan(3); |
| 10 | + |
| 11 | + schema = { |
| 12 | + type: 'dateTime' |
| 13 | + }; |
| 14 | + |
| 15 | + msg = 'dateTime is invalid type'; |
| 16 | + assert.throws(function() { convert(schema); }, /InvalidTypeError/, msg); |
| 17 | + |
| 18 | + schema = { |
| 19 | + type: 'foo' |
| 20 | + }; |
| 21 | + |
| 22 | + msg = 'foo is invalid type'; |
| 23 | + assert.throws(function() { convert(schema); }, /InvalidTypeError/, msg); |
| 24 | + |
| 25 | + schema = getSchema('schema-2-invalid-type.json'); |
| 26 | + |
| 27 | + msg = 'invalid type inside complex schema'; |
| 28 | + assert.throws(function() { convert(schema); }, /InvalidTypeError.*invalidtype/, msg); |
| 29 | +}); |
| 30 | + |
| 31 | +test('valid types', function(assert) { |
| 32 | + var types = ['integer', 'number', 'string', 'boolean', 'object', 'array']; |
| 33 | + |
| 34 | + assert.plan(types.length); |
| 35 | + |
| 36 | + types.forEach(function(type) { |
| 37 | + var schema, result, expected; |
| 38 | + |
| 39 | + schema = { |
| 40 | + type: type |
| 41 | + }; |
| 42 | + |
| 43 | + result = convert(schema); |
| 44 | + |
| 45 | + expected = { |
| 46 | + $schema: 'http://json-schema.org/draft-04/schema#', |
| 47 | + type: type, |
| 48 | + }; |
| 49 | + |
| 50 | + assert.deepEqual(result, expected, type + ' ok'); |
| 51 | + }); |
| 52 | +}); |
0 commit comments