generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pi 2105 crn crn convictions conviction id requirements (#3951)
* PI-2105 add model, service and repo files Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update service and repo layer Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 add resource layer and update service Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 add integration test and small refactor Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 small refactor Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update integration test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update model and integration test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update model and integration test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update model and integration test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update model and integration test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update model and integration test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update model and integration test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update model and integration test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 service and integration refactor Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 update test Signed-off-by: Amardeep Chimber <[email protected]> * PI-2105 - remove commented code * PI-2105 - fix np error in dev --------- Signed-off-by: Amardeep Chimber <[email protected]>
- Loading branch information
1 parent
ef711bf
commit 8314e4e
Showing
13 changed files
with
432 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...elius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/RequirementsGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.CURRENT_SENTENCE | ||
import uk.gov.justice.digital.hmpps.integrations.delius.event.conviction.entity.Requirement | ||
import java.time.LocalDate | ||
|
||
object RequirementsGenerator { | ||
|
||
val ACTIVE_REQ = Requirement( | ||
IdGenerator.getAndIncrement(), | ||
CURRENT_SENTENCE.id, | ||
"notes", | ||
LocalDate.of(2024, 1, 1), | ||
LocalDate.of(2024, 1, 2), | ||
LocalDate.of(2024, 1, 3), | ||
LocalDate.of(2024, 1, 4), | ||
LocalDate.of(2024, 1, 5), | ||
ReferenceDataGenerator.REQUIREMENT_SUB_CAT, | ||
ReferenceDataGenerator.REQUIREMENT_MAIN_CAT, | ||
ReferenceDataGenerator.AD_REQUIREMENT_MAIN_CAT, | ||
ReferenceDataGenerator.AD_REQUIREMENT_SUB_CAT, | ||
ReferenceDataGenerator.TERMINATION_REASON, | ||
3, | ||
active = true | ||
) | ||
|
||
val INACTIVE_REQ = generate(CURRENT_SENTENCE.id, active = false, softDeleted = false) | ||
|
||
val DELETED_REQ = generate(CURRENT_SENTENCE.id, active = true, softDeleted = true) | ||
|
||
val INACTIVE_AND_DELETED_REQ = generate(CURRENT_SENTENCE.id, active = false, softDeleted = true) | ||
|
||
fun generate( | ||
disposalId: Long, | ||
active: Boolean, | ||
softDeleted: Boolean, | ||
) = Requirement( | ||
IdGenerator.getAndIncrement(), | ||
disposalId, | ||
active = active, | ||
softDeleted = softDeleted, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...tegrationTest/kotlin/uk/gov/justice/digital/hmpps/RequirementsByEventIdIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.CsvSource | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.api.model.KeyValue | ||
import uk.gov.justice.digital.hmpps.api.model.conviction.ConvictionRequirements | ||
import uk.gov.justice.digital.hmpps.api.model.conviction.Requirement | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.RequirementsGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
internal class RequirementsByEventIdIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `unauthorized status returned`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
mockMvc | ||
.perform(get("/probation-case/$crn/convictions/123/requirements")) | ||
.andExpect(status().isUnauthorized) | ||
} | ||
|
||
@Test | ||
fun `probation record not found`() { | ||
mockMvc | ||
.perform(get("/probation-case/A123456/convictions/123/requirements").withToken()) | ||
.andExpect(status().isNotFound) | ||
.andExpect(jsonPath("$.message").value("Person with crn of A123456 not found")) | ||
} | ||
|
||
@Test | ||
fun `sentence not found`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
|
||
mockMvc | ||
.perform(get("/probation-case/$crn/convictions/3/requirements").withToken()) | ||
.andExpect(status().isNotFound) | ||
.andExpect(jsonPath("$.message").value("Conviction with convictionId 3 not found")) | ||
} | ||
|
||
@Test | ||
fun `return list of requirements`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
val event = SentenceGenerator.CURRENTLY_MANAGED | ||
|
||
val requirement = RequirementsGenerator.ACTIVE_REQ | ||
val expectedResponse = ConvictionRequirements( | ||
listOf( | ||
Requirement( | ||
requirement.id, | ||
requirement.notes, | ||
requirement.commencementDate, | ||
requirement.startDate, | ||
requirement.terminationDate, | ||
requirement.expectedStartDate, | ||
requirement.expectedEndDate, | ||
requirement.active, | ||
requirement.subCategory?.let { KeyValue(it.code, it.description) }, | ||
requirement.mainCategory?.let { KeyValue(it.code, it.description) }, | ||
requirement.adMainCategory?.let { KeyValue(it.code, it.description) }, | ||
requirement.adSubCategory?.let { KeyValue(it.code, it.description) }, | ||
requirement.terminationReason?.let { KeyValue(it.code, it.description) }, | ||
requirement.length, | ||
requirement.mainCategory?.let { it.units?.description }, | ||
restrictive = false, | ||
softDeleted = false, | ||
rarCount = requirement.rarCount | ||
) | ||
) | ||
) | ||
|
||
val response = mockMvc | ||
.perform(get("/probation-case/$crn/convictions/${event.id}/requirements").withToken()) | ||
.andExpect(status().isOk) | ||
.andDo(print()) | ||
.andReturn().response.contentAsJson<ConvictionRequirements>() | ||
|
||
assertEquals(expectedResponse, response) | ||
} | ||
|
||
@Test | ||
fun `return empty list of requirements`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
val event = SentenceGenerator.INACTIVE_EVENT | ||
|
||
mockMvc | ||
.perform(get("/probation-case/$crn/convictions/${event.id}/requirements").withToken()) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.requirements").isEmpty) | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource( | ||
"activeOnly=false,false,false", | ||
"excludeSoftDeleted=false,true,true", | ||
"activeOnly=false&&excludeSoftDeleted=false,false,true" | ||
) | ||
fun `return list based on request parameters`(requestParams: String, active: Boolean, deleted: Boolean) { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
val event = SentenceGenerator.CURRENTLY_MANAGED | ||
|
||
mockMvc | ||
.perform(get("/probation-case/$crn/convictions/${event.id}/requirements?$requestParams").withToken()) | ||
.andExpect(status().isOk) | ||
.andDo(print()) | ||
.andExpect(jsonPath("$.requirements.length()").value(1)) | ||
.andExpect(jsonPath("$.requirements[0].active").value(active)) | ||
.andExpect(jsonPath("$.requirements[0].softDeleted").value(deleted)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...c/main/kotlin/uk/gov/justice/digital/hmpps/api/model/conviction/ConvictionRequirements.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uk.gov.justice.digital.hmpps.api.model.conviction | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
import uk.gov.justice.digital.hmpps.api.model.KeyValue | ||
import java.time.LocalDate | ||
|
||
data class ConvictionRequirements( | ||
val requirements: List<Requirement> | ||
) | ||
|
||
data class Requirement( | ||
@Schema(description = "Unique identifier for the requirement", required = true) | ||
val requirementId: Long, | ||
@Schema(description = "Name of the requirement", required = true) | ||
val requirementNotes: String?, | ||
val commencementDate: LocalDate?, | ||
val startDate: LocalDate?, | ||
val terminationDate: LocalDate?, | ||
val expectedStartDate: LocalDate?, | ||
val expectedEndDate: LocalDate?, | ||
@Schema(description = "Is the requirement currently active") | ||
val active: Boolean, | ||
val requirementTypeSubCategory: KeyValue?, | ||
val requirementTypeMainCategory: KeyValue?, | ||
val adRequirementTypeMainCategory: KeyValue?, | ||
val adRequirementTypeSubCategory: KeyValue?, | ||
val terminationReason: KeyValue?, | ||
@Schema(description = "The number of temporal units to complete the requirement (see lengthUnit field for unit)") | ||
val length: Long?, | ||
@Schema(description = "The temporal unit corresponding to the length field") | ||
val lengthUnit: String?, | ||
@Schema(description = "Is the main category restrictive") | ||
val restrictive: Boolean?, | ||
val softDeleted: Boolean, | ||
@Schema(description = "Total RAR days completed") | ||
val rarCount: Long? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.