Skip to content

Commit

Permalink
PI-2521: Handle soft deleted records the same as community api
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 committed Sep 16, 2024
1 parent de3de53 commit b6a8f00
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class DataLoader(
CourtGenerator.PROBATION_AREA,
CourtGenerator.BHAM,
PersonGenerator.NEW_TO_PROBATION,
PersonGenerator.SOFT_DELETED,
PersonGenerator.CURRENTLY_MANAGED,
PersonGenerator.PREVIOUSLY_MANAGED,
PersonGenerator.NO_SENTENCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import java.time.ZonedDateTime
object PersonGenerator {

val NEW_TO_PROBATION = generate("N123456")
val SOFT_DELETED = generate("S123456", softDeleted = true)
val CURRENTLY_MANAGED = generate("C123456", currentDisposal = true)
val PREVIOUSLY_MANAGED = generate("P123456")
val NO_SENTENCE = generate("U123456")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.gov.justice.digital.hmpps

import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
Expand Down Expand Up @@ -264,4 +266,13 @@ internal class ConvictionByCrnIntegrationTest {
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.length()").value(0))
}

@Test
fun `convictions record soft deleted return emptyList for convictions`() {
val response = mockMvc
.perform(get("/probation-case/S123456/convictions").withToken())
.andExpect(status().isOk).andReturn()
.response.contentAsJson<List<Conviction>>()
MatcherAssert.assertThat(response, Matchers.equalTo(emptyList()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,33 @@ internal class OffenderIntegrationTest {
.andExpect(status().isNotFound)
}

@Test
fun `probation summary record that is soft deleted still returns`() {
val response = mockMvc
.perform(get("/probation-case/S123456").withToken())
.andExpect(status().isOk).andReturn()
.response.contentAsJson<OffenderDetailSummary>()
assertThat(response.softDeleted, equalTo(true))
}

@Test
fun `probation detail record that is soft deleted still returns`() {
val response = mockMvc
.perform(get("/probation-case/S123456/all").withToken())
.andExpect(status().isOk).andReturn()
.response.contentAsJson<OffenderDetail>()
assertThat(response.softDeleted, equalTo(true))
}

@Test
fun `Detail API call allOffenderManagers record soft deleted`() {
val response = mockMvc
.perform(get("/probation-case/S123456/allOffenderManagers").withToken())
.andExpect(status().isOk).andReturn()
.response.contentAsJson<List<OffenderManager>>()
assertThat(response, equalTo(emptyList()))
}

@Test
fun `Detail API call retuns probation record with no active sentence`() {
val crn = PersonGenerator.NO_SENTENCE.crn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ internal class RegistrationsIntegrationTest {
assertThat(response.registrations?.size, equalTo(2))
assertThat(response.registrations?.get(0)?.active, equalTo(true))
}

@Test
fun `registrations record soft deleted returns null registations`() {
val response = mockMvc
.perform(get("/probation-case/S123456/registrations").withToken())
.andExpect(status().isOk).andReturn()
.response.contentAsJson<Registrations>()
assertThat(response.registrations, equalTo(null))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import java.time.ZonedDateTime
@Immutable
@Entity
@Table(name = "offender")
@SQLRestriction("soft_deleted = 0")
class Person(

@Id
Expand Down Expand Up @@ -346,7 +345,6 @@ interface PersonRepository : JpaRepository<Person, Long> {
left join fetch p.partitionArea pa
left join fetch p.title title
where p.crn = :crn
and p.softDeleted = false
"""
)
fun findByCrn(crn: String): Person?
Expand Down

0 comments on commit b6a8f00

Please sign in to comment.