Skip to content

Commit ef3d995

Browse files
committed
HIA-765 - update test
1 parent 28c7b46 commit ef3d995

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

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

+24-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import org.mockito.internal.verification.VerificationModeFactory
88
import org.mockito.kotlin.verify
99
import org.mockito.kotlin.whenever
1010
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer
11-
import org.springframework.boot.test.mock.mockito.MockBean
1211
import org.springframework.test.context.ContextConfiguration
12+
import org.springframework.test.context.bean.override.mockito.MockitoBean
1313
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.PrisonerOffenderSearchGateway
1414
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.CellLocation
1515
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
@@ -24,8 +24,8 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffenders
2424
classes = [GetCellLocationForPersonService::class],
2525
)
2626
internal class GetCellLocationForPersonServiceTest(
27-
@MockBean val getPersonService: GetPersonService,
28-
@MockBean val prisonerOffenderSearchGateway: PrisonerOffenderSearchGateway,
27+
@MockitoBean val getPersonService: GetPersonService,
28+
@MockitoBean val prisonerOffenderSearchGateway: PrisonerOffenderSearchGateway,
2929
private val getCellLocationForPersonService: GetCellLocationForPersonService,
3030
) : DescribeSpec(
3131
{
@@ -76,5 +76,26 @@ internal class GetCellLocationForPersonServiceTest(
7676
response.errors.first().causedBy.shouldBe(UpstreamApi.PROBATION_OFFENDER_SEARCH)
7777
response.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND)
7878
}
79+
80+
it("returns the upstream error when nomis id is not found") {
81+
whenever(prisonerOffenderSearchGateway.getPrisonOffender(nomisNumber)).thenReturn(
82+
Response(
83+
data = null,
84+
errors =
85+
listOf(
86+
UpstreamApiError(
87+
causedBy = UpstreamApi.PRISONER_OFFENDER_SEARCH,
88+
type = UpstreamApiError.Type.ENTITY_NOT_FOUND,
89+
),
90+
),
91+
),
92+
)
93+
94+
val response = getCellLocationForPersonService.execute(nomisNumber)
95+
96+
response.errors.shouldHaveSize(1)
97+
response.errors.first().causedBy.shouldBe(UpstreamApi.PRISONER_OFFENDER_SEARCH)
98+
response.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND)
99+
}
79100
},
80101
)

0 commit comments

Comments
 (0)