-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathEmailAddress.test.ts
88 lines (76 loc) · 2.34 KB
/
EmailAddress.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
/* global describe, test, expect */
import { Kind } from 'graphql/language';
import { GraphQLEmailAddress } from '../src/scalars/EmailAddress.js';
describe('EmailAddress', () => {
describe('valid', () => {
test('serialize', () => {
expect(GraphQLEmailAddress.serialize('test@test.com')).toBe('test@test.com');
});
test('parseValue', () => {
expect(GraphQLEmailAddress.parseValue('test@test.com')).toBe('test@test.com');
});
test('parseValue', () => {
expect(GraphQLEmailAddress.parseValue('test@test')).toBe('test@test');
});
test('parseLiteral', () => {
expect(
GraphQLEmailAddress.parseLiteral(
{
value: 'test@test.com',
kind: Kind.STRING,
},
{},
),
).toBe('test@test.com');
});
test('parseLiteral', () => {
expect(
GraphQLEmailAddress.parseLiteral(
{
value: 'test@test',
kind: Kind.STRING,
},
{},
),
).toBe('test@test');
});
});
describe('invalid', () => {
describe('not an email address', () => {
test('serialize', () => {
expect(() => GraphQLEmailAddress.serialize('this is not an email address')).toThrow(
/Value is not a valid email address/,
);
});
test('parseValue', () => {
expect(() => GraphQLEmailAddress.parseValue('this is not an email address')).toThrow(
/Value is not a valid email address/,
);
});
test('parseLiteral', () => {
expect(() =>
GraphQLEmailAddress.parseLiteral(
{
value: 'this is not an email address',
kind: Kind.STRING,
},
{},
),
).toThrow(/Value is not a valid email address/);
});
});
describe('not a string', () => {
test('serialize', () => {
expect(() => GraphQLEmailAddress.serialize(123)).toThrow(/Value is not string/);
});
test('parseValue', () => {
expect(() => GraphQLEmailAddress.parseValue(123)).toThrow(/Value is not string/);
});
test('parseLiteral', () => {
expect(() =>
GraphQLEmailAddress.parseLiteral({ value: '123', kind: Kind.INT }, {}),
).toThrow(/Can only validate strings as email addresses but got a/);
});
});
});
});