From 8e740de58c36a46d69852a573833aaaa12341ea2 Mon Sep 17 00:00:00 2001 From: Chiara Date: Wed, 22 May 2024 10:55:56 +0100 Subject: [PATCH] Editing the type of ID we need to pull upstream from String to Int --- docker-compose.yml | 2 +- .../gateways/CreateAndVaryLicenceGateway.kt | 2 +- .../services/GetLicenceConditionService.kt | 9 +++++++-- .../GetLicenceConditionsTests.kt | 2 +- .../CreateAndVaryLicenceApiMockServer.kt | 2 +- .../services/GetLicenceConditionServiceTest.kt | 14 +++++++------- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9a288d7f6..612c3888d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -112,7 +112,7 @@ services: dockerfile: Dockerfile.setup-create-and-vary-a-licence-api container_name: create-and-vary-licence-api healthcheck: - test: 'wget --header="Authorization: Bearer abc" http://0.0.0.0:4010/public/licences/id/abc -O /dev/null' + test: 'wget --header="Authorization: Bearer abc" http://0.0.0.0:4010/public/licences/id/123 -O /dev/null' ports: - '4070:4010' diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/CreateAndVaryLicenceGateway.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/CreateAndVaryLicenceGateway.kt index 7404f4411..834425dbc 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/CreateAndVaryLicenceGateway.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/CreateAndVaryLicenceGateway.kt @@ -45,7 +45,7 @@ class CreateAndVaryLicenceGateway( } } - fun getLicenceConditions(id: String): Response> { + fun getLicenceConditions(id: Int): Response> { val result = webClient.request( HttpMethod.GET, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionService.kt index 536ce2a19..c2cf6e41b 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionService.kt @@ -21,8 +21,13 @@ class GetLicenceConditionService( if (crn != null) { licences = createAndVaryLicenceGateway.getLicenceSummaries(id = crn) licences.data.forEach { - val conditions = createAndVaryLicenceGateway.getLicenceConditions(it.id) - it.conditions = conditions.data + val licenceId = it.id.toIntOrNull() + if (licenceId != null) { + val conditions = createAndVaryLicenceGateway.getLicenceConditions(licenceId) + it.conditions = conditions.data + } else { + it.conditions = emptyList() + } } personLicences = PersonLicences(hmppsId, licences.data.firstOrNull()?.offenderNumber, licences.data) } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/createAndVaryLicence/GetLicenceConditionsTests.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/createAndVaryLicence/GetLicenceConditionsTests.kt index 8bf4dc04a..250cfc67b 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/createAndVaryLicence/GetLicenceConditionsTests.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/createAndVaryLicence/GetLicenceConditionsTests.kt @@ -29,7 +29,7 @@ class GetLicenceConditionsTests( ) : DescribeSpec( { val createAndVaryLicenceApiMockServer = CreateAndVaryLicenceApiMockServer() - val conditionId = "X777776" + val conditionId = 12345 beforeEach { createAndVaryLicenceApiMockServer.start() diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/mockservers/CreateAndVaryLicenceApiMockServer.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/mockservers/CreateAndVaryLicenceApiMockServer.kt index 2e8ad4718..620e1ad31 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/mockservers/CreateAndVaryLicenceApiMockServer.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/mockservers/CreateAndVaryLicenceApiMockServer.kt @@ -29,7 +29,7 @@ class CreateAndVaryLicenceApiMockServer : WireMockServer(WIREMOCK_PORT) { } fun stubGetLicenceConditions( - id: String, + id: Int, body: String, status: HttpStatus = HttpStatus.OK, ) { diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionServiceTest.kt index eaeb569e5..4e5d48831 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionServiceTest.kt @@ -25,13 +25,13 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi internal class GetLicenceConditionServiceTest( @MockBean val createAndVaryLicenceGateway: CreateAndVaryLicenceGateway, @MockBean val getPersonService: GetPersonService, - private val getLicenceCondtionService: GetLicenceConditionService, + private val getLicenceConditionService: GetLicenceConditionService, ) : DescribeSpec( { val hmppsId = "1234/56789B" val crn = "Z99999ZZ" val person = Person(firstName = "Qui-gon", lastName = "Jin", identifiers = Identifiers(deliusCrn = crn)) - val licences = listOf(Licence(id = "MockLicenceId")) + val licences = listOf(Licence(id = "12345")) val conditions = listOf(LicenceCondition(condition = "MockCondition", category = "AP")) beforeEach { @@ -40,11 +40,11 @@ internal class GetLicenceConditionServiceTest( whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn(Response(person)) whenever(createAndVaryLicenceGateway.getLicenceSummaries(id = crn)).thenReturn(Response(licences)) - whenever(createAndVaryLicenceGateway.getLicenceConditions(id = "MockLicenceId")).thenReturn(Response(conditions)) + whenever(createAndVaryLicenceGateway.getLicenceConditions(id = 12345)).thenReturn(Response(conditions)) } it("performs a search according to hmpps Id") { - getLicenceCondtionService.execute(hmppsId) + getLicenceConditionService.execute(hmppsId) verify(getPersonService, VerificationModeFactory.times(1)).execute(hmppsId = hmppsId) } @@ -61,7 +61,7 @@ internal class GetLicenceConditionServiceTest( ), ), ) - val result = getLicenceCondtionService.execute("notfound") + val result = getLicenceConditionService.execute("notfound") result.data.licences.shouldBe(emptyList()) result.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND) } @@ -79,13 +79,13 @@ internal class GetLicenceConditionServiceTest( ), ), ) - val result = getLicenceCondtionService.execute(hmppsId = hmppsId) + val result = getLicenceConditionService.execute(hmppsId = hmppsId) result.data.licences.shouldBe(emptyList()) result.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND) } it("should return licence condition from gateway") { - val result = getLicenceCondtionService.execute(hmppsId = hmppsId) + val result = getLicenceConditionService.execute(hmppsId = hmppsId) result.data.licences.first().conditions.first().condition.shouldBe("MockCondition") result.errors.count().shouldBe(0) }