Skip to content

Commit

Permalink
PI-1939 - handle null code_description from r_standard_reference_list… (
Browse files Browse the repository at this point in the history
#3629)

PI-1939 - handle null code_description from r_standard_reference_list table

Signed-off-by: Amardeep Chimber <[email protected]>
  • Loading branch information
achimber-moj authored Apr 15, 2024
1 parent 9d4e4d9 commit 6253ccc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ interface RequirementDetails {
val lengthUnitValue: String?
val code: String
val description: String
val codeDescription: String
val codeDescription: String?
val notes: String?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ class SentenceService(
return requirement
}

fun populateRequirementDescription(description: String, codeDescription: String, rar: Rar?): String {
fun populateRequirementDescription(description: String, codeDescription: String?, rar: Rar?): String {
rar?.let { return "" + it.totalDays + " days RAR, " + it.completed + " completed" }

return "$description - $codeDescription"
if (codeDescription != null) {
return "$description - $codeDescription"
}

return description
}

private fun getRar(requirementId: Long, requirementType: String): Rar? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ class SentenceServiceTest {
"rar requirement"
)

val requirement3 = RequirementDetails(
1,
LocalDate.now(),
LocalDate.now(),
null,
LocalDate.now().minusDays(7),
null,
"Expired (Normal)",
null,
null,
"RM49",
"Curfew (Electronic Monitored)",
null,
"new requirement"
)

val courtDocumentDetails = CourtDocs("A001", LocalDate.now(), "Pre Sentence Event")

val completedRarDays = OverviewServiceTest.RarDays(1, "COMPLETED")
Expand All @@ -142,7 +158,7 @@ class SentenceServiceTest {
.thenReturn(listOf(AdditionalSentenceGenerator.SENTENCE_DISQ, AdditionalSentenceGenerator.SENTENCE_FINE))

whenever(requirementRepository.getRequirements(event.id, event.eventNumber))
.thenReturn(listOf(requirement1, requirement2))
.thenReturn(listOf(requirement1, requirement2, requirement3))

whenever(requirementRepository.getRarDaysByRequirementId(requirement2._id)).thenReturn(
listOf(
Expand Down Expand Up @@ -208,6 +224,19 @@ class SentenceServiceTest {
requirement2.lengthUnitValue,
requirement2._notes,
Rar(1, 2, 3)
),
Requirement(
requirement3._code,
requirement3._expectedStartDate,
requirement3._startDate,
requirement3._expectedEndDate,
requirement3._terminationDate,
requirement3._terminationReason,
requirement3._description,
requirement3._length,
requirement3.lengthUnitValue,
requirement3._notes,
null
)
),
listOf(CourtDocument("A001", LocalDate.now(), "Pre Sentence Event"))
Expand Down Expand Up @@ -240,7 +269,7 @@ class SentenceServiceTest {
val _lengthUnitValue: String?,
val _code: String,
val _description: String,
val _codeDescription: String,
val _codeDescription: String?,
val _notes: String?
) : uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.RequirementDetails {
override val id: Long
Expand Down Expand Up @@ -276,7 +305,7 @@ class SentenceServiceTest {
override val description: String
get() = _description

override val codeDescription: String
override val codeDescription: String?
get() = _codeDescription

override val notes: String?
Expand Down

0 comments on commit 6253ccc

Please sign in to comment.