Skip to content

Commit

Permalink
PI-2586 - fix conflicts with main
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-bcl committed Jan 9, 2025
1 parent b9c72a6 commit 3ef6c37
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,16 @@ internal class IntegrationTest {
fun resetWireMock() {
wireMockServer.resetAll()
}

@AfterEach
fun cleanup() {
courtAppearanceRepository.deleteAll()
mainOffenceRepository.deleteAll()
orderManagerRepository.deleteAll()
eventRepository.deleteAll()
addressRepository.deleteAll()
contactRepository.deleteAll()
personManagerRepository.deleteAll()
personRepository.deleteAll()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ class Handler(
offence.judicialResults?.any { it.label == "Remanded in custody" } == true
}

// TODO: Currently using the first offence, We will need to identify the main offence
val mainOffence = remandedOffences.firstOrNull()
?: return@forEach

val caseUrn = hearing.prosecutionCases
val caseUrn = notification.message.hearing.prosecutionCases
.find { it.defendants.contains(defendant) }
?.prosecutionCaseIdentifier?.caseURN ?: return@forEach

Expand All @@ -114,13 +115,13 @@ class Handler(
if (existingCourtAppearance != null) {
val savedCourtAppearance = eventService.insertCourtAppearance(
existingCourtAppearance.event,
courtCode,
hearing.hearingDays.first().sittingDay,
notification.message.hearing.courtCentre.code,
notification.message.hearing.hearingDays.first().sittingDay,
caseUrn
)
telemetryService.trackEvent(
"CourtAppearanceCreated", mapOf(
"hearingId" to hearing.id,
"hearingId" to notification.message.hearing.id,
"courtAppearanceId" to savedCourtAppearance.id.toString(),
"personId" to savedCourtAppearance.person.id.toString(),
"eventId" to savedCourtAppearance.event.id.toString(),
Expand All @@ -129,14 +130,14 @@ class Handler(
} else {
val savedEventEntities = eventService.insertEvent(
mainOffence,
savedPersonEntities.person,
courtCode,
hearing.hearingDays.first().sittingDay,
savedEntities.person,
notification.message.hearing.courtCentre.code,
notification.message.hearing.hearingDays.first().sittingDay,
caseUrn
)
telemetryService.trackEvent(
"EventCreated", mapOf(
"hearingId" to hearing.id,
"hearingId" to notification.message.hearing.id,
"eventId" to savedEventEntities.event.id.toString(),
"eventNumber" to savedEventEntities.event.number,
"CRN" to savedEventEntities.event.person.crn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ import org.mockito.Mockito.anyMap
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.*
import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.data.generator.MessageGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonAddressGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonManagerGenerator
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.data.generator.*
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.client.*
import uk.gov.justice.digital.hmpps.integrations.delius.entity.CourtAppearanceRepository
import uk.gov.justice.digital.hmpps.integrations.delius.entity.Equality
Expand Down Expand Up @@ -77,7 +73,7 @@ internal class HandlerTest {
)

probationSearchMatchNotFound()
whenever(featureFlags.enabled("common-platform-record-creation-toggle")).thenReturn(true)
featureFlagIsEnabled(true)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)
handler.handle(notification)
Expand Down Expand Up @@ -124,8 +120,7 @@ internal class HandlerTest {
@Test
fun `Person created logged when feature flag enabled`() {
probationSearchMatchNotFound()

whenever(featureFlags.enabled("common-platform-record-creation-toggle")).thenReturn(true)
featureFlagIsEnabled(true)
whenever(personService.insertPerson(any(), any())).thenReturn(
InsertPersonResult(
person = PersonGenerator.DEFAULT,
Expand All @@ -134,6 +129,16 @@ internal class HandlerTest {
address = PersonAddressGenerator.MAIN_ADDRESS,
)
)
whenever(courtAppearanceRepository.findLatestByCaseUrn(any())).thenReturn(null)
whenever(eventService.insertEvent(any(), any(), any(), any(), any())).thenReturn(
InsertEventResult(
EventGenerator.DEFAULT,
MainOffenceGenerator.DEFAULT,
listOf(CourtAppearanceGenerator.TRIAL_ADJOURNMENT, CourtAppearanceGenerator.TRIAL_ADJOURNMENT),
listOf(ContactGenerator.EAPP, ContactGenerator.EAPP),
OrderManagerGenerator.DEFAULT
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)
handler.handle(notification)
Expand All @@ -148,8 +153,7 @@ internal class HandlerTest {
@Test
fun `Simulated person created logged when feature flag disabled`() {
probationSearchMatchNotFound()
whenever(featureFlags.enabled("common-platform-record-creation-toggle")).thenReturn(false)

featureFlagIsEnabled(false)
val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)
handler.handle(notification)

Expand All @@ -162,8 +166,9 @@ internal class HandlerTest {

@Test
fun `Inserts event when case urn does not exist`() {
probationSearchMatchNotFound()
featureFlagIsEnabled(true)
whenever(courtAppearanceRepository.findLatestByCaseUrn(any())).thenReturn(null)

whenever(personService.insertPerson(any(), any())).thenReturn(
InsertPersonResult(
person = PersonGenerator.DEFAULT,
Expand All @@ -172,7 +177,6 @@ internal class HandlerTest {
address = PersonAddressGenerator.MAIN_ADDRESS,
)
)

whenever(eventService.insertEvent(any(), any(), any(), any(), any())).thenReturn(
InsertEventResult(
EventGenerator.DEFAULT,
Expand All @@ -183,13 +187,6 @@ internal class HandlerTest {
)
)

whenever(probationSearchClient.match(any())).thenReturn(
ProbationMatchResponse(
matches = emptyList(),
matchedBy = "NONE"
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)

handler.handle(notification)
Expand All @@ -204,6 +201,8 @@ internal class HandlerTest {

@Test
fun `Inserts court appearance record when case urn exists`() {
probationSearchMatchNotFound()
featureFlagIsEnabled(true)
whenever(courtAppearanceRepository.findLatestByCaseUrn(any())).thenReturn(CourtAppearanceGenerator.TRIAL_ADJOURNMENT)

whenever(personService.insertPerson(any(), any())).thenReturn(
Expand All @@ -219,13 +218,6 @@ internal class HandlerTest {
CourtAppearanceGenerator.TRIAL_ADJOURNMENT
)

whenever(probationSearchClient.match(any())).thenReturn(
ProbationMatchResponse(
matches = emptyList(),
matchedBy = "NONE"
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)

handler.handle(notification)
Expand Down Expand Up @@ -263,4 +255,8 @@ internal class HandlerTest {
)
whenever(probationSearchClient.match(any())).thenReturn(fakeMatchResponse)
}

private fun featureFlagIsEnabled(flag: Boolean) {
whenever(featureFlags.enabled("common-platform-record-creation-toggle")).thenReturn(flag)
}
}

0 comments on commit 3ef6c37

Please sign in to comment.