Skip to content

Commit

Permalink
Merge pull request #837 from ministryofjustice/APG-314-d-acp-history
Browse files Browse the repository at this point in the history
(APG-314d) Add client and service methods to call `course-participations/referral/{id}`
  • Loading branch information
jsrobertson authored Jan 13, 2025
2 parents 2f7df15 + f88250b commit a4fc71f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/data/accreditedProgrammesApi/courseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ export default class CourseClient {
})) as Array<CourseParticipation>
}

/* istanbul ignore next */
async findParticipationsByReferral(referralId: string): Promise<Array<CourseParticipation>> {
return (await this.restClient.get({
path: apiPaths.participations.referral({ referralId }),
})) as Array<CourseParticipation>
}

/* istanbul ignore next */
async updateCourse(courseId: Course['id'], courseUpdate: CourseCreateRequest): Promise<Course> {
return (await this.restClient.put({
Expand Down
1 change: 1 addition & 0 deletions server/paths/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default {
participations: {
create: participationsPath,
delete: participationPath,
referral: participationsPath.path('referral/:referralId'),
show: participationPath,
update: participationPath,
},
Expand Down
17 changes: 17 additions & 0 deletions server/services/courseService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,23 @@ describe('CourseService', () => {
})
})

describe('getParticipationsByReferral', () => {
const referral = referralFactory.build()

it('returns a list of participations for a given referral', async () => {
const courseParticipations = courseParticipationFactory.buildList(2, { referralId: referral.id })

when(courseClient.findParticipationsByReferral).calledWith(referral.id).mockResolvedValue(courseParticipations)

const result = await service.getParticipationsByReferral(username, referral.id)

expect(result).toEqual(courseParticipations)

expect(courseClientBuilder).toHaveBeenCalledWith(systemToken)
expect(courseClient.findParticipationsByReferral).toHaveBeenCalledWith(referral.id)
})
})

describe('presentCourseParticipation', () => {
const addedByUser = userFactory.build({ name: 'john smith' })
const courseParticipation = courseParticipationFactory.build({ addedBy: addedByUser.username })
Expand Down
11 changes: 11 additions & 0 deletions server/services/courseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ export default class CourseService {
return courseClient.findParticipationsByPerson(prisonNumber)
}

async getParticipationsByReferral(
username: Express.User['username'],
referralId: Referral['id'],
): Promise<Array<CourseParticipation>> {
const hmppsAuthClient = this.hmppsAuthClientBuilder()
const systemToken = await hmppsAuthClient.getSystemClientToken(username)
const courseClient = this.courseClientBuilder(systemToken)

return courseClient.findParticipationsByReferral(referralId)
}

async presentCourseParticipation(
userToken: Express.User['token'],
courseParticipation: CourseParticipation,
Expand Down

0 comments on commit a4fc71f

Please sign in to comment.