-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathLocalTime.test.ts
95 lines (84 loc) · 2.63 KB
/
LocalTime.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
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
import { Kind } from 'graphql/language';
import { GraphQLLocalTime } from '../src/scalars/LocalTime.js';
export const VALID_LOCAL_TIMES = [
'00:00',
'00:00:00',
'00:00:00.000',
'23:59',
'23:59:59',
'23:59:59.999',
'12:30',
'12:30:45',
'12:30:45.678',
];
export const INVALID_LOCAL_TIMES = [
'this is not a valid time',
'24:01',
'24:00:01',
'24:00:00.001',
'99:99:99',
'00:00:00+01:30',
'10:00:11.003Z',
];
describe(`LocalTime`, () => {
describe(`valid`, () => {
it(`serialize`, () => {
VALID_LOCAL_TIMES.forEach(testValue => {
expect(GraphQLLocalTime.serialize(testValue)).toEqual(testValue);
});
});
it(`parseValue`, () => {
VALID_LOCAL_TIMES.forEach(testValue => {
expect(GraphQLLocalTime.parseValue(testValue)).toEqual(testValue);
});
});
it(`parseLiteral`, () => {
VALID_LOCAL_TIMES.forEach(testValue => {
expect(
GraphQLLocalTime.parseLiteral(
{
value: testValue,
kind: Kind.STRING,
},
{},
),
).toEqual(testValue);
});
});
});
describe(`invalid`, () => {
describe(`not a valid LocalTime`, () => {
it(`serialize`, () => {
expect(() => GraphQLLocalTime.serialize(123)).toThrow(/Value is not string/);
expect(() => GraphQLLocalTime.serialize(false)).toThrow(/Value is not string/);
INVALID_LOCAL_TIMES.forEach(testValue => {
expect(() => GraphQLLocalTime.serialize(testValue)).toThrow(
/Value is not a valid LocalTime/,
);
});
});
it(`parseValue`, () => {
expect(() => GraphQLLocalTime.parseValue(123)).toThrow(/Value is not string/);
expect(() => GraphQLLocalTime.parseValue(false)).toThrow(/Value is not string/);
INVALID_LOCAL_TIMES.forEach(testValue => {
expect(() => GraphQLLocalTime.parseValue(testValue)).toThrow(
/Value is not a valid LocalTime/,
);
});
});
it(`parseLiteral`, () => {
expect(() =>
GraphQLLocalTime.parseLiteral({ value: 123, kind: Kind.INT } as any, {}),
).toThrow(/Can only validate strings as local times but got a/);
expect(() =>
GraphQLLocalTime.parseLiteral({ value: false, kind: Kind.BOOLEAN }, {}),
).toThrow(/Can only validate strings as local times but got a/);
INVALID_LOCAL_TIMES.forEach(testValue => {
expect(() =>
GraphQLLocalTime.parseLiteral({ value: testValue, kind: Kind.STRING }, {}),
).toThrow(/Value is not a valid LocalTime/);
});
});
});
});
});