Skip to content

Commit

Permalink
Update CYA page to only show participations added as part of referral
Browse files Browse the repository at this point in the history
  • Loading branch information
jsrobertson committed Jan 17, 2025
1 parent cea6667 commit 656eb7c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
6 changes: 3 additions & 3 deletions integration_tests/e2e/refer/new/submit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ context('Submitting a referral', () => {
})

it('Shows the information the user has submitted in the referral form', () => {
cy.task('stubParticipationsByPerson', { courseParticipations, prisonNumber: prisoner.prisonerNumber })
cy.task('stubParticipationsByReferral', { courseParticipations, referralId: submittableReferral.id })

cy.visit(path)

Expand Down Expand Up @@ -151,7 +151,7 @@ context('Submitting a referral', () => {

describe('for a person with no programme history', () => {
it('indicates that there is no programme history', () => {
cy.task('stubParticipationsByPerson', { courseParticipations: [], prisonNumber: prisoner.prisonerNumber })
cy.task('stubParticipationsByReferral', { courseParticipations: [], referralId: submittableReferral.id })

cy.visit(path)

Expand All @@ -173,7 +173,7 @@ context('Submitting a referral', () => {
describe('When submitting a referral', () => {
beforeEach(() => {
cy.task('stubCourse', course)
cy.task('stubParticipationsByPerson', { courseParticipations, prisonNumber: prisoner.prisonerNumber })
cy.task('stubParticipationsByReferral', { courseParticipations, referralId: submittableReferral.id })
})

it('redirects to the referral complete page when the user confirms the details', () => {
Expand Down
38 changes: 31 additions & 7 deletions server/controllers/refer/new/referralsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
courseAudienceFactory,
courseFactory,
courseOfferingFactory,
courseParticipationFactory,
organisationFactory,
personFactory,
referralFactory,
Expand Down Expand Up @@ -380,7 +381,17 @@ describe('NewReferralsController', () => {
audience: courseAudienceFactory.build(),
})
const organisation = organisationFactory.build({ id: referableCourseOffering.organisationId })
const summaryListOptions = 'summary list options' as unknown as GovukFrontendSummaryListWithRowsWithKeysAndValues
const participationsForReferral = courseParticipationFactory.buildList(2, { isDraft: true })
const summaryListOptions: Array<GovukFrontendSummaryListWithRowsWithKeysAndValues> = [
{
card: { title: { text: 'Participation 1' } },
rows: [{ key: { text: 'Setting' }, value: { text: 'Community' } }],
},
{
card: { title: { text: 'Participation 2' } },
rows: [{ key: { text: 'Setting' }, value: { text: 'Custody' } }],
},
]

beforeEach(() => {
courseService.getCourseByOffering.mockResolvedValue(course)
Expand All @@ -401,7 +412,8 @@ describe('NewReferralsController', () => {
courseService.getCourse.mockResolvedValue(course)
;(CourseUtils.presentCourse as jest.Mock).mockReturnValue(coursePresenter)

courseService.getAndPresentParticipationsByPerson.mockResolvedValue([summaryListOptions, summaryListOptions])
courseService.getParticipationsByReferral.mockResolvedValue(participationsForReferral)
courseService.getAndPresentParticipationsByPerson.mockResolvedValue(summaryListOptions)

const emptyErrorsLocal = { list: [], messages: {} }
;(FormUtils.setFieldErrors as jest.Mock).mockImplementation((_request, _response, _fields) => {
Expand All @@ -410,20 +422,32 @@ describe('NewReferralsController', () => {
})

it('renders the referral check answers page and sets the `returnTo` value in the sesssion', async () => {
const actions = {
change: true,
remove: false,
}
const requestHandler = controller.checkAnswers()
await requestHandler(request, response, next)

expect(referralService.getReferral).toHaveBeenCalledWith(username, referralId)
expect(personService.getPerson).toHaveBeenCalledWith(username, submittableReferral.prisonNumber)
expect(userService.getFullNameFromUsername).toHaveBeenCalledWith(userToken, submittableReferral.referrerUsername)
expect(FormUtils.setFieldErrors).toHaveBeenCalledWith(request, response, ['confirmation'])
expect(courseService.getAndPresentParticipationsByPerson).toHaveBeenCalledWith(
username,
expect(courseService.getParticipationsByReferral).toHaveBeenCalledWith(username, referralId)
expect(courseService.presentCourseParticipation).toHaveBeenCalledTimes(2)
expect(courseService.presentCourseParticipation).toHaveBeenCalledWith(
userToken,
participationsForReferral[0],
referralId,
undefined,
actions,
)
expect(courseService.presentCourseParticipation).toHaveBeenCalledWith(
userToken,
person.prisonNumber,
participationsForReferral[1],
referralId,
{ change: true, remove: false },
3,
undefined,
actions,
)
expect(request.session.returnTo).toBe('check-answers')
expect(response.render).toHaveBeenCalledWith('referrals/new/checkAnswers', {
Expand Down
20 changes: 11 additions & 9 deletions server/controllers/refer/new/referralsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ export default class NewReferralsController {
this.userService.getEmailFromUsername(req.user.token, referral.referrerUsername),
])

const [organisation, participationSummaryListsOptions] = await Promise.all([
const [organisation, participationsForReferral] = await Promise.all([
this.organisationService.getOrganisation(req.user.token, courseOffering.organisationId),
this.courseService.getAndPresentParticipationsByPerson(
req.user.username,
req.user.token,
person.prisonNumber,
referralId,
{ change: true, remove: false },
3,
),
this.courseService.getParticipationsByReferral(req.user.username, referralId),
])

const participationSummaryListsOptions = await Promise.all(
participationsForReferral.map(participation =>
this.courseService.presentCourseParticipation(req.user.token, participation, referralId, undefined, {
change: true,
remove: false,
}),
),
)

const coursePresenter = CourseUtils.presentCourse(course)

FormUtils.setFieldErrors(req, res, ['confirmation'])
Expand Down

0 comments on commit 656eb7c

Please sign in to comment.