forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspf-failure-table.test.js
More file actions
234 lines (207 loc) · 7.47 KB
/
spf-failure-table.test.js
File metadata and controls
234 lines (207 loc) · 7.47 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import {
GraphQLID,
GraphQLInt,
GraphQLString,
GraphQLBoolean,
GraphQLNonNull,
} from 'graphql'
import { toGlobalId } from 'graphql-relay'
import { spfFailureTableType } from '../spf-failure-table'
import { guidanceTagType } from '../../../guidance-tag/objects'
describe('given spfFailureTable gql object', () => {
describe('testing field definitions', () => {
it('has an id field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('id')
expect(demoType.id.type).toMatchObject(GraphQLNonNull(GraphQLID))
})
it('has a dnsHost field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('dnsHost')
expect(demoType.dnsHost.type).toMatchObject(GraphQLString)
})
it('has a envelopeFrom field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('envelopeFrom')
expect(demoType.envelopeFrom.type).toMatchObject(GraphQLString)
})
it('has a guidance field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('guidance')
expect(demoType.guidance.type).toMatchObject(GraphQLString)
})
it('has a guidanceTag field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('guidanceTag')
expect(demoType.guidanceTag.type).toMatchObject(guidanceTagType)
})
it('has a headerFrom field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('headerFrom')
expect(demoType.headerFrom.type).toMatchObject(GraphQLString)
})
it('has a sourceIpAddress field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('sourceIpAddress')
expect(demoType.sourceIpAddress.type).toMatchObject(GraphQLString)
})
it('has a spfAligned field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('spfAligned')
expect(demoType.spfAligned.type).toMatchObject(GraphQLBoolean)
})
it('has a spfDomains field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('spfDomains')
expect(demoType.spfDomains.type).toMatchObject(GraphQLString)
})
it('has a spfResults field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('spfResults')
expect(demoType.spfResults.type).toMatchObject(GraphQLString)
})
it('has a totalMessages field', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType).toHaveProperty('totalMessages')
expect(demoType.totalMessages.type).toMatchObject(GraphQLInt)
})
})
describe('testing field resolvers', () => {
describe('testing the id resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType.id.resolve({ id: '1' })).toEqual(
toGlobalId('spfFail', 1),
)
})
})
describe('testing the dnsHost resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType.dnsHost.resolve({ dnsHost: 'dnsHost' })).toEqual(
'dnsHost',
)
})
})
describe('testing the envelopeFrom resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(
demoType.envelopeFrom.resolve({ envelopeFrom: 'envelopeFrom' }),
).toEqual('envelopeFrom')
})
})
describe('testing the guidance resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType.guidance.resolve({ guidance: 'guidance' })).toEqual(
'guidance',
)
})
})
describe('testing the guidanceTag resolver', () => {
describe('guidance is not null', () => {
it('returns resolved value', async () => {
const demoType = spfFailureTableType.getFields()
const expectedResult = {
_id: 'aggregateGuidanceTags/agg1',
_key: 'agg1',
_rev: 'rev',
_type: 'guidanceTag',
guidance: 'cool guidance for issue',
id: 'agg1',
refLinksGuide: [
{ description: 'Link Description', ref_link: 'www.link.ca' },
],
refLinksTechnical: [
{
description: 'Tech link description',
tech_link: 'www.tech.link.ca',
},
],
tagId: 'agg1',
tagName: 'cool-tag-name',
}
expect(
await demoType.guidanceTag.resolve(
{ guidance: 'agg1' },
{},
{
loaders: {
loadAggregateGuidanceTagByTagId: {
load: jest.fn().mockReturnValue(expectedResult),
},
},
},
),
).toEqual(expectedResult)
})
})
describe('guidance is null', () => {
it('returns an empty obj', async () => {
const demoType = spfFailureTableType.getFields()
const expectedResult = {}
expect(
await demoType.guidanceTag.resolve(
{ guidance: null },
{},
{
loaders: {
loadAggregateGuidanceTagByTagId: {
load: jest.fn().mockReturnValue(expectedResult),
},
},
},
),
).toEqual(expectedResult)
})
})
})
describe('testing the headerFrom resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(
demoType.headerFrom.resolve({ headerFrom: 'headerFrom' }),
).toEqual('headerFrom')
})
})
describe('testing the sourceIpAddress resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(
demoType.sourceIpAddress.resolve({
sourceIpAddress: 'sourceIpAddress',
}),
).toEqual('sourceIpAddress')
})
})
describe('testing the spfAligned field', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType.spfAligned.resolve({ spfAligned: true })).toEqual(true)
})
})
describe('testing the spfDomains resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(
demoType.spfDomains.resolve({ spfDomains: 'spfDomains' }),
).toEqual('spfDomains')
})
})
describe('testing the spfResults resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(
demoType.spfResults.resolve({ spfResults: 'spfResults' }),
).toEqual('spfResults')
})
})
describe('testing the totalMessages resolver', () => {
it('returns the resolved value', () => {
const demoType = spfFailureTableType.getFields()
expect(demoType.totalMessages.resolve({ totalMessages: 5 })).toEqual(5)
})
})
})
})