From 6f3509c1d9b2e255e13eaac554ac3aac546ae56b Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Mon, 18 Mar 2024 16:03:23 +0000 Subject: [PATCH] PI-1939 - add additional sentences to Conviction and update tests --- .../data/generator/AdditionalSentenceGenerator.kt | 2 +- .../justice/digital/hmpps/SentenceIntegrationTest.kt | 6 ++---- .../digital/hmpps/api/model/sentence/Conviction.kt | 3 ++- .../digital/hmpps/api/model/sentence/Sentence.kt | 2 +- .../justice/digital/hmpps/service/SentenceService.kt | 6 ++++-- .../digital/hmpps/service/SentenceServiceTest.kt | 12 +++++++++--- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AdditionalSentenceGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AdditionalSentenceGenerator.kt index 998c1d834b..99f4b9d2cf 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AdditionalSentenceGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AdditionalSentenceGenerator.kt @@ -10,7 +10,7 @@ object AdditionalSentenceGenerator { val REF_FINE = generateReferenceDate("FINE", "Fine") val SENTENCE_DISQ = generateSentence(length = 3, referenceData = REF_DISQ) - val SENTENCE_FINE = generateSentence(amount = 500, referenceData = REF_FINE) + val SENTENCE_FINE = generateSentence(amount = 500, referenceData = REF_FINE, notes = "fine notes") fun generateSentence( length: Long? = null, amount: Long? = null, diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index 947cbb5ac0..40698c359d 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -41,8 +41,7 @@ class SentenceIntegrationTest { Offence("Assault", 1) ) ), - Conviction("Hull Court", "Birmingham Court", LocalDate.now()), - listOf(AdditionalSentence(3, null, null, "Disqualified from Driving")) + Conviction("Hull Court", "Birmingham Court", LocalDate.now(), listOf(AdditionalSentence(3, null, null, "Disqualified from Driving"))) ), Sentence( OffenceDetails( @@ -51,8 +50,7 @@ class SentenceIntegrationTest { "overview", emptyList() ), - Conviction(null, null, null), - listOf() + Conviction(null, null, null, listOf()) ) ) ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Conviction.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Conviction.kt index 2fbb62032d..c1ff81d123 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Conviction.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Conviction.kt @@ -5,5 +5,6 @@ import java.time.LocalDate data class Conviction( val sentencingCourt: String?, val responsibleCourt: String?, - val convictionDate: LocalDate? + val convictionDate: LocalDate?, + val additionalSentences: List ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt index 9dbde13bab..dc63ad1280 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt @@ -3,5 +3,5 @@ package uk.gov.justice.digital.hmpps.api.model.sentence data class Sentence( val offence: OffenceDetails, val conviction: Conviction? = null, - val additionalSentences: List + ) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index 2b50199c41..a2ec4dfbf2 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -36,8 +36,10 @@ class SentenceService( } ) ), - Conviction(sentencingCourt = courtAppearance?.court?.name, responsibleCourt = court?.name, convictionDate = convictionDate), - additionalSentences.map { it.toAdditionalSentence() } + Conviction(sentencingCourt = courtAppearance?.court?.name, + responsibleCourt = court?.name, + convictionDate = convictionDate, + additionalSentences.map { it.toAdditionalSentence() }) ) } diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt index c768f1a6e9..763f18a04d 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt @@ -8,6 +8,7 @@ import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension import org.mockito.kotlin.* import uk.gov.justice.digital.hmpps.api.model.sentence.* +import uk.gov.justice.digital.hmpps.data.generator.AdditionalSentenceGenerator import uk.gov.justice.digital.hmpps.data.generator.CourtAppearanceGenerator import uk.gov.justice.digital.hmpps.data.generator.CourtGenerator import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator @@ -71,6 +72,9 @@ class SentenceServiceTest { .getFirstCourtAppearanceByEventIdOrderByDate(event.id)) .thenReturn(CourtAppearanceGenerator.generate(CourtGenerator.DEFAULT)) + whenever(additionalSentenceRepository.getAllByEvent_Id(event.id)) + .thenReturn(listOf(AdditionalSentenceGenerator.SENTENCE_DISQ, AdditionalSentenceGenerator.SENTENCE_FINE)) + val response = service.getMostRecentActiveEvent(PersonGenerator.OVERVIEW.crn) val expected = SentenceOverview( @@ -86,9 +90,11 @@ class SentenceServiceTest { ), Conviction("Hull Court", null, - null - ), - listOf() + null, + listOf(AdditionalSentence(3, null, null, "Disqualified from Driving"), + AdditionalSentence(null, 500, "fine notes", "Fine") + ) + ) ) ) )