-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathObjectID.test.ts
100 lines (87 loc) · 3.47 KB
/
ObjectID.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
96
97
98
99
100
/* global describe, test, expect */
import { Kind } from 'graphql/language';
import { GraphQLObjectID } from '../src/scalars/ObjectID.js';
describe('ObjectId', () => {
describe('valid', () => {
test('serialize', () => {
expect(GraphQLObjectID.serialize('5e5677d71bdc2ae76344968c')).toBe(
'5e5677d71bdc2ae76344968c',
);
});
test('parseValue', () => {
expect(GraphQLObjectID.parseValue('5e5677d71bdc2ae76344968c')).toBe(
'5e5677d71bdc2ae76344968c',
);
});
test('parseLiteral', () => {
expect(
GraphQLObjectID.parseLiteral(
{ value: '5e5677d71bdc2ae76344968c', kind: Kind.STRING },
undefined,
), // undefined as prescribed by the Maybe<T> type
).toBe('5e5677d71bdc2ae76344968c');
});
});
describe('invalid', () => {
describe('not a mongodb object id', () => {
test('serialize', () => {
const invalid = '5e5677d71bdc2ae76344968z';
expect(() => GraphQLObjectID.serialize(invalid)).toThrow(
new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`),
);
});
test('parseValue', () => {
const invalid = '5e5677d71bdc2ae76344968z';
expect(() => GraphQLObjectID.parseValue(invalid)).toThrow(
new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`),
);
});
test('parseLiteral', () => {
const invalid = '5e5677d71bdc2ae76344968z';
expect(
() => GraphQLObjectID.parseLiteral({ value: invalid, kind: Kind.STRING }, undefined), // undefined as prescribed by the Maybe<T> type
).toThrow(new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`));
});
});
describe('too short', () => {
test('serialize', () => {
const invalid = '5e5677d71bdc2ae';
expect(() => GraphQLObjectID.serialize(invalid)).toThrow(
new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`),
);
});
test('parseValue', () => {
const invalid = '5e5677d71bdc2ae';
expect(() => GraphQLObjectID.parseValue(invalid)).toThrow(
new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`),
);
});
test('parseLiteral', () => {
const invalid = '5e5677d71bdc2ae';
expect(
() => GraphQLObjectID.parseLiteral({ value: invalid, kind: Kind.STRING }, undefined), // undefined as prescribed by the Maybe<T> type
).toThrow(new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`));
});
});
describe('too long', () => {
test('serialize', () => {
const invalid = '5e5677d71bdc2ae76344968c5';
expect(() => GraphQLObjectID.serialize(invalid)).toThrow(
new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`),
);
});
test('parseValue', () => {
const invalid = '5e5677d71bdc2ae76344968c5';
expect(() => GraphQLObjectID.parseValue(invalid)).toThrow(
new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`),
);
});
test('parseLiteral', () => {
const invalid = '5e5677d71bdc2ae76344968c5';
expect(
() => GraphQLObjectID.parseLiteral({ value: invalid, kind: Kind.STRING }, undefined), // undefined as prescribed by the Maybe<T> type
).toThrow(new RegExp(`Value is not a valid mongodb object id of form: ${invalid}`));
});
});
});
});