Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing the type of ID we need to pull upstream from String to Int #430

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CreateAndVaryLicenceGateway(
}
}

fun getLicenceConditions(id: String): Response<List<LicenceCondition>> {
fun getLicenceConditions(id: Int): Response<List<LicenceCondition>> {
val result =
webClient.request<CvlLicence>(
HttpMethod.GET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible refactor for readability if you wanted:

val licences = createAndVaryLicenceGateway.getLicenceSummaries(id = crn) licences.data.forEach { summary -> summary.conditions = summary.id.toIntOrNull()?.let { licenceId -> createAndVaryLicenceGateway.getLicenceConditions(licenceId).data } ?: emptyList() }

}
personLicences = PersonLicences(hmppsId, licences.data.firstOrNull()?.offenderNumber, licences.data)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GetLicenceConditionsTests(
) : DescribeSpec(
{
val createAndVaryLicenceApiMockServer = CreateAndVaryLicenceApiMockServer()
val conditionId = "X777776"
val conditionId = 12345

beforeEach {
createAndVaryLicenceApiMockServer.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CreateAndVaryLicenceApiMockServer : WireMockServer(WIREMOCK_PORT) {
}

fun stubGetLicenceConditions(
id: String,
id: Int,
body: String,
status: HttpStatus = HttpStatus.OK,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
Loading