Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 70 additions & 14 deletions api-js/src/types/base/__tests__/domain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ describe('given the domain object', () => {
},
},
),
).resolves.toEqual({ endDate: '2020-01-01', startDate: '2020-01-01' })
).resolves.toEqual({
endDate: '2020-01-01',
startDate: '2020-01-01',
domainKey: domainOne._key,
})
})
})
describe('user does not have domain ownership permission', () => {
Expand Down Expand Up @@ -530,19 +534,71 @@ describe('given the domain object', () => {
}

const expectedResult = [
{ endDate: '2019-01-31', startDate: '2019-01-01' },
{ endDate: '2019-02-28', startDate: '2019-02-01' },
{ endDate: '2019-03-31', startDate: '2019-03-01' },
{ endDate: '2019-04-30', startDate: '2019-04-01' },
{ endDate: '2019-01-31', startDate: '2019-05-01' },
{ endDate: '2019-06-30', startDate: '2019-06-01' },
{ endDate: '2019-07-31', startDate: '2019-07-01' },
{ endDate: '2019-08-31', startDate: '2019-08-01' },
{ endDate: '2019-09-30', startDate: '2019-09-01' },
{ endDate: '2019-10-31', startDate: '2019-10-01' },
{ endDate: '2019-11-30', startDate: '2019-11-01' },
{ endDate: '2019-12-31', startDate: '2019-12-01' },
{ endDate: '2020-01-31', startDate: '2020-01-01' },
{
endDate: '2019-01-31',
startDate: '2019-01-01',
domainKey: domainOne._key,
},
{
endDate: '2019-02-28',
startDate: '2019-02-01',
domainKey: domainOne._key,
},
{
endDate: '2019-03-31',
startDate: '2019-03-01',
domainKey: domainOne._key,
},
{
endDate: '2019-04-30',
startDate: '2019-04-01',
domainKey: domainOne._key,
},
{
endDate: '2019-01-31',
startDate: '2019-05-01',
domainKey: domainOne._key,
},
{
endDate: '2019-06-30',
startDate: '2019-06-01',
domainKey: domainOne._key,
},
{
endDate: '2019-07-31',
startDate: '2019-07-01',
domainKey: domainOne._key,
},
{
endDate: '2019-08-31',
startDate: '2019-08-01',
domainKey: domainOne._key,
},
{
endDate: '2019-09-30',
startDate: '2019-09-01',
domainKey: domainOne._key,
},
{
endDate: '2019-10-31',
startDate: '2019-10-01',
domainKey: domainOne._key,
},
{
endDate: '2019-11-30',
startDate: '2019-11-01',
domainKey: domainOne._key,
},
{
endDate: '2019-12-31',
startDate: '2019-12-01',
domainKey: domainOne._key,
},
{
endDate: '2020-01-31',
startDate: '2020-01-01',
domainKey: domainOne._key,
},
]

await expect(
Expand Down
49 changes: 48 additions & 1 deletion api-js/src/types/base/dmarc-report/__tests__/period.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
const { DB_PASS: rootPass, DB_URL: url } = process.env

const { ArangoTools, dbNameFromFile } = require('arango-tools')
const moment = require('moment')

const { makeMigrations } = require('../../../../../migrations')
const { periodType } = require('../period')
const { detailTablesType } = require('../detail-tables')
const { categoryTotalsType } = require('../category-totals')
const { categoryPercentagesType } = require('../category-percentages')
const { PeriodEnums } = require('../../../../enums')
const { Year } = require('../../../../scalars')
const { Year, Domain } = require('../../../../scalars')
const { domainLoaderByKey } = require('../../../../loaders')

describe('testing the period gql object', () => {
describe('testing the field definitions', () => {
it('has a domain field', () => {
const demoType = periodType.getFields()

expect(demoType).toHaveProperty('domain')
expect(demoType.domain.type).toMatchObject(Domain)
})
it('has a month field', () => {
const demoType = periodType.getFields()

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

describe('testing the field resolvers', () => {
describe('testing the domain resolver', () => {
let query, drop, truncate, migrate, collections, domain

beforeAll(async () => {
;({ migrate } = await ArangoTools({ rootPass, url }))
;({ query, drop, truncate, collections } = await migrate(
makeMigrations({
databaseName: dbNameFromFile(__filename),
rootPass,
}),
))

domain = await collections.domains.save({
domain: 'test.domain.gc.ca',
})
})

afterAll(async () => {
await truncate()
await drop()
})

it('returns the resolved field', async () => {
const demoType = periodType.getFields()

const loader = domainLoaderByKey(query, '1', {})

await expect(
demoType.domain.resolve(
{ domainKey: domain._key },
{},
{ loaders: { domainLoaderByKey: loader } },
),
).resolves.toEqual('test.domain.gc.ca')
})
})
describe('testing the month resolver', () => {
it('returns the resolved value', () => {
const demoType = periodType.getFields()
Expand Down
14 changes: 13 additions & 1 deletion api-js/src/types/base/dmarc-report/period.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@ const { categoryPercentagesType } = require('./category-percentages')
const { categoryTotalsType } = require('./category-totals')
const { detailTablesType } = require('./detail-tables')
const { PeriodEnums } = require('../../../enums')
const { Year } = require('../../../scalars')
const { Domain, Year } = require('../../../scalars')

const periodType = new GraphQLObjectType({
name: 'Period',
description:
'Object that contains information for each data collection period.',
fields: () => ({
domain: {
type: Domain,
description: 'The domain that the data in this period belongs to.',
resolve: async (
{ domainKey },
_args,
{ loaders: { domainLoaderByKey } },
) => {
const domain = await domainLoaderByKey.load(domainKey)
return domain.domain
},
},
month: {
type: PeriodEnums,
description: 'Start date of data collection.',
Expand Down
6 changes: 5 additions & 1 deletion api-js/src/types/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const domainType = new GraphQLObjectType({
const {
data: { dmarcSummaryByPeriod },
} = await dmarcReportLoader({ info, domain, userKey, tokenize })
dmarcSummaryByPeriod.domainKey = _key
return dmarcSummaryByPeriod
},
},
Expand Down Expand Up @@ -151,7 +152,10 @@ const domainType = new GraphQLObjectType({
const {
data: { yearlyDmarcSummaries },
} = await dmarcReportLoader({ info, domain, userKey, tokenize })
return yearlyDmarcSummaries
return yearlyDmarcSummaries.map((report) => {
report.domainKey = _key
return report
})
},
},
}),
Expand Down