-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisInformationStatus.spec.ts
119 lines (115 loc) · 4.72 KB
/
isInformationStatus.spec.ts
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { expect } from 'chai';
import {
isInformationStatus,
isInformationStatusCode,
isInformationReasonPhrase,
is1xxInformationStatusCode,
} from './isInformationStatus';
import {
HttpInformationStatusCodes,
HttpStatusCodes,
} from '../HttpStatusCodes';
import {
HttpInformationReasonPhrases,
HttpReasonPhrases,
} from '../HttpReasonPhrases';
describe('isInformationStatus', function () {
describe('isInformationStatusCode', function () {
it('# Returns true for all codes defined in HttpInformationStatusCodes', function () {
Object.values(HttpInformationStatusCodes).forEach((code) => {
if (typeof code === 'number') {
expect(isInformationStatusCode(code)).to.be.true;
}
});
expect(isInformationStatusCode(100)).to.be.true;
});
it('# Returns false for all codes not defined in HttpInformationStatusCodes', function () {
Object.values(HttpStatusCodes).forEach((code) => {
if (
typeof code === 'number' &&
!(code in HttpInformationStatusCodes)
) {
expect(isInformationStatusCode(code)).to.be.false;
}
});
expect(isInformationStatusCode(2344575)).to.be.false;
});
});
describe('isInformationReasonPhrase', function () {
it('# Returns true for all phrases defined in HttpInformationReasonPhrases', function () {
Object.values(HttpInformationReasonPhrases).forEach((phrase) => {
expect(isInformationReasonPhrase(phrase)).to.be.true;
});
expect(isInformationReasonPhrase('Continue')).to.be.true;
});
it('# Returns false for all phrases not defined in HttpInformationReasonPhrases', function () {
Object.entries(HttpReasonPhrases).forEach((phrase) => {
if (
!(
HttpInformationReasonPhrases as {
[key: string]: string;
}
)[phrase[0]]
) {
expect(isInformationReasonPhrase(phrase[1])).to.be.false;
}
});
expect(isInformationReasonPhrase('Ok')).to.be.false;
});
});
describe('isInformationStatus', function () {
it('# Returns true for all codes defined in HttpInformationStatusCodes', function () {
Object.values(HttpInformationStatusCodes).forEach((code) => {
if (typeof code === 'number') {
expect(isInformationStatus(code)).to.be.true;
}
});
expect(isInformationStatus(100)).to.be.true;
});
it('# Returns false for all codes not defined in HttpInformationStatusCodes', function () {
Object.values(HttpStatusCodes).forEach((code) => {
if (
typeof code === 'number' &&
!(code in HttpInformationStatusCodes)
) {
expect(isInformationStatus(code)).to.be.false;
}
});
expect(isInformationStatus(2344575)).to.be.false;
});
it('# Returns true for all phrases defined in HttpInformationReasonPhrases', function () {
Object.values(HttpInformationReasonPhrases).forEach((phrase) => {
expect(isInformationStatus(phrase)).to.be.true;
});
expect(isInformationStatus('Continue')).to.be.true;
});
it('# Returns false for all phrases not defined in HttpInformationReasonPhrases', function () {
Object.entries(HttpReasonPhrases).forEach((phrase) => {
if (
!(
HttpInformationReasonPhrases as {
[key: string]: string;
}
)[phrase[0]]
) {
expect(isInformationStatus(phrase[1])).to.be.false;
}
});
expect(isInformationStatus('Ok')).to.be.false;
});
});
describe('is1xxInformationStatusCode', function () {
it('# Returns true for any integer in range [100 - 199]', function () {
for (let code = 100; code <= 199; code += 1) {
expect(is1xxInformationStatusCode(code)).to.be.true;
}
});
it('# Returns false for any integer outside of range [100 - 199]', function () {
for (let code = 0; code <= 1000; code += 1) {
if (code < 100 || code > 199) {
expect(is1xxInformationStatusCode(code)).to.be.false;
}
}
});
});
});