Skip to content

Commit e914607

Browse files
Editing the type of ID we need to pull upstream from String to Int (#430)
1 parent eea7ff7 commit e914607

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ services:
112112
dockerfile: Dockerfile.setup-create-and-vary-a-licence-api
113113
container_name: create-and-vary-licence-api
114114
healthcheck:
115-
test: 'wget --header="Authorization: Bearer abc" http://0.0.0.0:4010/public/licences/id/abc -O /dev/null'
115+
test: 'wget --header="Authorization: Bearer abc" http://0.0.0.0:4010/public/licences/id/123 -O /dev/null'
116116
ports:
117117
- '4070:4010'
118118

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/CreateAndVaryLicenceGateway.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CreateAndVaryLicenceGateway(
4545
}
4646
}
4747

48-
fun getLicenceConditions(id: String): Response<List<LicenceCondition>> {
48+
fun getLicenceConditions(id: Int): Response<List<LicenceCondition>> {
4949
val result =
5050
webClient.request<CvlLicence>(
5151
HttpMethod.GET,

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionService.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ class GetLicenceConditionService(
2121
if (crn != null) {
2222
licences = createAndVaryLicenceGateway.getLicenceSummaries(id = crn)
2323
licences.data.forEach {
24-
val conditions = createAndVaryLicenceGateway.getLicenceConditions(it.id)
25-
it.conditions = conditions.data
24+
val licenceId = it.id.toIntOrNull()
25+
if (licenceId != null) {
26+
val conditions = createAndVaryLicenceGateway.getLicenceConditions(licenceId)
27+
it.conditions = conditions.data
28+
} else {
29+
it.conditions = emptyList()
30+
}
2631
}
2732
personLicences = PersonLicences(hmppsId, licences.data.firstOrNull()?.offenderNumber, licences.data)
2833
}

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/createAndVaryLicence/GetLicenceConditionsTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class GetLicenceConditionsTests(
2929
) : DescribeSpec(
3030
{
3131
val createAndVaryLicenceApiMockServer = CreateAndVaryLicenceApiMockServer()
32-
val conditionId = "X777776"
32+
val conditionId = 12345
3333

3434
beforeEach {
3535
createAndVaryLicenceApiMockServer.start()

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/mockservers/CreateAndVaryLicenceApiMockServer.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CreateAndVaryLicenceApiMockServer : WireMockServer(WIREMOCK_PORT) {
2929
}
3030

3131
fun stubGetLicenceConditions(
32-
id: String,
32+
id: Int,
3333
body: String,
3434
status: HttpStatus = HttpStatus.OK,
3535
) {

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetLicenceConditionServiceTest.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
2525
internal class GetLicenceConditionServiceTest(
2626
@MockBean val createAndVaryLicenceGateway: CreateAndVaryLicenceGateway,
2727
@MockBean val getPersonService: GetPersonService,
28-
private val getLicenceCondtionService: GetLicenceConditionService,
28+
private val getLicenceConditionService: GetLicenceConditionService,
2929
) : DescribeSpec(
3030
{
3131
val hmppsId = "1234/56789B"
3232
val crn = "Z99999ZZ"
3333
val person = Person(firstName = "Qui-gon", lastName = "Jin", identifiers = Identifiers(deliusCrn = crn))
34-
val licences = listOf(Licence(id = "MockLicenceId"))
34+
val licences = listOf(Licence(id = "12345"))
3535
val conditions = listOf(LicenceCondition(condition = "MockCondition", category = "AP"))
3636

3737
beforeEach {
@@ -40,11 +40,11 @@ internal class GetLicenceConditionServiceTest(
4040

4141
whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn(Response(person))
4242
whenever(createAndVaryLicenceGateway.getLicenceSummaries(id = crn)).thenReturn(Response(licences))
43-
whenever(createAndVaryLicenceGateway.getLicenceConditions(id = "MockLicenceId")).thenReturn(Response(conditions))
43+
whenever(createAndVaryLicenceGateway.getLicenceConditions(id = 12345)).thenReturn(Response(conditions))
4444
}
4545

4646
it("performs a search according to hmpps Id") {
47-
getLicenceCondtionService.execute(hmppsId)
47+
getLicenceConditionService.execute(hmppsId)
4848
verify(getPersonService, VerificationModeFactory.times(1)).execute(hmppsId = hmppsId)
4949
}
5050

@@ -61,7 +61,7 @@ internal class GetLicenceConditionServiceTest(
6161
),
6262
),
6363
)
64-
val result = getLicenceCondtionService.execute("notfound")
64+
val result = getLicenceConditionService.execute("notfound")
6565
result.data.licences.shouldBe(emptyList())
6666
result.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND)
6767
}
@@ -79,13 +79,13 @@ internal class GetLicenceConditionServiceTest(
7979
),
8080
),
8181
)
82-
val result = getLicenceCondtionService.execute(hmppsId = hmppsId)
82+
val result = getLicenceConditionService.execute(hmppsId = hmppsId)
8383
result.data.licences.shouldBe(emptyList())
8484
result.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND)
8585
}
8686

8787
it("should return licence condition from gateway") {
88-
val result = getLicenceCondtionService.execute(hmppsId = hmppsId)
88+
val result = getLicenceConditionService.execute(hmppsId = hmppsId)
8989
result.data.licences.first().conditions.first().condition.shouldBe("MockCondition")
9090
result.errors.count().shouldBe(0)
9191
}

0 commit comments

Comments
 (0)