forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy-tracker-result.test.js
More file actions
117 lines (106 loc) · 3.13 KB
/
Copy pathmy-tracker-result.test.js
File metadata and controls
117 lines (106 loc) · 3.13 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
import { GraphQLInt } from 'graphql'
import { toGlobalId } from 'graphql-relay'
import { domainConnection } from '../../../domain/objects'
import { organizationSummaryType } from '../../../organization/objects'
import { myTrackerType } from '../index'
describe('given the myTracker result gql object', () => {
describe('testing field definitions', () => {
it('has a summaries field', () => {
const demoType = myTrackerType.getFields()
expect(demoType).toHaveProperty('summaries')
expect(demoType.summaries.type).toMatchObject(organizationSummaryType)
})
it('has a domainCount field', () => {
const demoType = myTrackerType.getFields()
expect(demoType).toHaveProperty('domainCount')
expect(demoType.domainCount.type).toMatchObject(GraphQLInt)
})
it('has a domains field', () => {
const demoType = myTrackerType.getFields()
expect(demoType).toHaveProperty('domains')
expect(demoType.domains.type).toMatchObject(
domainConnection.connectionType,
)
})
})
describe('testing the field resolvers', () => {
describe('testing the summaries resolver', () => {
it('returns the resolved field', () => {
const demoType = myTrackerType.getFields()
const org = {
summaries: {
web: {
pass: 50,
fail: 1000,
total: 1050,
},
mail: {
pass: 50,
fail: 1000,
total: 1050,
},
},
}
const expectedResult = {
web: {
pass: 50,
fail: 1000,
total: 1050,
},
mail: {
pass: 50,
fail: 1000,
total: 1050,
},
}
expect(demoType.summaries.resolve(org)).toEqual(expectedResult)
})
})
})
describe('testing the domainCount field', () => {
it('returns the resolved value', () => {
const demoType = myTrackerType.getFields()
expect(demoType.domainCount.resolve({ domainCount: 5 })).toEqual(5)
})
})
describe('testing the domains resolver', () => {
it('returns the resolved value', async () => {
const demoType = myTrackerType.getFields()
const expectedResult = {
edges: [
{
cursor: toGlobalId('domains', '1'),
node: {
_id: 'domains/1',
_key: '1',
_rev: 'rev',
_type: 'domain',
id: '1',
domain: 'test.gc.ca',
},
},
],
totalCount: 1,
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
startCursor: toGlobalId('domains', '1'),
endCursor: toGlobalId('domains', '1'),
},
}
await expect(
demoType.domains.resolve(
{ _id: 'users/1' },
{ first: 1 },
{
loaders: {
loadDomainConnectionsByUserId: jest
.fn()
.mockReturnValue(expectedResult),
},
},
),
).resolves.toEqual(expectedResult)
})
})
})