Skip to content

Commit 5dc10e2

Browse files
authored
Domain Scalar added to Period Type (canada-ca#1276)
* add domain field to period type * tests for adding domain to period type
1 parent 910a1b3 commit 5dc10e2

4 files changed

Lines changed: 136 additions & 17 deletions

File tree

api-js/src/types/base/__tests__/domain.test.js

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,11 @@ describe('given the domain object', () => {
389389
},
390390
},
391391
),
392-
).resolves.toEqual({ endDate: '2020-01-01', startDate: '2020-01-01' })
392+
).resolves.toEqual({
393+
endDate: '2020-01-01',
394+
startDate: '2020-01-01',
395+
domainKey: domainOne._key,
396+
})
393397
})
394398
})
395399
describe('user does not have domain ownership permission', () => {
@@ -530,19 +534,71 @@ describe('given the domain object', () => {
530534
}
531535

532536
const expectedResult = [
533-
{ endDate: '2019-01-31', startDate: '2019-01-01' },
534-
{ endDate: '2019-02-28', startDate: '2019-02-01' },
535-
{ endDate: '2019-03-31', startDate: '2019-03-01' },
536-
{ endDate: '2019-04-30', startDate: '2019-04-01' },
537-
{ endDate: '2019-01-31', startDate: '2019-05-01' },
538-
{ endDate: '2019-06-30', startDate: '2019-06-01' },
539-
{ endDate: '2019-07-31', startDate: '2019-07-01' },
540-
{ endDate: '2019-08-31', startDate: '2019-08-01' },
541-
{ endDate: '2019-09-30', startDate: '2019-09-01' },
542-
{ endDate: '2019-10-31', startDate: '2019-10-01' },
543-
{ endDate: '2019-11-30', startDate: '2019-11-01' },
544-
{ endDate: '2019-12-31', startDate: '2019-12-01' },
545-
{ endDate: '2020-01-31', startDate: '2020-01-01' },
537+
{
538+
endDate: '2019-01-31',
539+
startDate: '2019-01-01',
540+
domainKey: domainOne._key,
541+
},
542+
{
543+
endDate: '2019-02-28',
544+
startDate: '2019-02-01',
545+
domainKey: domainOne._key,
546+
},
547+
{
548+
endDate: '2019-03-31',
549+
startDate: '2019-03-01',
550+
domainKey: domainOne._key,
551+
},
552+
{
553+
endDate: '2019-04-30',
554+
startDate: '2019-04-01',
555+
domainKey: domainOne._key,
556+
},
557+
{
558+
endDate: '2019-01-31',
559+
startDate: '2019-05-01',
560+
domainKey: domainOne._key,
561+
},
562+
{
563+
endDate: '2019-06-30',
564+
startDate: '2019-06-01',
565+
domainKey: domainOne._key,
566+
},
567+
{
568+
endDate: '2019-07-31',
569+
startDate: '2019-07-01',
570+
domainKey: domainOne._key,
571+
},
572+
{
573+
endDate: '2019-08-31',
574+
startDate: '2019-08-01',
575+
domainKey: domainOne._key,
576+
},
577+
{
578+
endDate: '2019-09-30',
579+
startDate: '2019-09-01',
580+
domainKey: domainOne._key,
581+
},
582+
{
583+
endDate: '2019-10-31',
584+
startDate: '2019-10-01',
585+
domainKey: domainOne._key,
586+
},
587+
{
588+
endDate: '2019-11-30',
589+
startDate: '2019-11-01',
590+
domainKey: domainOne._key,
591+
},
592+
{
593+
endDate: '2019-12-31',
594+
startDate: '2019-12-01',
595+
domainKey: domainOne._key,
596+
},
597+
{
598+
endDate: '2020-01-31',
599+
startDate: '2020-01-01',
600+
domainKey: domainOne._key,
601+
},
546602
]
547603

548604
await expect(

api-js/src/types/base/dmarc-report/__tests__/period.test.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
const { DB_PASS: rootPass, DB_URL: url } = process.env
2+
3+
const { ArangoTools, dbNameFromFile } = require('arango-tools')
14
const moment = require('moment')
25

6+
const { makeMigrations } = require('../../../../../migrations')
37
const { periodType } = require('../period')
48
const { detailTablesType } = require('../detail-tables')
59
const { categoryTotalsType } = require('../category-totals')
610
const { categoryPercentagesType } = require('../category-percentages')
711
const { PeriodEnums } = require('../../../../enums')
8-
const { Year } = require('../../../../scalars')
12+
const { Year, Domain } = require('../../../../scalars')
13+
const { domainLoaderByKey } = require('../../../../loaders')
914

1015
describe('testing the period gql object', () => {
1116
describe('testing the field definitions', () => {
17+
it('has a domain field', () => {
18+
const demoType = periodType.getFields()
19+
20+
expect(demoType).toHaveProperty('domain')
21+
expect(demoType.domain.type).toMatchObject(Domain)
22+
})
1223
it('has a month field', () => {
1324
const demoType = periodType.getFields()
1425

@@ -44,6 +55,42 @@ describe('testing the period gql object', () => {
4455
})
4556

4657
describe('testing the field resolvers', () => {
58+
describe('testing the domain resolver', () => {
59+
let query, drop, truncate, migrate, collections, domain
60+
61+
beforeAll(async () => {
62+
;({ migrate } = await ArangoTools({ rootPass, url }))
63+
;({ query, drop, truncate, collections } = await migrate(
64+
makeMigrations({
65+
databaseName: dbNameFromFile(__filename),
66+
rootPass,
67+
}),
68+
))
69+
70+
domain = await collections.domains.save({
71+
domain: 'test.domain.gc.ca',
72+
})
73+
})
74+
75+
afterAll(async () => {
76+
await truncate()
77+
await drop()
78+
})
79+
80+
it('returns the resolved field', async () => {
81+
const demoType = periodType.getFields()
82+
83+
const loader = domainLoaderByKey(query, '1', {})
84+
85+
await expect(
86+
demoType.domain.resolve(
87+
{ domainKey: domain._key },
88+
{},
89+
{ loaders: { domainLoaderByKey: loader } },
90+
),
91+
).resolves.toEqual('test.domain.gc.ca')
92+
})
93+
})
4794
describe('testing the month resolver', () => {
4895
it('returns the resolved value', () => {
4996
const demoType = periodType.getFields()

api-js/src/types/base/dmarc-report/period.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ const { categoryPercentagesType } = require('./category-percentages')
33
const { categoryTotalsType } = require('./category-totals')
44
const { detailTablesType } = require('./detail-tables')
55
const { PeriodEnums } = require('../../../enums')
6-
const { Year } = require('../../../scalars')
6+
const { Domain, Year } = require('../../../scalars')
77

88
const periodType = new GraphQLObjectType({
99
name: 'Period',
1010
description:
1111
'Object that contains information for each data collection period.',
1212
fields: () => ({
13+
domain: {
14+
type: Domain,
15+
description: 'The domain that the data in this period belongs to.',
16+
resolve: async (
17+
{ domainKey },
18+
_args,
19+
{ loaders: { domainLoaderByKey } },
20+
) => {
21+
const domain = await domainLoaderByKey.load(domainKey)
22+
return domain.domain
23+
},
24+
},
1325
month: {
1426
type: PeriodEnums,
1527
description: 'Start date of data collection.',

api-js/src/types/base/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const domainType = new GraphQLObjectType({
118118
const {
119119
data: { dmarcSummaryByPeriod },
120120
} = await dmarcReportLoader({ info, domain, userKey, tokenize })
121+
dmarcSummaryByPeriod.domainKey = _key
121122
return dmarcSummaryByPeriod
122123
},
123124
},
@@ -151,7 +152,10 @@ const domainType = new GraphQLObjectType({
151152
const {
152153
data: { yearlyDmarcSummaries },
153154
} = await dmarcReportLoader({ info, domain, userKey, tokenize })
154-
return yearlyDmarcSummaries
155+
return yearlyDmarcSummaries.map((report) => {
156+
report.domainKey = _key
157+
return report
158+
})
155159
},
156160
},
157161
}),

0 commit comments

Comments
 (0)