Skip to content

Commit

Permalink
feat(*): fix failing tests after rebase main
Browse files Browse the repository at this point in the history
  • Loading branch information
malaw-moj committed Feb 26, 2025
1 parent c0b09b3 commit 953a987
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import uk.gov.justice.digital.hmpps.learnerrecordsapi.config.AuditEvent.createAu
import uk.gov.justice.digital.hmpps.learnerrecordsapi.config.Roles.ROLE_LEARNER_RECORDS_SEARCH__RO
import uk.gov.justice.digital.hmpps.learnerrecordsapi.logging.LoggerUtil
import uk.gov.justice.digital.hmpps.learnerrecordsapi.logging.LoggerUtil.log
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.db.MatchEntity
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.exceptions.MatchNotFoundException
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.CheckMatchResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LearnerEventsResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.openapi.LearnerEventsApi
import uk.gov.justice.digital.hmpps.learnerrecordsapi.openapi.LearnerEventsByNomisIdApi
Expand Down Expand Up @@ -57,11 +57,11 @@ class LearnerEventsResource(
val nomisId = nomisId.getAsString("nomisId")
auditService.publishEvent(createAuditEvent(searchLearnerEventsByNomisId, userName, nomisId))
logger.log("Received a post request to learner events by Nomis ID endpoint", nomisId)
val matchEntity: MatchEntity? = learnerEventsService.getMatchEntityForNomisId(nomisId)
if (matchEntity == null) {
val checkMatchResponse: CheckMatchResponse? = learnerEventsService.getMatchEntityForNomisId(nomisId)
if (checkMatchResponse == null) {
throw MatchNotFoundException(nomisId)
} else {
val learnerEventsRequest = learnerEventsService.formLearningEventRequestFromMatchEntity(matchEntity)
val learnerEventsRequest = learnerEventsService.formLearningEventRequestFromMatchEntity(checkMatchResponse)
val learnerEventsResponse = learnerEventsService.getLearningEvents(learnerEventsRequest, userName)
return ResponseEntity.status(HttpStatus.OK).body(learnerEventsResponse)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import uk.gov.justice.digital.hmpps.learnerrecordsapi.config.HttpClientConfigura
import uk.gov.justice.digital.hmpps.learnerrecordsapi.config.LRSConfiguration
import uk.gov.justice.digital.hmpps.learnerrecordsapi.logging.LoggerUtil
import uk.gov.justice.digital.hmpps.learnerrecordsapi.logging.LoggerUtil.debugLog
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.db.MatchEntity
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.LearningEventsResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.exceptions.LRSException
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.Gender
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.CheckMatchResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LRSResponseType
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LearnerEventsResponse

Expand Down Expand Up @@ -57,13 +57,13 @@ class LearnerEventsService(
)
}

fun getMatchEntityForNomisId(nomisId: String): MatchEntity? = matchService.findMatch(MatchEntity(nomisId = nomisId))
fun getMatchEntityForNomisId(nomisId: String): CheckMatchResponse? = matchService.findMatch(nomisId = nomisId)

fun formLearningEventRequestFromMatchEntity(matchEntity: MatchEntity): LearnerEventsRequest = LearnerEventsRequest(
matchEntity.givenName.orEmpty(),
matchEntity.familyName.orEmpty(),
matchEntity.matchedUln.orEmpty(),
matchEntity.dateOfBirth,
Gender.valueOf(matchEntity.gender.orEmpty()),
fun formLearningEventRequestFromMatchEntity(checkMatchResponse: CheckMatchResponse): LearnerEventsRequest = LearnerEventsRequest(
checkMatchResponse.givenName.orEmpty(),
checkMatchResponse.familyName.orEmpty(),
checkMatchResponse.matchedUln.orEmpty(),
checkMatchResponse.dateOfBirth,
Gender.valueOf(checkMatchResponse.gender.orEmpty()),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class LearnerEventsResourceIntTest : IntegrationTestBase() {
val actualResponse = objectMapper.readValue(
webTestClient.post()
.uri("/learner-events/nomisId")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.headers(setAuthorisation(roles = listOf(ROLE_LEARNER_RECORDS_SEARCH__RO)))
.header("X-Username", "TestUser")
.bodyValue(requestJson)
.accept(MediaType.parseMediaType("application/json"))
Expand Down Expand Up @@ -414,7 +414,7 @@ class LearnerEventsResourceIntTest : IntegrationTestBase() {
val actualResponse = objectMapper.readValue(
webTestClient.post()
.uri("/learner-events/nomisId")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.headers(setAuthorisation(roles = listOf(ROLE_LEARNER_RECORDS_SEARCH__RO)))
.header("X-Username", "TestUser")
.bodyValue(requestJson)
.accept(MediaType.parseMediaType("application/json"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class LearnersResourceIntTest : IntegrationTestBase() {

webTestClient.post()
.uri("/learner-events/nomisId")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.headers(setAuthorisation(roles = listOf(ROLE_LEARNER_RECORDS_SEARCH__RO)))
.header("X-Username", "TestUser")
.bodyValue(requestJson)
.accept(MediaType.parseMediaType("application/json"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import org.mockito.Mockito.`when`
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.any
import org.springframework.http.HttpStatus
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.db.MatchEntity
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.exceptions.MatchNotFoundException
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.CheckMatchResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.CheckMatchStatus
import uk.gov.justice.digital.hmpps.learnerrecordsapi.service.LearnerEventsService
import uk.gov.justice.digital.hmpps.learnerrecordsapi.service.MatchService
import uk.gov.justice.hmpps.sqs.audit.HmppsAuditService
Expand Down Expand Up @@ -55,13 +56,13 @@ class LearnerEventsResourceTest {
@Test
fun `should return entity if record found`(): Unit = runTest {
`when`(mockLearnerEventsService.getMatchEntityForNomisId(any())).thenReturn(
MatchEntity(
nomisId = nomisId,
CheckMatchResponse(
matchedUln = matchedUln,
familyName = familyName,
givenName = givenName,
dateOfBirth = dateOfBirth,
gender = gender,
status = CheckMatchStatus.Found,
),
)
val requestJson = JSONObject()
Expand Down

0 comments on commit 953a987

Please sign in to comment.