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