-
Notifications
You must be signed in to change notification settings - Fork 22
/
validateMethod.test.js
89 lines (75 loc) · 1.89 KB
/
validateMethod.test.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const { expect } = require('../../chai');
const { validateMethod } = require('../../../lib/units/validateMethod');
describe('validateMethod', () => {
describe('given matching methods', () => {
const result = validateMethod(
{
method: 'GET'
},
{
method: 'GET'
}
);
it('marks fields as valid', () => {
expect(result).to.be.valid;
});
it('has "text" kind', () => {
expect(result).to.have.kind('text');
});
it('has no errors', () => {
expect(result).to.not.have.errors;
});
});
describe('given non-matching methods', () => {
const result = validateMethod(
{
method: 'POST'
},
{
method: 'GET'
}
);
it('marks field as valid', () => {
expect(result).to.not.be.valid;
});
it('has "text" kind', () => {
expect(result).to.have.kind('text');
});
describe('produces an error', () => {
it('exactly one error', () => {
expect(result).to.have.errors.lengthOf(1);
});
it('has explanatory message', () => {
expect(result)
.to.have.errorAtIndex(0)
.withMessage(`Expected method 'POST', but got 'GET'.`);
});
});
});
describe('given expected, but no real method', () => {
const result = validateMethod(
{
method: 'PATCH'
},
{
method: ''
}
);
it('marks field as invalid', () => {
expect(result).to.not.be.valid;
});
it('has "text" kind', () => {
expect(result).to.have.kind('text');
});
describe('produces an error', () => {
it('exactly one error', () => {
expect(result).to.have.errors.lengthOf(1);
});
it('has explanatory message', () => {
expect(result)
.to.have.errorAtIndex(0)
.withMessage(`Expected method 'PATCH', but got ''.`);
});
});
});
});