Skip to content

Commit

Permalink
Remove getAndPresentParticipationsByPerson method from CourseService
Browse files Browse the repository at this point in the history
  • Loading branch information
jsrobertson committed Jan 17, 2025
1 parent 656eb7c commit eab830e
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('NewReferralsCourseParticipationsController', () => {

controller = new NewReferralsCourseParticipationsController(courseService, personService, referralService)
courseService.presentCourseParticipation.mockResolvedValue(summaryListOptions)
courseService.getAndPresentParticipationsByPerson.mockResolvedValue([summaryListOptions, summaryListOptions])
courseService.getParticipationsByPerson.mockResolvedValue(existingParticipations)
courseService.getParticipationsByReferral.mockResolvedValue(referralParticipations)
})
Expand Down
1 change: 0 additions & 1 deletion server/controllers/refer/new/referralsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ describe('NewReferralsController', () => {
;(CourseUtils.presentCourse as jest.Mock).mockReturnValue(coursePresenter)

courseService.getParticipationsByReferral.mockResolvedValue(participationsForReferral)
courseService.getAndPresentParticipationsByPerson.mockResolvedValue(summaryListOptions)

const emptyErrorsLocal = { list: [], messages: {} }
;(FormUtils.setFieldErrors as jest.Mock).mockImplementation((_request, _response, _fields) => {
Expand Down
90 changes: 0 additions & 90 deletions server/services/courseService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,96 +167,6 @@ describe('CourseService', () => {
})
})

describe('getAndPresentCourseParticipationsByPrisonNumber', () => {
const person = personFactory.build()
const addedByUser = userFactory.build({ name: 'john smith' })

const earliestCourseParticipation = courseParticipationFactory.build({
addedBy: addedByUser.username,
createdAt: '2022-01-01T12:00:00.000Z',
prisonNumber: person.prisonNumber,
})
const latestCourseParticipation = courseParticipationFactory.build({
addedBy: addedByUser.username,
createdAt: '2023-01-01T12:00:00.000Z',
prisonNumber: person.prisonNumber,
})
const addedByDisplayName = StringUtils.convertToTitleCase(addedByUser.name)

beforeEach(() => {
courseClient.findParticipationsByPerson.mockResolvedValue([
latestCourseParticipation,
earliestCourseParticipation,
])

userService.getFullNameFromUsername.mockResolvedValue(addedByDisplayName)
})

describe('when no actions are passed', () => {
it('fetches the creator, then formats the participation and creator in the appropriate format for passing to a GOV.UK summary list Nunjucks macro', async () => {
when(CourseParticipationUtils.summaryListOptions as jest.Mock)
.calledWith({ ...earliestCourseParticipation, addedByDisplayName }, 'a-referral-id', undefined, {
change: true,
remove: true,
})
.mockReturnValue('course participation 1 options')
when(CourseParticipationUtils.summaryListOptions as jest.Mock)
.calledWith({ ...latestCourseParticipation, addedByDisplayName }, 'a-referral-id', undefined, {
change: true,
remove: true,
})
.mockReturnValue('course participation 2 options')

const result = await service.getAndPresentParticipationsByPerson(
username,
userToken,
person.prisonNumber,
'a-referral-id',
)

expect(result).toEqual(['course participation 1 options', 'course participation 2 options'])
})
})

describe('when actions and headingLevel are passed', () => {
it('uses the specified actions when creating options for the summary list Nunjucks macro', async () => {
await service.getAndPresentParticipationsByPerson(
username,
userToken,
person.prisonNumber,
'a-referral-id',
{
change: false,
remove: false,
},
3,
)

expect(CourseParticipationUtils.summaryListOptions).toHaveBeenNthCalledWith(
1,
{ ...earliestCourseParticipation, addedByDisplayName },
'a-referral-id',
3,
{
change: false,
remove: false,
},
)

expect(CourseParticipationUtils.summaryListOptions).toHaveBeenNthCalledWith(
2,
{ ...latestCourseParticipation, addedByDisplayName },
'a-referral-id',
3,
{
change: false,
remove: false,
},
)
})
})
})

describe('getBuildingChoicesVariants', () => {
it('returns the courses associated with a given offering', async () => {
const course = courseFactory.build()
Expand Down
22 changes: 0 additions & 22 deletions server/services/courseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,6 @@ export default class CourseService {
return courseClient.destroyParticipation(courseParticipationId)
}

async getAndPresentParticipationsByPerson(
username: Express.User['username'],
userToken: Express.User['token'],
prisonNumber: Person['prisonNumber'],
referralId: Referral['id'],
withActions?: {
change: boolean
remove: boolean
},
headingLevel?: number,
): Promise<Array<GovukFrontendSummaryListWithRowsWithKeysAndValues>> {
const sortedCourseParticipations = (await this.getParticipationsByPerson(username, prisonNumber)).sort(
(participationA, participationB) => participationA.createdAt.localeCompare(participationB.createdAt),
)

return Promise.all(
sortedCourseParticipations.map(participation =>
this.presentCourseParticipation(userToken, participation, referralId, headingLevel, withActions),
),
)
}

async getBuildingChoicesVariants(
username: Express.User['username'],
courseId: Course['id'],
Expand Down

0 comments on commit eab830e

Please sign in to comment.