forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaffiliation.test.js
More file actions
138 lines (125 loc) · 3.96 KB
/
affiliation.test.js
File metadata and controls
138 lines (125 loc) · 3.96 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { GraphQLNonNull, GraphQLID } from 'graphql'
import { toGlobalId } from 'graphql-relay'
import { affiliationType } from '../affiliation'
import { organizationType } from '../../../organization/objects'
import { RoleEnums } from '../../../enums'
import { userSharedType } from '../../../user/objects'
describe('given the user affiliation object', () => {
describe('testing the field definitions', () => {
it('has an id field', () => {
const demoType = affiliationType.getFields()
expect(demoType).toHaveProperty('id')
expect(demoType.id.type).toMatchObject(GraphQLNonNull(GraphQLID))
})
it('has a permission field', () => {
const demoType = affiliationType.getFields()
expect(demoType).toHaveProperty('permission')
expect(demoType.permission.type).toMatchObject(RoleEnums)
})
it('has a user field', () => {
const demoType = affiliationType.getFields()
expect(demoType).toHaveProperty('user')
expect(demoType.user.type).toMatchObject(userSharedType)
})
it('has an organization field', () => {
const demoType = affiliationType.getFields()
expect(demoType).toHaveProperty('organization')
expect(demoType.organization.type).toMatchObject(organizationType)
})
})
describe('testing the field resolvers', () => {
describe('testing the id resolver', () => {
it('returns the resolved value', () => {
const demoType = affiliationType.getFields()
expect(demoType.id.resolve({ id: '1' })).toEqual(
toGlobalId('affiliations', '1'),
)
})
})
describe('testing the permission resolver', () => {
it('returns the resolved value', () => {
const demoType = affiliationType.getFields()
expect(demoType.permission.resolve({ permission: 'admin' })).toEqual(
'admin',
)
})
})
describe('testing the user resolver', () => {
it('returns the resolved value', async () => {
const demoType = affiliationType.getFields()
const expectedResult = {
_id: 'users/1',
_key: '1',
_rev: 'rev',
_type: 'user',
id: '1',
displayName: 'Test Account',
emailValidated: false,
preferredLang: 'french',
tfaValidated: false,
userName: 'test.account@istio.actually.exists',
}
await expect(
demoType.user.resolve(
{ _to: 'users/1' },
{},
{
loaders: {
loadUserByKey: {
load: jest.fn().mockReturnValue(expectedResult),
},
},
},
),
).resolves.toEqual(expectedResult)
})
})
describe('testing the organization resolver', () => {
it('returns the resolved value', async () => {
const demoType = affiliationType.getFields()
const expectedResult = {
_id: 'organizations/1',
_key: '1',
_rev: 'rev',
_type: 'organization',
acronym: 'TBS',
city: 'Ottawa',
country: 'Canada',
domainCount: 0,
id: '1',
name: 'Treasury Board of Canada Secretariat',
province: 'Ontario',
sector: 'TBS',
slug: 'treasury-board-secretariat',
summaries: {
mail: {
fail: 1000,
pass: 50,
total: 1050,
},
web: {
fail: 1000,
pass: 50,
total: 1050,
},
},
verified: false,
zone: 'FED',
}
await expect(
demoType.organization.resolve(
{ _from: '1' },
{},
{
loaders: {
loadOrgByKey: {
load: jest.fn().mockReturnValue(expectedResult),
},
},
},
),
).resolves.toEqual(expectedResult)
})
})
})
})