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
161 lines (149 loc) · 4.64 KB
/
Copy pathdkim-sub.test.js
File metadata and controls
161 lines (149 loc) · 4.64 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
import { ensure, dbNameFromFile } from 'arango-tools'
import { GraphQLList } from 'graphql'
import { databaseOptions } from '../../../../database-options'
import { dkimResultSubType, dkimSubType } from '../index'
import { domainType } from '../../../domain/objects'
const { DB_PASS: rootPass, DB_URL: url } = process.env
describe('given the dkimSubType object', () => {
describe('testing its field definitions', () => {
it('has a domain field', () => {
const demoType = dkimSubType.getFields()
expect(demoType).toHaveProperty('domain')
expect(demoType.domain.type).toMatchObject(domainType)
})
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 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 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',
},
])
})
})
})
})