Skip to content

Commit cfcbbd2

Browse files
authored
API Handle Null Values in DKIM and SPF Failure Tables (canada-ca#2828)
* update dkim failure table guidanceTag to handle null values * update spf failure table guidanceTag field to support null values
1 parent e738743 commit cfcbbd2

4 files changed

Lines changed: 126 additions & 70 deletions

File tree

api-js/src/dmarc-summaries/objects/__tests__/dkim-failure-table.test.js

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -159,42 +159,65 @@ describe('given the dkimFailureTable gql object', () => {
159159
})
160160
})
161161
describe('testing the guidanceTag resolver', () => {
162-
it('returns resolved value', async () => {
163-
const demoType = dkimFailureTableType.getFields()
164-
165-
const expectedResults = {
166-
_id: 'aggregateGuidanceTags/agg1',
167-
_key: 'agg1',
168-
_rev: 'rev',
169-
_type: 'guidanceTag',
170-
guidance: 'cool guidance for issue',
171-
id: 'agg1',
172-
refLinksGuide: [
173-
{ description: 'Link Description', ref_link: 'www.link.ca' },
174-
],
175-
refLinksTechnical: [
176-
{
177-
description: 'Tech link description',
178-
tech_link: 'www.tech.link.ca',
179-
},
180-
],
181-
tagId: 'agg1',
182-
tagName: 'cool-tag-name',
183-
}
184-
185-
expect(
186-
await demoType.guidanceTag.resolve(
187-
{ guidance: 'agg1' },
188-
{},
189-
{
190-
loaders: {
191-
loadAggregateGuidanceTagByTagId: {
192-
load: jest.fn().mockReturnValue(expectedResults),
162+
describe('guidance is not null', () => {
163+
it('returns resolved value', async () => {
164+
const demoType = dkimFailureTableType.getFields()
165+
166+
const expectedResults = {
167+
_id: 'aggregateGuidanceTags/agg1',
168+
_key: 'agg1',
169+
_rev: 'rev',
170+
_type: 'guidanceTag',
171+
guidance: 'cool guidance for issue',
172+
id: 'agg1',
173+
refLinksGuide: [
174+
{ description: 'Link Description', ref_link: 'www.link.ca' },
175+
],
176+
refLinksTechnical: [
177+
{
178+
description: 'Tech link description',
179+
tech_link: 'www.tech.link.ca',
180+
},
181+
],
182+
tagId: 'agg1',
183+
tagName: 'cool-tag-name',
184+
}
185+
186+
expect(
187+
await demoType.guidanceTag.resolve(
188+
{ guidance: 'agg1' },
189+
{},
190+
{
191+
loaders: {
192+
loadAggregateGuidanceTagByTagId: {
193+
load: jest.fn().mockReturnValue(expectedResults),
194+
},
195+
},
196+
},
197+
),
198+
).toEqual(expectedResults)
199+
})
200+
})
201+
describe('guidance is null', () => {
202+
it('returns an empty obj', async () => {
203+
const demoType = dkimFailureTableType.getFields()
204+
205+
const expectedResults = {}
206+
207+
expect(
208+
await demoType.guidanceTag.resolve(
209+
{ guidance: null },
210+
{},
211+
{
212+
loaders: {
213+
loadAggregateGuidanceTagByTagId: {
214+
load: jest.fn().mockReturnValue(expectedResults),
215+
},
193216
},
194217
},
195-
},
196-
),
197-
).toEqual(expectedResults)
218+
),
219+
).toEqual(expectedResults)
220+
})
198221
})
199222
})
200223
describe('testing the headerFrom resolver', () => {

api-js/src/dmarc-summaries/objects/__tests__/spf-failure-table.test.js

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -117,42 +117,65 @@ describe('given spfFailureTable gql object', () => {
117117
})
118118
})
119119
describe('testing the guidanceTag resolver', () => {
120-
it('returns resolved value', async () => {
121-
const demoType = spfFailureTableType.getFields()
122-
123-
const expectedResult = {
124-
_id: 'aggregateGuidanceTags/agg1',
125-
_key: 'agg1',
126-
_rev: 'rev',
127-
_type: 'guidanceTag',
128-
guidance: 'cool guidance for issue',
129-
id: 'agg1',
130-
refLinksGuide: [
131-
{ description: 'Link Description', ref_link: 'www.link.ca' },
132-
],
133-
refLinksTechnical: [
134-
{
135-
description: 'Tech link description',
136-
tech_link: 'www.tech.link.ca',
137-
},
138-
],
139-
tagId: 'agg1',
140-
tagName: 'cool-tag-name',
141-
}
142-
143-
expect(
144-
await demoType.guidanceTag.resolve(
145-
{ guidance: 'agg1' },
146-
{},
147-
{
148-
loaders: {
149-
loadAggregateGuidanceTagByTagId: {
150-
load: jest.fn().mockReturnValue(expectedResult),
120+
describe('guidance is not null', () => {
121+
it('returns resolved value', async () => {
122+
const demoType = spfFailureTableType.getFields()
123+
124+
const expectedResult = {
125+
_id: 'aggregateGuidanceTags/agg1',
126+
_key: 'agg1',
127+
_rev: 'rev',
128+
_type: 'guidanceTag',
129+
guidance: 'cool guidance for issue',
130+
id: 'agg1',
131+
refLinksGuide: [
132+
{ description: 'Link Description', ref_link: 'www.link.ca' },
133+
],
134+
refLinksTechnical: [
135+
{
136+
description: 'Tech link description',
137+
tech_link: 'www.tech.link.ca',
138+
},
139+
],
140+
tagId: 'agg1',
141+
tagName: 'cool-tag-name',
142+
}
143+
144+
expect(
145+
await demoType.guidanceTag.resolve(
146+
{ guidance: 'agg1' },
147+
{},
148+
{
149+
loaders: {
150+
loadAggregateGuidanceTagByTagId: {
151+
load: jest.fn().mockReturnValue(expectedResult),
152+
},
153+
},
154+
},
155+
),
156+
).toEqual(expectedResult)
157+
})
158+
})
159+
describe('guidance is null', () => {
160+
it('returns an empty obj', async () => {
161+
const demoType = spfFailureTableType.getFields()
162+
163+
const expectedResult = {}
164+
165+
expect(
166+
await demoType.guidanceTag.resolve(
167+
{ guidance: null },
168+
{},
169+
{
170+
loaders: {
171+
loadAggregateGuidanceTagByTagId: {
172+
load: jest.fn().mockReturnValue(expectedResult),
173+
},
151174
},
152175
},
153-
},
154-
),
155-
).toEqual(expectedResult)
176+
),
177+
).toEqual(expectedResult)
178+
})
156179
})
157180
})
158181
describe('testing the headerFrom resolver', () => {

api-js/src/dmarc-summaries/objects/dkim-failure-table.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ export const dkimFailureTableType = new GraphQLObjectType({
5959
{ guidance },
6060
_args,
6161
{ loaders: { loadAggregateGuidanceTagByTagId } },
62-
) => await loadAggregateGuidanceTagByTagId.load(guidance),
62+
) => {
63+
if (guidance) {
64+
return await loadAggregateGuidanceTagByTagId.load(guidance)
65+
}
66+
return {}
67+
},
6368
},
6469
headerFrom: {
6570
type: GraphQLString,

api-js/src/dmarc-summaries/objects/spf-failure-table.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ export const spfFailureTableType = new GraphQLObjectType({
3838
{ guidance },
3939
_args,
4040
{ loaders: { loadAggregateGuidanceTagByTagId } },
41-
) => await loadAggregateGuidanceTagByTagId.load(guidance),
41+
) => {
42+
if (guidance) {
43+
return await loadAggregateGuidanceTagByTagId.load(guidance)
44+
}
45+
return {}
46+
},
4247
},
4348
headerFrom: {
4449
type: GraphQLString,

0 commit comments

Comments
 (0)