Skip to content

Commit dca12ad

Browse files
testing errors
1 parent 2eaa8ec commit dca12ad

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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)