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
206 lines (185 loc) · 5.89 KB
/
Copy pathaffiliation.test.js
File metadata and controls
206 lines (185 loc) · 5.89 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { ArangoTools, dbNameFromFile } from 'arango-tools'
import { GraphQLNonNull, GraphQLID } from 'graphql'
import { toGlobalId } from 'graphql-relay'
import { affiliationType } from '../affiliation'
import { makeMigrations } from '../../../../migrations'
import { userLoaderByKey } from '../../../user/loaders'
import { orgLoaderByKey } from '../../../organization/loaders'
import { organizationType } from '../../../organization/objects'
import { RoleEnums } from '../../../enums'
import { userSharedType } from '../../../user/objects'
const { DB_PASS: rootPass, DB_URL: url } = process.env
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', () => {
let query, drop, truncate, migrate, collections, user, org
beforeAll(async () => {
// Generate DB Items
;({ migrate } = await ArangoTools({ rootPass, url }))
;({ query, drop, truncate, collections } = await migrate(
makeMigrations({ databaseName: dbNameFromFile(__filename), rootPass }),
))
})
beforeEach(async () => {
user = await collections.users.save({
userName: 'test.account@istio.actually.exists',
displayName: 'Test Account',
preferredLang: 'french',
tfaValidated: false,
emailValidated: false,
})
org = await collections.organizations.save({
verified: false,
summaries: {
web: {
pass: 50,
fail: 1000,
total: 1050,
},
mail: {
pass: 50,
fail: 1000,
total: 1050,
},
},
orgDetails: {
en: {
slug: 'treasury-board-secretariat',
acronym: 'TBS',
name: 'Treasury Board of Canada Secretariat',
zone: 'FED',
sector: 'TBS',
country: 'Canada',
province: 'Ontario',
city: 'Ottawa',
},
fr: {
slug: 'secretariat-conseil-tresor',
acronym: 'SCT',
name: 'Secrétariat du Conseil Trésor du Canada',
zone: 'FED',
sector: 'TBS',
country: 'Canada',
province: 'Ontario',
city: 'Ottawa',
},
},
})
await collections.affiliations.save({
_to: user._id,
_from: org._id,
permission: 'user',
})
})
afterEach(async () => {
await truncate()
})
afterAll(async () => {
await drop()
})
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 loader = userLoaderByKey(query, '1', {})
const expectedResult = {
_id: user._id,
_key: user._key,
_rev: user._rev,
_type: 'user',
id: user._key,
displayName: 'Test Account',
emailValidated: false,
preferredLang: 'french',
tfaValidated: false,
userName: 'test.account@istio.actually.exists',
}
await expect(
demoType.user.resolve(
{ _to: user._id },
{},
{ loaders: { userLoaderByKey: loader } },
),
).resolves.toEqual(expectedResult)
})
})
describe('testing the organization resolver', () => {
it('returns the resolved value', async () => {
const demoType = affiliationType.getFields()
const loader = orgLoaderByKey(query, 'en', '1', {})
const expectedResult = {
_id: org._id,
_key: org._key,
_rev: org._rev,
_type: 'organization',
acronym: 'TBS',
city: 'Ottawa',
country: 'Canada',
domainCount: 0,
id: org._key,
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: org._id },
{},
{ loaders: { orgLoaderByKey: loader } },
),
).resolves.toEqual(expectedResult)
})
})
})
})