Skip to content

Commit

Permalink
PI-2096 update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeep Chimber <[email protected]>
  • Loading branch information
achimber-moj committed Jun 20, 2024
1 parent 67980f4 commit 096b277
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class DataLoader(
PersonGenerator.CURRENTLY_MANAGED,
PersonGenerator.PREVIOUSLY_MANAGED,
PersonGenerator.NO_SENTENCE,
PersonGenerator.NO_ACTIVE_EVENTS,
PersonGenerator.PROVISION_1,
PersonGenerator.DISABILITY_1,
PersonGenerator.PREVIOUS_CONVICTION_DOC,
Expand Down Expand Up @@ -156,6 +157,7 @@ class DataLoader(
em.saveAll(
currentEvent,
SentenceGenerator.INACTIVE_EVENT,
SentenceGenerator.INACTIVE_EVENT_1,
currentSentence,
AdditionalSentenceGenerator.SENTENCE_DISQ,
ReferenceDataGenerator.HOURS_WORKED,
Expand All @@ -181,6 +183,7 @@ class DataLoader(
SentenceGenerator.HANDOVER_KEY_DATE,
mainOffence,
SentenceGenerator.MAIN_OFFENCE_FOR_INACTIVE_EVENT,
SentenceGenerator.MAIN_OFFENCE_FOR_INACTIVE_EVENT_1,
additionalOffence,
requirement,
licenceCondition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object PersonGenerator {
val CURRENTLY_MANAGED = generate("C123456", currentDisposal = true)
val PREVIOUSLY_MANAGED = generate("P123456")
val NO_SENTENCE = generate("U123456")
val NO_ACTIVE_EVENTS = generate("Z123456")

val PROVISION_1 = generateProvision(CURRENTLY_MANAGED.id, null)
val DISABILITY_1 = generateDisability(CURRENTLY_MANAGED.id, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ object SentenceGenerator {
active = false
)

val INACTIVE_EVENT_1 = generateEvent(
PersonGenerator.NO_ACTIVE_EVENTS,
referralDate = LocalDate.now().minusDays(1),
inBreach = true,
breachDate = LocalDate.now().minusMonths(3),
court = CourtGenerator.BHAM,
active = false
)

val CURRENT_SENTENCE = generateSentence(
CURRENTLY_MANAGED,
LocalDate.now(),
Expand Down Expand Up @@ -240,6 +249,17 @@ object SentenceGenerator {
ZonedDateTime.of(LocalDate.now().plusDays(1), LocalTime.NOON, TIME_ZONE),
)

val MAIN_OFFENCE_FOR_INACTIVE_EVENT_1 =
generateMainOffence(
INACTIVE_EVENT_1,
MAIN_OFFENCE,
LocalDate.now(),
offenceCount = 1,
PersonGenerator.NO_ACTIVE_EVENTS.id,
ZonedDateTime.of(LocalDate.now().minusDays(3), LocalTime.NOON, TIME_ZONE),
ZonedDateTime.of(LocalDate.now().plusDays(1), LocalTime.NOON, TIME_ZONE),
)

val ADDITIONAL_OFFENCE_DEFAULT = generateAdditionalOffence(
CURRENTLY_MANAGED,
ADDITIONAL_OFFENCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ internal class ConvictionIntegrationByCrnAndEventIdTest {
@Autowired
lateinit var mockMvc: MockMvc

@Test
fun `unauthorized status returned`() {
val crn = PersonGenerator.CURRENTLY_MANAGED.crn
mockMvc
.perform(get("/probation-case/$crn/convictions/1"))
.andExpect(status().isUnauthorized)
}

@Test
fun `API call probation record not found`() {
mockMvc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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
Expand Down Expand Up @@ -38,6 +37,14 @@ internal class ConvictionIntegrationByCrnTest {
@Autowired
lateinit var mockMvc: MockMvc

@Test
fun `unauthorized status returned`() {
val crn = PersonGenerator.CURRENTLY_MANAGED.crn
mockMvc
.perform(get("/probation-case/$crn/convictions"))
.andExpect(status().isUnauthorized)
}

@Test
fun `API call probation record not found`() {
mockMvc
Expand All @@ -47,7 +54,7 @@ internal class ConvictionIntegrationByCrnTest {
}

@Test
fun `API call retuns list of events for a person`() {
fun `retun a list of active events for a person`() {
val crn = PersonGenerator.CURRENTLY_MANAGED.crn
val event = SentenceGenerator.CURRENTLY_MANAGED
val mainOffence = SentenceGenerator.MAIN_OFFENCE_DEFAULT
Expand Down Expand Up @@ -232,9 +239,29 @@ internal class ConvictionIntegrationByCrnTest {
val response = mockMvc
.perform(get("/probation-case/$crn/convictions?activeOnly=true").withToken())
.andExpect(status().is2xxSuccessful)
.andDo(print())
.andReturn().response.contentAsJson<List<Conviction>>()

assertEquals(expectedResponse, response)
}

@Test
fun `retun a list of active and inactive events for a person`() {
val crn = PersonGenerator.CURRENTLY_MANAGED.crn

val response = mockMvc
.perform(get("/probation-case/$crn/convictions").withToken())
.andExpect(status().is2xxSuccessful)
.andReturn().response.contentAsJson<List<Conviction>>()

assertEquals(2, response.size)
}

@Test
fun `retun a empty list for a person with no active events`() {
val crn = PersonGenerator.NO_ACTIVE_EVENTS.crn
mockMvc
.perform(get("/probation-case/$crn/convictions?activeOnly=true").withToken())
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.length()").value(0))
}
}

0 comments on commit 096b277

Please sign in to comment.