-
Notifications
You must be signed in to change notification settings - Fork 1
/
hostname.test.ts
55 lines (47 loc) · 1.67 KB
/
hostname.test.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
import * as fc from 'fast-check';
import * as E from 'fp-ts/Either';
import { DecodeFailed } from '..';
import { Variable } from '../Variable';
import { hostname } from './hostname';
describe(hostname, () => {
it('accepts an arbitrary URL string', () => {
const decoder = hostname();
fc.assert(
fc.property(
fc.webUrl().map((url) => new URL(url).hostname),
(str) => {
const variable = new Variable('KEY', str);
expect(decoder(variable)).toStrictEqual(E.right(str));
},
),
);
});
it('rejects an arbitrary host string with a port number', () => {
const decoder = hostname();
fc.assert(
fc.property(
fc
.tuple(
fc.webUrl(),
fc.nat().filter((n) => n < 65536),
)
.map(([url, port]) => `${new URL(url).hostname}:${port}`),
(str) => {
const variable = new Variable('KEY', str);
expect(decoder(variable)).toStrictEqual(
E.left(new DecodeFailed(variable, 'must be a valid hostname')),
);
},
),
);
});
it('rejects an arbitrary URL string', () => {
const decoder = hostname();
fc.assert(
fc.property(fc.webUrl(), (str) => {
const variable = new Variable('KEY', str);
expect(decoder(variable)).toStrictEqual(E.left(new DecodeFailed(variable, 'must be a valid hostname')));
}),
);
});
});