-
Notifications
You must be signed in to change notification settings - Fork 1
/
port.test.ts
39 lines (33 loc) · 1.16 KB
/
port.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
import * as fc from 'fast-check';
import * as E from 'fp-ts/Either';
import { DecodeFailed } from '../EnvironmentError';
import { Variable } from '../Variable';
import { port } from './port';
describe(port, () => {
it('rejects well-known ports by default', () => {
const decoder = port();
fc.assert(
fc.property(
fc.nat().filter((n) => n < 1024),
(port) => {
const variable = new Variable('KEY', String(port));
expect(decoder(variable)).toStrictEqual(
E.left(new DecodeFailed(variable, 'must be greater than or equal to 1024')),
);
},
),
);
});
it('accepts well-known ports when explicitly allowed', () => {
const decoder = port({ includeWellKnown: true });
fc.assert(
fc.property(
fc.nat().filter((n) => n < 1024),
(port) => {
const variable = new Variable('KEY', String(port));
expect(decoder(variable)).toStrictEqual(E.right(port));
},
),
);
});
});