Skip to content

Commit faf5208

Browse files
Added test to check for errors when code not in list
1 parent 039e8ff commit faf5208

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/hmpps/UpstreamApiError.kt

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps
33
data class UpstreamApiError(val causedBy: UpstreamApi, val type: Type, val description: String? = null) {
44
enum class Type {
55
ENTITY_NOT_FOUND,
6-
ATTRIBUTE_NOT_FOUND,
76
BAD_REQUEST,
87
FORBIDDEN,
98
INTERNAL_SERVER_ERROR,

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

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import org.springframework.stereotype.Service
55
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.NomisGateway
66
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Alert
77
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
8+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
9+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
810

911
@Service
1012
class GetAlertsForPersonService(
@@ -42,6 +44,18 @@ class GetAlertsForPersonService(
4244
"RSS", "RST", "RDP", "REG", "RLG", "ROP", "RRV", "RTP", "RYP", "HS", "SC",
4345
)
4446
}.orEmpty()
47+
if (filteredAlerts.isEmpty()) {
48+
return Response(
49+
data = emptyList(),
50+
errors =
51+
listOf(
52+
UpstreamApiError(
53+
causedBy = UpstreamApi.PRISONER_OFFENDER_SEARCH,
54+
type = UpstreamApiError.Type.ENTITY_NOT_FOUND,
55+
),
56+
),
57+
)
58+
}
4559
nomisAlerts = Response(data = filteredAlerts, errors = allNomisAlerts.errors)
4660
}
4761

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

+15
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,20 @@ internal class GetAlertsForPersonServiceTest(
137137
response.data[0].code shouldBe "XA"
138138
response.data[0].codeDescription shouldBe "Test Alert XA"
139139
}
140+
141+
it("returns an error when the alert code is not in the allowed list") {
142+
whenever(personService.execute(hmppsId = deliusCrn)).thenReturn(Response(person))
143+
whenever(personService.execute(hmppsId = hmppsId)).thenReturn(Response(person))
144+
whenever(nomisGateway.getAlertsForPerson(prisonerNumber)).thenReturn(
145+
Response(
146+
data = listOf(nonMatchingAlert),
147+
),
148+
)
149+
150+
val response = getAlertsForPersonService.getAlertsForPnd(hmppsId)
151+
152+
response.errors.shouldHaveSize(1)
153+
response.data.shouldHaveSize(0)
154+
}
140155
},
141156
)

0 commit comments

Comments
 (0)