-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisRedirectionStatus.spec.ts
119 lines (115 loc) · 4.72 KB
/
isRedirectionStatus.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 {
isRedirectionStatus,
isRedirectionStatusCode,
isRedirectionReasonPhrase,
is3xxRedirectionStatusCode,
} from './isRedirectionStatus';
import {
HttpRedirectionStatusCodes,
HttpStatusCodes,
} from '../HttpStatusCodes';
import {
HttpReasonPhrases,
HttpRedirectionReasonPhrases,
} from '../HttpReasonPhrases';
describe('isRedirectionStatus', function () {
describe('isRedirectionStatusCode', function () {
it('# Returns true for all codes defined in HttpRedirectionStatusCodes', function () {
Object.values(HttpRedirectionStatusCodes).forEach((code) => {
if (typeof code === 'number') {
expect(isRedirectionStatusCode(code)).to.be.true;
}
});
expect(isRedirectionStatusCode(300)).to.be.true;
});
it('# Returns false for all codes not defined in HttpRedirectionStatusCodes', function () {
Object.values(HttpStatusCodes).forEach((code) => {
if (
typeof code === 'number' &&
!(code in HttpRedirectionStatusCodes)
) {
expect(isRedirectionStatusCode(code)).to.be.false;
}
});
expect(isRedirectionStatusCode(2344575)).to.be.false;
});
});
describe('isRedirectionReasonPhrase', function () {
it('# Returns true for all phrases defined in HttpRedirectionReasonPhrases', function () {
Object.values(HttpRedirectionReasonPhrases).forEach((phrase) => {
expect(isRedirectionReasonPhrase(phrase)).to.be.true;
});
expect(isRedirectionReasonPhrase('Found')).to.be.true;
});
it('# Returns false for all phrases not defined in HttpRedirectionReasonPhrases', function () {
Object.entries(HttpReasonPhrases).forEach((phrase) => {
if (
!(
HttpRedirectionReasonPhrases as {
[key: string]: string;
}
)[phrase[0]]
) {
expect(isRedirectionReasonPhrase(phrase[1])).to.be.false;
}
});
expect(isRedirectionReasonPhrase('Ok')).to.be.false;
});
});
describe('isRedirectionStatus', function () {
it('# Returns true for all codes defined in HttpRedirectionStatusCodes', function () {
Object.values(HttpRedirectionStatusCodes).forEach((code) => {
if (typeof code === 'number') {
expect(isRedirectionStatus(code)).to.be.true;
}
});
expect(isRedirectionStatus(300)).to.be.true;
});
it('# Returns false for all codes not defined in HttpRedirectionStatusCodes', function () {
Object.values(HttpStatusCodes).forEach((code) => {
if (
typeof code === 'number' &&
!(code in HttpRedirectionStatusCodes)
) {
expect(isRedirectionStatus(code)).to.be.false;
}
});
expect(isRedirectionStatus(2344575)).to.be.false;
});
it('# Returns true for all phrases defined in HttpRedirectionReasonPhrases', function () {
Object.values(HttpRedirectionReasonPhrases).forEach((phrase) => {
expect(isRedirectionStatus(phrase)).to.be.true;
});
expect(isRedirectionStatus('Found')).to.be.true;
});
it('# Returns false for all phrases not defined in HttpRedirectionReasonPhrases', function () {
Object.entries(HttpReasonPhrases).forEach((phrase) => {
if (
!(
HttpRedirectionReasonPhrases as {
[key: string]: string;
}
)[phrase[0]]
) {
expect(isRedirectionStatus(phrase[1])).to.be.false;
}
});
expect(isRedirectionStatus('Ok')).to.be.false;
});
});
describe('is3xxRedirectionStatusCode', function () {
it('# Returns true for any integer in range [300 - 399]', function () {
for (let code = 300; code <= 399; code += 1) {
expect(is3xxRedirectionStatusCode(code)).to.be.true;
}
});
it('# Returns false for any integer outside of range [300 - 399]', function () {
for (let code = 0; code <= 1000; code += 1) {
if (code < 300 || code > 399) {
expect(is3xxRedirectionStatusCode(code)).to.be.false;
}
}
});
});
});