Skip to content

Commit

Permalink
Delete orphaned CPP details and current offence data
Browse files Browse the repository at this point in the history
If a user answers yes to the community supervision question and fills in
subsequent screens, the data will persist even after coming back to change the
answer to 'no' and will show on the check your answers screen and be submitted
with the application.

This change ensures we remove that data when the answer is 'no.
  • Loading branch information
Daniel Liburd committed Jan 8, 2025
1 parent 6efb7f7 commit 774ab28
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
53 changes: 53 additions & 0 deletions server/utils/applications/deleteOrphanedData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,57 @@ describe('deleteOrphanedFollowOnAnswers', () => {
})
})
})
describe('cpp-details and current offences', () => {
describe('when probation supervision is set to no', () => {
const applicationData = {
'community-supervision-and-current-offences': {
'community-supervision': {
probationSupervision: 'no',
},
'cpp-details': {
cppDetails: {
name: 'A. CPP',
probationRegion: 'some region',
email: '[email protected]',
telephone: '012345',
},
},
'current-offence-data': [
{
titleAndNumber: 'Arson',
offenceCategory: 'Arson',
'offenceDate-day': '5',
'offenceDate-month': '6',
'offenceDate-year': '1940',
sentenceLength: '3 years',
summary: 'summary detail',
outstandingCharges: 'yes',
outstandingChargesDetail: 'outstanding charges detail',
},
{
titleAndNumber: 'Stalking',
offenceCategory: 'Stalking',
'offenceDate-day': '6',
'offenceDate-month': '7',
'offenceDate-year': '2023',
sentenceLength: '2 months',
summary: 'more summary detail',
outstandingCharges: 'no',
},
],
'current-offences': {},
},
}

it('removes cpp details and current offence data', () => {
expect(deleteOrphanedFollowOnAnswers(applicationData)).toEqual({
'community-supervision-and-current-offences': {
'community-supervision': {
probationSupervision: 'no',
},
},
})
})
})
})
})
17 changes: 17 additions & 0 deletions server/utils/applications/deleteOrphanedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export default function deleteOrphanedFollowOnAnswers(applicationData: AnyValue)
}
}

const deleteOrphanedCPPAndCurrentOffenceData = () => {
delete applicationData['community-supervision-and-current-offences']['cpp-details']
delete applicationData['community-supervision-and-current-offences']['current-offence-data']
delete applicationData['community-supervision-and-current-offences']['current-offences']
}

const hasOrphanedInformation = ({
taskName,
pageName,
Expand Down Expand Up @@ -90,5 +96,16 @@ export default function deleteOrphanedFollowOnAnswers(applicationData: AnyValue)
deleteAddressHistoryInformation()
}

if (
hasOrphanedInformation({
taskName: 'community-supervision-and-current-offences',
pageName: 'community-supervision',
questionKey: 'probationSupervision',
answerToCheck: 'no',
})
) {
deleteOrphanedCPPAndCurrentOffenceData()
}

return applicationData
}

0 comments on commit 774ab28

Please sign in to comment.