@@ -14,6 +14,8 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
14
14
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
15
15
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
16
16
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
17
19
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffendersearch.POSPrisoner
18
20
19
21
@ContextConfiguration(
@@ -88,4 +90,21 @@ internal class GetPersonServiceTest(
88
90
result.data.shouldBe(expectedResult)
89
91
result.errors shouldBe emptyList()
90
92
}
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
+ }
91
110
})
0 commit comments