From 656eb7c6aee09aac981d58db12a99adebe24f043 Mon Sep 17 00:00:00 2001 From: John Robertson Date: Fri, 17 Jan 2025 10:30:18 +0000 Subject: [PATCH] Update CYA page to only show participations added as part of referral --- integration_tests/e2e/refer/new/submit.cy.ts | 6 +-- .../refer/new/referralsController.test.ts | 38 +++++++++++++++---- .../refer/new/referralsController.ts | 20 +++++----- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/integration_tests/e2e/refer/new/submit.cy.ts b/integration_tests/e2e/refer/new/submit.cy.ts index a33cd5c9a..cb77ea051 100644 --- a/integration_tests/e2e/refer/new/submit.cy.ts +++ b/integration_tests/e2e/refer/new/submit.cy.ts @@ -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) @@ -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) @@ -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', () => { diff --git a/server/controllers/refer/new/referralsController.test.ts b/server/controllers/refer/new/referralsController.test.ts index a1f7d8b6c..c28e95f87 100644 --- a/server/controllers/refer/new/referralsController.test.ts +++ b/server/controllers/refer/new/referralsController.test.ts @@ -11,6 +11,7 @@ import { courseAudienceFactory, courseFactory, courseOfferingFactory, + courseParticipationFactory, organisationFactory, personFactory, referralFactory, @@ -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 = [ + { + 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) @@ -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) => { @@ -410,6 +422,10 @@ 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) @@ -417,13 +433,21 @@ describe('NewReferralsController', () => { 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', { diff --git a/server/controllers/refer/new/referralsController.ts b/server/controllers/refer/new/referralsController.ts index 746eeed07..098e13884 100644 --- a/server/controllers/refer/new/referralsController.ts +++ b/server/controllers/refer/new/referralsController.ts @@ -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'])