Skip to content

Commit

Permalink
Dont call POS if no prison filters passed in and we already have hmppsId
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwatkins1994 committed Feb 18, 2025
1 parent 7efb747 commit 10a044c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class GetHmppsIdService(
)
}
var hmppsId = personResponse.data?.hmppsId
// If no filters passed in, then we don't need to get the prison ID
if (hmppsId != null && filters == null) {
return Response(data = HmppsId(hmppsId))
}

val (prisoner, prisonerErrors) = getPersonService.getPersonFromNomis(nomisNumber.uppercase())
if (prisonerErrors.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe
import org.mockito.Mockito
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer
import org.springframework.test.context.ContextConfiguration
Expand Down Expand Up @@ -121,7 +123,7 @@ internal class GetHmppsIdServiceTest(
result.shouldBe(Response(data = hmppsId))
}

it("Returns a 200 when no hmppsid returned from getPersonService.execute but found in getPersonService.getPersonFromNomis") {
it("Returns a 200 when no hmppsId returned from getPersonService.execute but found in getPersonService.getPersonFromNomis") {
whenever(getPersonService.execute(id)).thenReturn(
Response(
data = Person(firstName = "Qui-gon", lastName = "Jin"),
Expand All @@ -131,6 +133,12 @@ internal class GetHmppsIdServiceTest(
result.shouldBe(Response(data = hmppsId))
}

it("Returns a 200 when hmppsId returned from getPersonService.execute and no filters passed in") {
val result = getHmppsIdService.execute(id, null)
verify(getPersonService, never()).getNomisNumber(id)
result.shouldBe(Response(data = hmppsId))
}

it("Returns a 404 when no neither service returns an error but hmppsId is null still") {
whenever(getPersonService.execute(id)).thenReturn(
Response(
Expand Down

0 comments on commit 10a044c

Please sign in to comment.