-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.spec.js
66 lines (55 loc) · 1.47 KB
/
index.spec.js
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
const { graphql } = require('graphql');
const directive = require('./index.js');
const schema = require('./example/schema');
expect.extend({
toBeUppercase(received) {
if (typeof received !== 'string')
return {
message: () => `expected to be a string`,
pass: false,
};
return {
message: () => `expected ${received.toUpperCase()} got ${received}`,
pass: received.toUpperCase() === received,
};
},
});
it('has defined initial declaration', () => {
expect(directive.getDirectiveDeclaration()).toMatchSnapshot();
});
it('should change given String field to UPPER version', () => {
const instance = new directive('upper');
const field = {};
instance.visitFieldDefinition(field);
return expect(
field.resolve(
{ personId: 5, name: 'vaclav brown' },
{},
{},
{ fieldName: 'name' }
)
).resolves.toEqual('VACLAV BROWN');
});
it('should ignore any other type then String', () => {
const instance = new directive('upper');
const field = {};
instance.visitFieldDefinition(field);
return expect(
field.resolve({ personId: 5, id: 0 }, {}, {}, { fieldName: 'id' })
).resolves.toEqual(0);
});
it('graphql query should return correctly modified entity', async () => {
const response = await graphql(
schema,
`
query persons {
persons {
name
}
}
`
);
response.data.persons.forEach(({ name }) => {
expect(name).toBeUppercase();
});
});