1
|
|
|
/* eslint-env mocha */ |
2
|
|
|
/* eslint-disable no-unused-expressions */ |
3
|
|
|
|
4
|
|
|
var Chai = require('chai') |
5
|
|
|
var expect = Chai.expect |
6
|
|
|
|
7
|
|
|
var Validator = require('../../../../lib/Schema/Validator').Validator |
8
|
|
|
|
9
|
|
|
describe('Unit', function () { |
10
|
|
|
describe('/Schema', function () { |
11
|
|
|
describe('/Validator.js', function () { |
12
|
|
|
describe('.Validator', function () { |
13
|
|
|
describe('.state()', function () { |
14
|
|
|
it('reports fatal violation if falsey value is passed', function () { |
15
|
|
|
var result = Validator.state(null) |
16
|
|
|
expect(result.severity).to.eq(Validator.Severity.Fatal) |
17
|
|
|
expect(result.violations).to.have.property('$').not.empty |
|
|
|
|
18
|
|
|
}) |
19
|
|
|
|
20
|
|
|
it('reports fatal violation if transition handler is missing', function () { |
21
|
|
|
var input = {abort: function () {}} |
22
|
|
|
var result = Validator.state(input) |
23
|
|
|
expect(result.severity).to.eq(Validator.Severity.Fatal) |
24
|
|
|
expect(result.violations).to.have.property('$.transition').not.empty |
|
|
|
|
25
|
|
|
}) |
26
|
|
|
|
27
|
|
|
it('reports fatal violation if transition handler is nor valid', function () { |
28
|
|
|
var input = {transition: true, abort: function () {}} |
29
|
|
|
var result = Validator.state(input) |
30
|
|
|
expect(result.severity).to.eq(Validator.Severity.Fatal) |
31
|
|
|
expect(result.violations).to.have.property('$.transition').not.empty |
|
|
|
|
32
|
|
|
}) |
33
|
|
|
|
34
|
|
|
it('reports minor violation if abort handler is missing', function () { |
35
|
|
|
var input = {transition: function () {}} |
36
|
|
|
var result = Validator.state(input) |
37
|
|
|
expect(result.severity).to.eq(Validator.Severity.Minor) |
38
|
|
|
expect(result.violations).to.have.property('$.abort').not.empty |
|
|
|
|
39
|
|
|
}) |
40
|
|
|
|
41
|
|
|
it('reports fatal violation if abort handler is not valid', function () { |
42
|
|
|
var input = {transition: function () {}, abort: true} |
43
|
|
|
var result = Validator.state(input) |
44
|
|
|
expect(result.severity).to.eq(Validator.Severity.Fatal) |
45
|
|
|
expect(result.violations).to.have.property('$.abort').not.empty |
|
|
|
|
46
|
|
|
}) |
47
|
|
|
|
48
|
|
|
it('reports no violations if handlers are correct', function () { |
49
|
|
|
var input = { |
50
|
|
|
transition: function () {}, |
51
|
|
|
abort: function () {} |
52
|
|
|
} |
53
|
|
|
expect(Validator.state(input).violations).to.be.empty |
|
|
|
|
54
|
|
|
}) |
55
|
|
|
|
56
|
|
|
it('doesn\'t report violation if function is passed', function () { |
57
|
|
|
var input = function () {} |
58
|
|
|
expect(Validator.state(input).violations).to.be.empty |
|
|
|
|
59
|
|
|
}) |
60
|
|
|
}) |
61
|
|
|
}) |
62
|
|
|
}) |
63
|
|
|
}) |
64
|
|
|
}) |
65
|
|
|
|