Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewan Donovan committed Feb 20, 2025
1 parent 0cf7639 commit ff3d341
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request
import jakarta.validation.constraints.Pattern
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.db.MatchEntity

class ConfirmMatchRequest(
class MatchRequest(

@field:Pattern(regexp = "^[A-Z]\\d{4}[A-Z]{2}\$")
val nomisId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
content = [
Content(
mediaType = "application/json",
schema = Schema(implementation = uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.ConfirmMatchRequest::class),
schema = Schema(implementation = uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.MatchRequest::class),
examples = [
ExampleObject(
name = "Example Request",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
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.request.ConfirmMatchRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.MatchRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.MatchResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.openapi.ConfirmMatchApi
import uk.gov.justice.digital.hmpps.learnerrecordsapi.service.MatchService
Expand All @@ -29,7 +29,7 @@ class MatchResource(
@Tag(name = "Match")
@ConfirmMatchApi
suspend fun confirmMatch(
@RequestBody @Valid confirmMatchRequest: ConfirmMatchRequest,
@RequestBody @Valid confirmMatchRequest: MatchRequest,
): ResponseEntity<MatchResponse> {
logger.log("Received a post request to confirm match endpoint", confirmMatchRequest)
val savedMatchEntity = matchService.saveMatch(confirmMatchRequest.asMatchEntity())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import uk.gov.justice.digital.hmpps.learnerrecordsapi.config.HmppsBoldLrsExceptionHandler
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.ConfirmMatchRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.MatchRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.MatchResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.repository.MatchRepository
import uk.gov.justice.digital.hmpps.learnerrecordsapi.service.MatchService
Expand Down Expand Up @@ -47,7 +47,7 @@ class MatchResourceIntTest : IntegrationTestBase() {

@Test
fun `POST to confirm match should return 200 with a response confirming a match`() {
val confirmMatchRequest = ConfirmMatchRequest("A1417AE", "1234567890")
val confirmMatchRequest = MatchRequest("A1417AE", "1234567890")

val actualResponse = objectMapper.readValue(
webTestClient.post()
Expand All @@ -74,7 +74,7 @@ class MatchResourceIntTest : IntegrationTestBase() {

@Test
fun `POST to confirm match should return 400 if nomis id is malformed`() {
val confirmMatchRequest = ConfirmMatchRequest("ABCDEFGH", "1234567890")
val confirmMatchRequest = MatchRequest("ABCDEFGH", "1234567890")

val actualResponse = objectMapper.readValue(
webTestClient.post()
Expand Down Expand Up @@ -106,14 +106,14 @@ class MatchResourceIntTest : IntegrationTestBase() {

@Test
fun `POST to confirm match should return 400 if uln is malformed`() {
val confirmMatchRequest = ConfirmMatchRequest("A1417AE", "1234567890abcdef")
val matchRequest = MatchRequest("A1417AE", "1234567890abcdef")

val actualResponse = objectMapper.readValue(
webTestClient.post()
.uri("/match/confirm")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.header("X-Username", "TestUser")
.bodyValue(confirmMatchRequest)
.bodyValue(matchRequest)
.accept(MediaType.parseMediaType("application/json"))
.exchange()
.expectStatus()
Expand All @@ -138,7 +138,7 @@ class MatchResourceIntTest : IntegrationTestBase() {

@Test
fun `POST to confirm match should return 500 if match service fails to save`() {
val confirmMatchRequest = ConfirmMatchRequest("A1417AE", "1234567890")
val matchRequest = MatchRequest("A1417AE", "1234567890")

doThrow(RuntimeException("Database error")).`when`(spiedMatchService).saveMatch(any())

Expand All @@ -147,7 +147,7 @@ class MatchResourceIntTest : IntegrationTestBase() {
.uri("/match/confirm")
.headers(setAuthorisation(roles = listOf("ROLE_LEARNER_RECORDS_SEARCH__RO")))
.header("X-Username", "TestUser")
.bodyValue(confirmMatchRequest)
.bodyValue(matchRequest)
.accept(MediaType.parseMediaType("application/json"))
.exchange()
.expectStatus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import jakarta.validation.ValidatorFactory
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class ConfirmMatchRequestTest {
class MatchRequestTest {

private val factory: ValidatorFactory = Validation.buildDefaultValidatorFactory()
private val validator = factory.validator

@Test
fun `valid request should pass validation`() {
val request = ConfirmMatchRequest(
val request = MatchRequest(
nomisId = "A1417AE",
matchingUln = "1234567890",
)
Expand All @@ -22,7 +22,7 @@ class ConfirmMatchRequestTest {

@Test
fun `invalid uln should fail validation`() {
val request = ConfirmMatchRequest(
val request = MatchRequest(
nomisId = "A1417AE",
matchingUln = "1234567890abcdedf",
)
Expand All @@ -32,7 +32,7 @@ class ConfirmMatchRequestTest {

@Test
fun `invalid nomisId should fail validation`() {
val request = ConfirmMatchRequest(
val request = MatchRequest(
nomisId = "A1424357AE",
matchingUln = "1234567890",
)
Expand Down

0 comments on commit ff3d341

Please sign in to comment.