Skip to content

Commit 88d8243

Browse files
The keys are distinct (#423)
1 parent 9fa3e08 commit 88d8243

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

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

+11-18
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,17 @@ class GetPersonService(
2626
prisonerOffenderSearchGateway.getPrisonOffender(nomsNumber = it)
2727
}
2828

29-
return if (prisonResponse != null) {
30-
Response(
31-
data =
32-
mapOf(
33-
"prisonerOffenderSearch" to prisonResponse.data?.toPerson(),
34-
"probationOffenderSearch" to probationResponse.data,
35-
),
36-
errors = prisonResponse.errors + probationResponse.errors,
29+
val data =
30+
mapOf(
31+
"prisonerOffenderSearch" to prisonResponse?.data?.toPerson(),
32+
"probationOffenderSearch" to probationResponse.data,
3733
)
38-
} else {
39-
Response(
40-
data =
41-
mapOf(
42-
"prisonerOffenderSearch" to null,
43-
"probationOffenderSearch" to probationResponse.data,
44-
),
45-
errors = probationResponse.errors,
46-
)
47-
}
34+
35+
val errors = (prisonResponse?.errors ?: emptyList()) + probationResponse.errors
36+
37+
return Response(
38+
data = data,
39+
errors = errors,
40+
)
4841
}
4942
}

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

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
1414
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
1515
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
1616
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
17+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
18+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
1719
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffendersearch.POSPrisoner
1820

1921
@ContextConfiguration(
@@ -88,4 +90,21 @@ internal class GetPersonServiceTest(
8890
result.data.shouldBe(expectedResult)
8991
result.errors shouldBe emptyList()
9092
}
93+
94+
it("returns errors when unable to retrieve prison data and data when probation data is available") {
95+
val personFromProbationOffenderSearch = Person("Paula", "First", identifiers = Identifiers(nomisNumber = "A1234AA"))
96+
97+
whenever(probationOffenderSearchGateway.getPerson(hmppsId)).thenReturn(Response(data = personFromProbationOffenderSearch))
98+
whenever(prisonerOffenderSearchGateway.getPrisonOffender("A1234AA")).thenReturn(Response(data = null, errors = listOf(UpstreamApiError(UpstreamApi.PRISONER_OFFENDER_SEARCH, UpstreamApiError.Type.ENTITY_NOT_FOUND, "MockError"))))
99+
100+
val result = getPersonService.getCombinedDataForPerson(hmppsId)
101+
result.data shouldBe
102+
mapOf(
103+
"prisonerOffenderSearch" to null,
104+
"probationOffenderSearch" to personFromProbationOffenderSearch,
105+
)
106+
result.errors.first().causedBy.shouldBe(UpstreamApi.PRISONER_OFFENDER_SEARCH)
107+
result.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND)
108+
result.errors.first().description.shouldBe("MockError")
109+
}
91110
})

0 commit comments

Comments
 (0)