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.
MAN-190: Added lao checks for caseload search
- Loading branch information
Showing
12 changed files
with
252 additions
and
40 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
38 changes: 38 additions & 0 deletions
38
...lius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LimitedAccessGenerator.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,38 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator | ||
import uk.gov.justice.digital.hmpps.entity.Exclusion | ||
import uk.gov.justice.digital.hmpps.entity.LimitedAccessPerson | ||
import uk.gov.justice.digital.hmpps.entity.LimitedAccessUser | ||
import uk.gov.justice.digital.hmpps.entity.Restriction | ||
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Person | ||
import uk.gov.justice.digital.hmpps.integrations.delius.user.entity.User | ||
import java.time.LocalDateTime | ||
|
||
object LimitedAccessGenerator { | ||
val EXCLUSION = generateExclusion(PersonDetailsGenerator.EXCLUSION) | ||
val RESTRICTION = | ||
generateRestriction(PersonDetailsGenerator.RESTRICTION, endDateTime = LocalDateTime.now().plusHours(1)) | ||
val BOTH_EXCLUSION = generateExclusion(PersonDetailsGenerator.RESTRICTION_EXCLUSION) | ||
val BOTH_RESTRICTION = generateRestriction( | ||
PersonDetailsGenerator.RESTRICTION_EXCLUSION, | ||
endDateTime = LocalDateTime.now().plusHours(1) | ||
) | ||
|
||
fun generateExclusion( | ||
person: Person, | ||
user: User = ContactGenerator.LIMITED_ACCESS_USER, | ||
endDateTime: LocalDateTime? = null, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Exclusion(person.limitedAccess(), user.limitedAccess(), endDateTime, id) | ||
|
||
fun generateRestriction( | ||
person: Person, | ||
user: User = ContactGenerator.USER_1, | ||
endDateTime: LocalDateTime? = null, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Restriction(person.limitedAccess(), user.limitedAccess(), endDateTime, id) | ||
|
||
private fun Person.limitedAccess() = LimitedAccessPerson(crn, exclusionMessage, restrictionMessage, id) | ||
private fun User.limitedAccess() = LimitedAccessUser(username, id) | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...ius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/LaoCaseloadIntegrationTest.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,65 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Assertions.assertNotEquals | ||
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.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.api.model.user.StaffCaseload | ||
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.LIMITED_ACCESS_USER | ||
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.EXCLUSION | ||
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.RESTRICTION | ||
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.RESTRICTION_EXCLUSION | ||
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 LaoCaseloadIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `all caseload activity for an lao user`() { | ||
|
||
val person = LIMITED_ACCESS_USER | ||
val res = mockMvc | ||
.perform(get("/caseload/user/${person.username}").withToken()) | ||
.andExpect(status().isOk) | ||
.andReturn().response.contentAsJson<StaffCaseload>() | ||
|
||
assertThat(res.caseload[0].crn, equalTo(EXCLUSION.crn)) | ||
assertThat(res.caseload[1].crn, equalTo(RESTRICTION.crn)) | ||
assertThat(res.caseload[2].crn, equalTo(RESTRICTION_EXCLUSION.crn)) | ||
|
||
assertThat(res.caseload[0].limitedAccess, equalTo(true)) | ||
assertThat(res.caseload[0].caseName, equalTo(null)) | ||
assertThat(res.caseload[0].latestSentence, equalTo(null)) | ||
assertThat(res.caseload[0].nextAppointment, equalTo(null)) | ||
assertThat(res.caseload[0].previousAppointment, equalTo(null)) | ||
assertThat(res.caseload[0].numberOfAdditionalSentences, equalTo(null)) | ||
|
||
assertThat(res.caseload[1].limitedAccess, equalTo(true)) | ||
assertThat(res.caseload[1].caseName, equalTo(null)) | ||
assertThat(res.caseload[1].latestSentence, equalTo(null)) | ||
assertThat(res.caseload[1].nextAppointment, equalTo(null)) | ||
assertThat(res.caseload[1].previousAppointment, equalTo(null)) | ||
assertThat(res.caseload[1].numberOfAdditionalSentences, equalTo(null)) | ||
|
||
assertThat(res.caseload[2].limitedAccess, equalTo(true)) | ||
assertThat(res.caseload[2].caseName, equalTo(null)) | ||
assertThat(res.caseload[2].latestSentence, equalTo(null)) | ||
assertThat(res.caseload[2].nextAppointment, equalTo(null)) | ||
assertThat(res.caseload[2].previousAppointment, equalTo(null)) | ||
assertThat(res.caseload[2].numberOfAdditionalSentences, equalTo(null)) | ||
|
||
assertThat(res.caseload[3].limitedAccess, equalTo(false)) | ||
assertNotEquals(res.caseload[3].caseName, null) | ||
} | ||
} |
Oops, something went wrong.