-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathMAC.test.ts
64 lines (56 loc) · 1.9 KB
/
MAC.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
56
57
58
59
60
61
62
63
64
/* global describe, it, expect */
import { Kind } from 'graphql/language';
import { GraphQLMAC } from '../src/scalars/MAC.js';
// Taken from https://github.com/hapijs/joi/blob/master/test/types/string.js
const addresses = [`01:23:45:67:89:ab`, `01-23-45-67-89-ab`, `0123.4567.89ab`];
describe(`MAC`, () => {
describe(`valid`, () => {
it(`serialize`, () => {
for (const address of addresses) {
expect(GraphQLMAC.serialize(address)).toEqual(address);
}
});
it(`parseValue`, () => {
for (const address of addresses) {
expect(GraphQLMAC.parseValue(address)).toEqual(address);
}
});
it(`parseLiteral`, () => {
for (const address of addresses) {
expect(
GraphQLMAC.parseLiteral(
{
value: address,
kind: Kind.STRING,
},
{},
),
).toEqual(address);
}
});
});
describe(`invalid`, () => {
describe(`not a valid MAC address`, () => {
it(`serialize`, () => {
expect(() => GraphQLMAC.serialize(123)).toThrow(/Value is not string/);
expect(() => GraphQLMAC.serialize(`this is not an mac address`)).toThrow(
/Value is not a valid MAC address/,
);
});
it(`parseValue`, () => {
expect(() => GraphQLMAC.serialize(123)).toThrow(/Value is not string/);
expect(() => GraphQLMAC.parseValue(`this is not an mac address`)).toThrow(
/Value is not a valid MAC address/,
);
});
it(`parseLiteral`, () => {
expect(() => GraphQLMAC.parseLiteral({ value: 123, kind: Kind.INT } as any, {})).toThrow(
/Can only validate strings as MAC addresses but got a/,
);
expect(() =>
GraphQLMAC.parseLiteral({ value: `this is not an mac address`, kind: Kind.STRING }, {}),
).toThrow(/Value is not a valid MAC address/);
});
});
});
});