Skip to content

Commit

Permalink
Stop pages being checked again
Browse files Browse the repository at this point in the history
If a page has no data, the next page defined in the task is selected to
continue building the task list. This removes pages from the list of
pages to check as the task list is being built, to ensure pages are not
checked twice through this.
  • Loading branch information
froddd committed Jan 16, 2025
1 parent 2deab3b commit e05d04e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions server/utils/applications/forPagesInTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { forPagesInTask } from './forPagesInTask'
jest.mock('../journeyTypeFromArtifact')
const FirstApplyPage = jest.fn()
const SecondApplyPage = jest.fn()
const ThirdApplyPage = jest.fn()
const AssessPage = jest.fn()
const PlacementRequestPage = jest.fn()

Expand All @@ -32,6 +33,7 @@ const applySection1Task1 = {
pages: {
first: FirstApplyPage,
second: SecondApplyPage,
third: ThirdApplyPage,
},
}
const applySection1Task2 = {
Expand Down Expand Up @@ -72,6 +74,7 @@ Apply.sections = [applySection1, applySection2]
Apply.pages['first-apply-section-task-1'] = {
first: FirstApplyPage,
second: SecondApplyPage,
third: ThirdApplyPage,
}

const assessSection1Task1 = {
Expand Down Expand Up @@ -224,4 +227,35 @@ describe('forPagesInTask', () => {
new Error('Page already visited while building task list: first. Visited pages: first, second'),
)
})

it('prevents a page being visited again through lack of previous page data', () => {
;(journeyTypeFromArtifact as jest.MockedFunction<typeof journeyTypeFromArtifact>).mockReturnValue('applications')

const firstApplyPageInstance = {
next: () => 'third',
}
const secondApplyPageInstance = {
next: () => '',
}
const thirdApplyPageInstance = {
next: () => 'second',
}

FirstApplyPage.mockReturnValue(firstApplyPageInstance)
SecondApplyPage.mockReturnValue(secondApplyPageInstance)
ThirdApplyPage.mockReturnValue(thirdApplyPageInstance)
const spy = jest.fn()

const application = applicationFactory.build({
data: {
'first-apply-section-task-1': { first: { foo: 'bar' }, second: undefined, third: { bar: 'foo' } },
},
})

forPagesInTask(application, applySection1Task1, spy)

expect(spy).toHaveBeenCalledWith(firstApplyPageInstance, 'first')
expect(spy).toHaveBeenCalledWith(thirdApplyPageInstance, 'third')
expect(spy).toHaveBeenCalledTimes(2)
})
})
1 change: 1 addition & 0 deletions server/utils/applications/forPagesInTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const forPagesInTask = (
}

visited.push(pageName)
pageNames.splice(pageNames.indexOf(pageName), 1)

const Page = getPage(task.id, pageName, journeyTypeFromArtifact(formArtifact))
const body = formArtifact?.data?.[task.id]?.[pageName]
Expand Down

0 comments on commit e05d04e

Please sign in to comment.