|
| 1 | +var Ajv = require('ajv'); |
| 2 | +var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true} |
| 3 | +var ReactionsType = require('../common/types-reactions'); |
| 4 | +var ApiType = require('../common/types-api'); |
| 5 | +var PostType = require('../common/types-post') |
| 6 | +var fixture = require('./fixture-api.js'); |
| 7 | +describe('types', function() { |
| 8 | + |
| 9 | + describe('reactions', function() { |
| 10 | + it('validate reaction types ', function () { |
| 11 | + var reactions = _.cloneDeep(fixture["1480348800000_1480435199999"].reactions); |
| 12 | + var isValid = ajv.validate(ReactionsType.schema, reactions); |
| 13 | + console.error(ajv.errors); |
| 14 | + expect(isValid).to.be.true; |
| 15 | + }); |
| 16 | + it('invalidate wrong reaction types ', function () { |
| 17 | + var reactions = _.cloneDeep(fixture["1480348800000_1480435199999"].reactions); |
| 18 | + reactions.HAHA = '0'; |
| 19 | + var isValid = ajv.validate(ReactionsType.schema, reactions); |
| 20 | + console.error(ajv.errors); |
| 21 | + expect(isValid).to.be.false; |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + describe('post', function() { |
| 26 | + it('validate post', function () { |
| 27 | + var post = _.cloneDeep(fixture["1480348800000_1480435199999"].tops)[0]; |
| 28 | + var isValid = ajv.validate(PostType.schema, post); |
| 29 | + console.error(ajv.errors); |
| 30 | + expect(isValid).to.be.true; |
| 31 | + }); |
| 32 | + it('invalidate incorrect post', function () { |
| 33 | + var post = _.cloneDeep(fixture["1480348800000_1480435199999"].tops)[0]; |
| 34 | + post.type = 'HIHI' |
| 35 | + var isValid = ajv.validate(PostType.schema, post); |
| 36 | + console.error(ajv.errors); |
| 37 | + expect(isValid).to.be.false; |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('api', function() { |
| 42 | + it('validate api responses', function () { |
| 43 | + var apiResponse = _.cloneDeep(fixture); |
| 44 | + var isValid = ajv.validate(ApiType.schema, apiResponse); |
| 45 | + console.error(ajv.errors); |
| 46 | + expect(isValid).to.be.true; |
| 47 | + }); |
| 48 | + |
| 49 | + it('invalidate incorrect api responses', function () { |
| 50 | + var apiResponse = _.cloneDeep(fixture); |
| 51 | + apiResponse["1480348800000_1480435199999"].tops = null |
| 52 | + var isValid = ajv.validate(ApiType.schema, apiResponse); |
| 53 | + console.error(ajv.errors); |
| 54 | + expect(isValid).to.be.false; |
| 55 | + }); |
| 56 | + |
| 57 | + }); |
| 58 | +}); |
0 commit comments