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

The keys are distinct #423

Merged
merged 2 commits into from
May 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,17 @@ class GetPersonService(
prisonerOffenderSearchGateway.getPrisonOffender(nomsNumber = it)
}

return if (prisonResponse != null) {
Response(
data =
mapOf(
"prisonerOffenderSearch" to prisonResponse.data?.toPerson(),
"probationOffenderSearch" to probationResponse.data,
),
errors = prisonResponse.errors + probationResponse.errors,
val data =
mapOf(
"prisonerOffenderSearch" to prisonResponse?.data?.toPerson(),
"probationOffenderSearch" to probationResponse.data,
)
} else {
Response(
data =
mapOf(
"prisonerOffenderSearch" to null,
"probationOffenderSearch" to probationResponse.data,
),
errors = probationResponse.errors,
)
}

val errors = (prisonResponse?.errors ?: emptyList()) + probationResponse.errors

return Response(
data = data,
errors = errors,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffendersearch.POSPrisoner

@ContextConfiguration(
Expand Down Expand Up @@ -88,4 +90,21 @@ internal class GetPersonServiceTest(
result.data.shouldBe(expectedResult)
result.errors shouldBe emptyList()
}

it("returns errors when unable to retrieve prison data and data when probation data is available") {
val personFromProbationOffenderSearch = Person("Paula", "First", identifiers = Identifiers(nomisNumber = "A1234AA"))

whenever(probationOffenderSearchGateway.getPerson(hmppsId)).thenReturn(Response(data = personFromProbationOffenderSearch))
whenever(prisonerOffenderSearchGateway.getPrisonOffender("A1234AA")).thenReturn(Response(data = null, errors = listOf(UpstreamApiError(UpstreamApi.PRISONER_OFFENDER_SEARCH, UpstreamApiError.Type.ENTITY_NOT_FOUND, "MockError"))))

val result = getPersonService.getCombinedDataForPerson(hmppsId)
result.data shouldBe
mapOf(
"prisonerOffenderSearch" to null,
"probationOffenderSearch" to personFromProbationOffenderSearch,
)
result.errors.first().causedBy.shouldBe(UpstreamApi.PRISONER_OFFENDER_SEARCH)
result.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND)
result.errors.first().description.shouldBe("MockError")
}
})
Loading