-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathCurrency.test.ts
55 lines (48 loc) · 1.63 KB
/
Currency.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
/* global describe, it, expect */
import { Kind } from 'graphql/language';
import { GraphQLCurrency } from '../src/scalars/Currency.js';
describe(`Currency`, () => {
describe(`valid`, () => {
it(`serialize`, () => {
expect(GraphQLCurrency.serialize(`USD`)).toEqual(`USD`);
});
it(`parseValue`, () => {
expect(GraphQLCurrency.parseValue(`USD`)).toEqual(`USD`);
});
it(`parseLiteral`, () => {
expect(
GraphQLCurrency.parseLiteral(
{
value: `USD`,
kind: Kind.STRING,
},
{},
),
).toEqual(`USD`);
});
});
describe(`invalid`, () => {
describe(`not a valid currency value`, () => {
it(`serialize`, () => {
expect(() => GraphQLCurrency.serialize(123)).toThrow(/Value is not string/);
expect(() => GraphQLCurrency.serialize(`this is not a currency`)).toThrow(
/Value is not a valid currency value/,
);
});
it(`parseValue`, () => {
expect(() => GraphQLCurrency.serialize(123)).toThrow(/Value is not string/);
expect(() => GraphQLCurrency.parseValue(`this is not a currency`)).toThrow(
/Value is not a valid currency value/,
);
});
it(`parseLiteral`, () => {
expect(() =>
GraphQLCurrency.parseLiteral({ value: 123, kind: Kind.INT } as any, {}),
).toThrow(/Can only validate strings as a currency but got a/);
expect(() =>
GraphQLCurrency.parseLiteral({ value: `this is not a currency`, kind: Kind.STRING }, {}),
).toThrow(/Value is not a valid currency value/);
});
});
});
});