Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against failure to fetch NOMIS data #632

Merged
merged 2 commits into from
Sep 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { acctAlertFactory, applicationFactory, personFactory } from '../../../..
import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples'
import { PageBodyPersonAcctAlert, mapAcctAlertsForPageBody } from '../../../utils'
import AcctAlerts, { acctAlertResponse } from './acctAlerts'
import { SanitisedError } from '../../../../sanitisedError'

jest.mock('../../../../services/personService')
jest.mock('../../../utils')
Expand Down Expand Up @@ -78,6 +79,24 @@ describe('AcctAlerts', () => {
expect(getAcctAlertsMock).toHaveBeenCalledWith(callConfig, application.person.crn)
expect(mapAcctAlertsForPageBody).toHaveBeenCalledWith(apiAcctAlerts)
})

it('sets the number of acctAlerts to 0 if none are found', async () => {
const err = <SanitisedError>{ data: { status: 404 } }
const getAcctAlertsMock = jest.fn().mockImplementation(() => {
throw err
})

const personService = createMock<PersonService>({
getAcctAlerts: getAcctAlertsMock,
})

const page = await AcctAlerts.initialize({}, application, callConfig, { personService })

expect(page.body).toEqual({ acctAlerts })

expect(getAcctAlertsMock).toHaveBeenCalledWith(callConfig, application.person.crn)
expect(mapAcctAlertsForPageBody).toHaveBeenCalledWith([])
})
})

itShouldHavePreviousValue(new AcctAlerts({}, application), 'adjudications')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ export default class AcctAlerts implements TasklistPage {
callConfig: CallConfig,
dataServices: DataServices,
) {
const acctAlerts = await dataServices.personService.getAcctAlerts(callConfig, application.person.crn)
let acctAlerts: PersonAcctAlert[] = []

try {
acctAlerts = await dataServices.personService.getAcctAlerts(callConfig, application.person.crn)
} catch (e) {
if (e?.data?.status !== 404) {
throw e
}
}

const page = new AcctAlerts({ acctAlerts: mapAcctAlertsForPageBody(acctAlerts) }, application)

page.importDate = DateFormats.dateObjToIsoDate(new Date())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { adjudicationFactory, applicationFactory, personFactory } from '../../..
import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples'
import { PageBodyAdjudication, mapAdjudicationsForPageBody } from '../../../utils'
import Adjudications, { adjudicationResponse } from './adjudications'
import { SanitisedError } from '../../../../sanitisedError'

jest.mock('../../../../services/personService')
jest.mock('../../../utils')
Expand Down Expand Up @@ -66,6 +67,24 @@ describe('Adjudications', () => {
expect(getAdjudicationsMock).toHaveBeenCalledWith(callConfig, application.person.crn)
expect(mapAdjudicationsForPageBody).toHaveBeenCalledWith(apiAdjudications)
})

it('sets the number of adjudications to 0 if none are found', async () => {
const err = <SanitisedError>{ data: { status: 404 } }
const getAdjudicationsMock = jest.fn().mockImplementation(() => {
throw err
})

const personService = createMock<PersonService>({
getAdjudications: getAdjudicationsMock,
})

const page = await Adjudications.initialize({}, application, callConfig, { personService })

expect(page.body).toEqual({ adjudications })

expect(getAdjudicationsMock).toHaveBeenCalledWith(callConfig, application.person.crn)
expect(mapAdjudicationsForPageBody).toHaveBeenCalledWith([])
})
})

itShouldHavePreviousValue(new Adjudications({}, application), 'dashboard')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ export default class Adjudications implements TasklistPage {
callConfig: CallConfig,
dataServices: DataServices,
) {
const adjudications = await dataServices.personService.getAdjudications(callConfig, application.person.crn)
let adjudications: Adjudication[] = []

try {
adjudications = await dataServices.personService.getAdjudications(callConfig, application.person.crn)
} catch (e) {
if (e?.data?.status !== 404) {
throw e
}
}

const page = new Adjudications({ adjudications: mapAdjudicationsForPageBody(adjudications) }, application)

Expand Down