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.
Feature/pi 2104 crn convictions conviction id pss requirements (#4051)
* PI-2104 - add new api * PI-2104 - update tests * Formatting changes * PI-2104 - refactor model object --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9b7c13a
commit 77d9aab
Showing
10 changed files
with
247 additions
and
22 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
83 changes: 83 additions & 0 deletions
83
...Test/kotlin/uk/gov/justice/digital/hmpps/PssRequirementsByCrnAndEventIdIntegrationTest.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,83 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
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 | ||
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.conviction.PssRequirement | ||
import uk.gov.justice.digital.hmpps.api.model.conviction.PssRequirements | ||
import uk.gov.justice.digital.hmpps.api.model.keyValueOf | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator | ||
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 PssRequirementsByCrnAndEventIdIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `unauthorized status returned`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
mockMvc | ||
.perform(get("/probation-case/$crn/convictions/1/pssRequirements")) | ||
.andExpect(status().isUnauthorized) | ||
} | ||
|
||
@Test | ||
fun `API call probation record not found`() { | ||
mockMvc | ||
.perform(get("/probation-case/A123456/convictions/1/pssRequirements").withToken()) | ||
.andExpect(status().isNotFound) | ||
.andExpect(jsonPath("$.message").value("Person with crn of A123456 not found")) | ||
} | ||
|
||
@Test | ||
fun `API call sentence not found`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
|
||
mockMvc | ||
.perform(get("/probation-case/$crn/convictions/3/pssRequirements").withToken()) | ||
.andExpect(status().isNotFound) | ||
.andExpect(jsonPath("$.message").value("Conviction with convictionId 3 not found")) | ||
} | ||
|
||
@Test | ||
fun `API call retuns pss requirements by crn convictionId`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
val event = SentenceGenerator.CURRENTLY_MANAGED | ||
|
||
val pssRequirements = listOf( | ||
PssRequirement( | ||
ReferenceDataGenerator.PSS_MAIN_CAT.keyValueOf(), | ||
ReferenceDataGenerator.PSS_SUB_CAT.keyValueOf(), | ||
true | ||
), | ||
PssRequirement( | ||
ReferenceDataGenerator.PSS_MAIN_CAT.keyValueOf(), | ||
ReferenceDataGenerator.PSS_SUB_CAT.keyValueOf(), | ||
false | ||
), | ||
) | ||
|
||
val expectedResponse = PssRequirements(pssRequirements) | ||
|
||
val response = mockMvc | ||
.perform(get("/probation-case/$crn/convictions/${event.id}/pssRequirements").withToken()) | ||
.andExpect(status().is2xxSuccessful) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andReturn().response.contentAsJson<PssRequirements>() | ||
|
||
assertEquals(expectedResponse, response) | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...lius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/conviction/PssRequirements.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,16 @@ | ||
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 | ||
|
||
data class PssRequirements( | ||
@Schema(description = "List of pssRequirements associated with this conviction") | ||
val pssRequirements: List<PssRequirement> | ||
) | ||
|
||
data class PssRequirement( | ||
val type: KeyValue?, | ||
val subType: KeyValue?, | ||
@Schema(description = "Is the requirement currently active") | ||
val active: Boolean | ||
) |
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
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
Oops, something went wrong.