Skip to content

Commit

Permalink
PI-2199 Only match if there is a single custodial sentence (#3797)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored May 14, 2024
1 parent d99fa85 commit e4ad711
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,18 @@ internal class PrisonMatchingIntegrationTest {

@Test
@Order(2)
fun `single match with existing noms number`() {
fun `no match with existing noms number if no custodial sentence in Delius`() {
val crn = PersonGenerator.PERSON_WITH_NOMS.crn

mockMvc
.perform(post("/person/match-by-crn").withToken().withJson(listOf(crn)))
.andExpect(status().is2xxSuccessful)

verify(telemetryService, timeout(5000)).trackEvent(
"MatchResultSuccess", mapOf(
"reason" to "Matched CRN A000001 to NOMS number E1234XS",
"MatchResultNoMatch", mapOf(
"reason" to "No single match found in prison system",
"crn" to "A000001",
"potentialMatches" to """[{"nomsNumber":"E1234XS"}]""",
"existingNomsNumber" to "E1234XS",
"matchedNomsNumber" to "E1234XS",
"nomsNumberChanged" to "false",
"matchedBookingNumber" to "76543A",
"bookingNumberChanged" to "false",
"totalCustodialEvents" to "1",
"matchingCustodialEvents" to "0",
"dryRun" to "true"
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class PrisonMatchingService(
val matchingCustodies = matchedPrisoner.sentenceStartDate
?.let { person.custodiesWithSentenceDateCloseTo(it) } ?: emptyList()
val matchingCustody = matchingCustodies.singleOrNull()
val matchingPerson = matchingCustodies.map { it.disposal.event.person }.distinctBy { it.crn }.singleOrNull()
if (matchingPerson == null)
return NoMatch("No single match found in prison system", prisonerMatches.telemetry())

return Success(
identifiers, person, matchingCustody, prisonerMatches.telemetry() + mapOf(
Expand Down

0 comments on commit e4ad711

Please sign in to comment.