forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdkim-sub.test.js
More file actions
190 lines (174 loc) · 5.6 KB
/
dkim-sub.test.js
File metadata and controls
190 lines (174 loc) · 5.6 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
import { ensure, dbNameFromFile } from 'arango-tools'
import { GraphQLID, GraphQLList } from 'graphql'
import { databaseOptions } from '../../../../database-options'
import { dkimResultSubType, dkimSubType } from '../index'
import { domainType } from '../../../domain/objects'
import { StatusEnum } from '../../../enums'
const { DB_PASS: rootPass, DB_URL: url } = process.env
describe('given the dkimSubType object', () => {
describe('testing its field definitions', () => {
it('has sharedId field', () => {
const demoType = dkimSubType.getFields()
expect(demoType).toHaveProperty('sharedId')
expect(demoType.sharedId.type).toMatchObject(GraphQLID)
})
it('has a domain field', () => {
const demoType = dkimSubType.getFields()
expect(demoType).toHaveProperty('domain')
expect(demoType.domain.type).toMatchObject(domainType)
})
it('has a status field', () => {
const demoType = dkimSubType.getFields()
expect(demoType).toHaveProperty('status')
expect(demoType.status.type).toMatchObject(StatusEnum)
})
it('has results field', () => {
const demoType = dkimSubType.getFields()
expect(demoType).toHaveProperty('results')
expect(demoType.results.type).toMatchObject(
GraphQLList(dkimResultSubType),
)
})
})
describe('testing its field resolvers', () => {
describe('testing the sharedId resolver', () => {
it('returns the parsed value', () => {
const demoType = dkimSubType.getFields()
expect(demoType.sharedId.resolve({ sharedId: 'sharedId' })).toEqual(
'sharedId',
)
})
})
describe('testing the domain resolver', () => {
it('returns the resolved value', async () => {
const demoType = dkimSubType.getFields()
const expectedResult = {
_id: 'domains/1',
_key: '1',
_rev: 'rev',
_type: 'domain',
id: '1',
domain: 'test.domain.gc.ca',
slug: 'test-domain-gc-ca',
}
await expect(
demoType.domain.resolve(
{ domainKey: '1' },
{},
{
loaders: {
loadDomainByKey: {
load: jest.fn().mockReturnValue(expectedResult),
},
},
},
),
).resolves.toEqual(expectedResult)
})
})
describe('testing the status resolver', () => {
it('returns the parsed value', () => {
const demoType = dkimSubType.getFields()
expect(demoType.status.resolve({ status: 'status' })).toEqual('status')
})
})
describe('testing the results resolver', () => {
let drop, truncate, collections, dkimGT
beforeAll(async () => {
;({ drop, truncate, collections } = await ensure({
type: 'database',
name: dbNameFromFile(__filename),
url,
rootPassword: rootPass,
options: databaseOptions({ rootPass }),
}))
})
beforeEach(async () => {
await truncate()
dkimGT = await collections.dkimGuidanceTags.save({
_key: 'dkim1',
tagName: 'DKIM-TAG',
guidance: 'Some Interesting Guidance',
refLinksGuide: [
{
description: 'refLinksGuide Description',
ref_link: 'www.refLinksGuide.ca',
},
],
refLinksTechnical: [
{
description: 'refLinksTechnical Description',
ref_link: 'www.refLinksTechnical.ca',
},
],
})
})
afterAll(async () => {
await drop()
})
it('returns the parsed value', async () => {
const demoType = dkimSubType.getFields()
const resultObj = [
{
selector: 'selector._dkim1',
record: 'txtRecord',
keyLength: '2048',
guidanceTags: [
{
_id: dkimGT._id,
_key: dkimGT._key,
_rev: dkimGT._rev,
guidance: 'Some Interesting Guidance',
id: 'dkim1',
refLinksGuide: [
{
description: 'refLinksGuide Description',
ref_link: 'www.refLinksGuide.ca',
},
],
refLinksTechnical: [
{
description: 'refLinksTechnical Description',
ref_link: 'www.refLinksTechnical.ca',
},
],
tagId: 'dkim1',
tagName: 'DKIM-TAG',
},
],
},
]
expect(demoType.results.resolve({ results: resultObj })).toEqual([
{
guidanceTags: [
{
_id: dkimGT._id,
_key: dkimGT._key,
_rev: dkimGT._rev,
guidance: 'Some Interesting Guidance',
id: 'dkim1',
refLinksGuide: [
{
description: 'refLinksGuide Description',
ref_link: 'www.refLinksGuide.ca',
},
],
refLinksTechnical: [
{
description: 'refLinksTechnical Description',
ref_link: 'www.refLinksTechnical.ca',
},
],
tagId: 'dkim1',
tagName: 'DKIM-TAG',
},
],
keyLength: '2048',
record: 'txtRecord',
selector: 'selector._dkim1',
},
])
})
})
})
})