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

Test licences #432

Merged
merged 7 commits into from
May 23, 2024
Merged
Changes from 1 commit
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
Next Next commit
Editing the type of ID we need to pull upstream from String to Int
  • Loading branch information
chiaramapellimt committed May 22, 2024
commit 8e740de58c36a46d69852a573833aaaa12341ea2
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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'

Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ class GetLicenceConditionsTests(
) : DescribeSpec(
{
val createAndVaryLicenceApiMockServer = CreateAndVaryLicenceApiMockServer()
val conditionId = "X777776"
val conditionId = 12345

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

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