Skip to content

Commit

Permalink
PI-2030 Log to Telemetry if merge is already up-to-date in Delius (#3534
Browse files Browse the repository at this point in the history
)
  • Loading branch information
marcus-bcl authored Mar 25, 2024
1 parent 239d042 commit 891d726
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package uk.gov.justice.digital.hmpps

import com.github.tomakehurst.wiremock.WireMockServer
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.mockito.Mockito.verify
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
Expand Down Expand Up @@ -35,7 +32,7 @@ internal class MergeIntegrationTest {

verify(telemetryService).trackEvent(
"MergeResultSuccess", mapOf(
"reason" to "Replaced NOMS numbers for 1 records",
"reason" to "Replaced NOMS numbers for 1 record",
"existingNomsNumber" to "A0007AA",
"updatedNomsNumber" to "B0007BB",
"matches" to """[{"crn":"A000007"}]""",
Expand All @@ -45,14 +42,19 @@ internal class MergeIntegrationTest {
}

@Test
fun `merge fails if the new noms number is already assigned`() {
fun `logs event if the new noms number is already assigned`() {
val event = prepEvent("prisoner-merged", wireMockServer.port()).apply {
message.additionalInformation["nomsNumber"] = PERSON_WITH_NOMS.nomsNumber!!
}

val exception = assertThrows<IllegalArgumentException> { handler.handle(event) }
handler.handle(event)

assertThat(exception.message, equalTo("NOMS number E1234XS is already assigned to A000001"))
verify(telemetryService).trackEvent(
"MergeResultIgnored", mapOf(
"reason" to "NOMS number E1234XS is already assigned to A000001",
"dryRun" to "false",
)
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ProbationMatchingService(

fun replaceIdentifiers(oldNomsNumber: String, newNomsNumber: String, dryRun: Boolean): MergeResult {
personRepository.findAllByNomsNumber(newNomsNumber).joinToString { it.crn }.takeIf { it.isNotEmpty() }?.let {
throw IllegalArgumentException("NOMS number $newNomsNumber is already assigned to $it")
return MergeResult.Ignored("NOMS number $newNomsNumber is already assigned to $it")
}

val existing = personRepository.findAllByNomsNumber(oldNomsNumber)
Expand All @@ -48,7 +48,7 @@ class ProbationMatchingService(
}
}
return MergeResult.Success(
"Replaced NOMS numbers for ${existing.size} records", mapOf(
"Replaced NOMS numbers for ${existing.size} record${if (existing.size == 1) "" else "s"}", mapOf(
"existingNomsNumber" to oldNomsNumber,
"updatedNomsNumber" to newNomsNumber,
"matches" to objectMapper.writeValueAsString(existing.map { mapOf("crn" to it.crn) })
Expand Down

0 comments on commit 891d726

Please sign in to comment.