forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscalar-domain.test.js
More file actions
125 lines (124 loc) · 4.08 KB
/
scalar-domain.test.js
File metadata and controls
125 lines (124 loc) · 4.08 KB
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
120
121
122
123
124
125
import { Kind } from 'graphql'
import { stringify } from 'jest-matcher-utils'
import { Domain } from '../index'
describe('given a domain scalar', () => {
describe('serializing inputs', () => {
describe('given valid inputs', () => {
describe('given a valid domain', () => {
it('returns test domain', () => {
const testDomain = 'test.domain.ca'
expect(Domain.serialize(testDomain)).toEqual(testDomain)
})
})
describe('given a domain with uppercase letters', () => {
it('sends it to lower', () => {
const testDomain = 'test.DOMAIN.ca'
expect(Domain.serialize(testDomain)).toEqual('test.domain.ca')
})
})
describe('given an invalid domain', () => {
it('throws type error', () => {
const testDomain = 'not an domain'
expect(() => Domain.serialize(testDomain)).toThrow(
new TypeError(`Value is not a valid domain: ${testDomain}`),
)
})
})
})
describe('given invalid inputs', () => {
;[123, {}, [], null, undefined, true].forEach((invalidInput) => {
it(`throws an error when serializing ${stringify(
invalidInput,
)}`, () => {
expect(() => Domain.serialize(invalidInput)).toThrow(
new TypeError(`Value is not a string: ${typeof invalidInput}`),
)
})
})
})
})
describe('value parsing', () => {
describe('given valid inputs', () => {
describe('given a valid domain', () => {
const testDomain = 'test.domain.ca'
expect(Domain.parseValue(testDomain)).toEqual(testDomain)
})
describe('given a domain with uppercase letters', () => {
it('sends it to lower', () => {
const testDomain = 'test.DOMAIN.ca'
expect(Domain.parseValue(testDomain)).toEqual('test.domain.ca')
})
})
describe('given an invalid domain', () => {
const testDomain = 'not an domain'
expect(() => Domain.parseValue(testDomain)).toThrow(
new TypeError(`Value is not a valid domain: ${testDomain}`),
)
})
})
describe('given invalid inputs', () => {
;[123, {}, [], null, undefined, true].forEach((invalidInput) => {
it(`throws an error when serializing ${stringify(
invalidInput,
)}`, () => {
expect(() => Domain.parseValue(invalidInput)).toThrow(
new TypeError(`Value is not a string: ${typeof invalidInput}`),
)
})
})
})
})
describe('literal parsing', () => {
describe('given valid inputs', () => {
describe('given a valid domain', () => {
const testDomain = 'test.domain.ca'
const testLiteral = {
kind: Kind.STRING,
value: testDomain,
}
expect(Domain.parseLiteral(testLiteral, {})).toEqual(testDomain)
})
describe('given a domain with uppercase letters', () => {
it('sends it to lower', () => {
const testDomain = 'test.DOMAIN.ca'
const testLiteral = {
kind: Kind.STRING,
value: testDomain,
}
expect(Domain.parseLiteral(testLiteral, {})).toEqual('test.domain.ca')
})
})
describe('given an invalid domain', () => {
const testDomain = 'not an domain'
const testLiteral = {
kind: Kind.STRING,
value: testDomain,
}
expect(() => Domain.parseLiteral(testLiteral, {})).toThrow(
new TypeError(`Value is not a valid domain: ${testDomain}`),
)
})
})
describe('given invalid inputs', () => {
;[
{
kind: Kind.FLOAT,
value: '5',
},
{
kind: Kind.DOCUMENT,
},
].forEach((literal) => {
it(`throws an error when parsing invalid literal ${stringify(
literal,
)}`, () => {
expect(() => Domain.parseLiteral(literal, {})).toThrow(
new TypeError(
`Can only validate strings as domains but got a: ${literal.kind}`,
),
)
})
})
})
})
})