@@ -9,14 +9,18 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
9
9
import org.springframework.boot.test.context.SpringBootTest
10
10
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
11
11
import org.springframework.test.web.servlet.MockMvc
12
+ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
12
13
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
13
14
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
14
15
import uk.gov.justice.digital.hmpps.api.model.user.StaffCaseload
15
16
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.LIMITED_ACCESS_USER
16
17
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.EXCLUSION
18
+ import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PERSONAL_DETAILS
17
19
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.RESTRICTION
18
20
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.RESTRICTION_EXCLUSION
21
+ import uk.gov.justice.digital.hmpps.service.UserAccess
19
22
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
23
+ import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withJson
20
24
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken
21
25
22
26
@AutoConfigureMockMvc
@@ -27,7 +31,6 @@ internal class LaoCaseloadIntegrationTest {
27
31
28
32
@Test
29
33
fun `all caseload activity for an lao user` () {
30
-
31
34
val person = LIMITED_ACCESS_USER
32
35
val res = mockMvc
33
36
.perform(get(" /caseload/user/${person.username} " ).withToken())
@@ -65,4 +68,42 @@ internal class LaoCaseloadIntegrationTest {
65
68
assertThat(caseload[3 ].limitedAccess, equalTo(false ))
66
69
assertNotEquals(caseload[3 ].caseName, null )
67
70
}
71
+
72
+ @Test
73
+ fun `check lao access for a user with list of crns` () {
74
+ val person = LIMITED_ACCESS_USER
75
+ val crns = listOf (RESTRICTION_EXCLUSION .crn, EXCLUSION .crn, RESTRICTION .crn, PERSONAL_DETAILS .crn)
76
+ val res = mockMvc
77
+ .perform(
78
+ MockMvcRequestBuilders .post(" /user/${person.username} /access" ).withToken()
79
+ .withJson(crns)
80
+ )
81
+ .andExpect(status().isOk)
82
+ .andReturn().response.contentAsJson<UserAccess >()
83
+
84
+ val userAccess = res.access.sortedBy { it.crn }
85
+
86
+ assertThat(userAccess[0 ].userExcluded, equalTo(true ))
87
+ assertThat(userAccess[0 ].userRestricted, equalTo(true ))
88
+
89
+ assertThat(userAccess[1 ].userExcluded, equalTo(true ))
90
+ assertThat(userAccess[1 ].userRestricted, equalTo(false ))
91
+
92
+ assertThat(userAccess[2 ].userExcluded, equalTo(false ))
93
+ assertThat(userAccess[2 ].userRestricted, equalTo(true ))
94
+
95
+ assertThat(userAccess[3 ].userExcluded, equalTo(false ))
96
+ assertThat(userAccess[3 ].userRestricted, equalTo(false ))
97
+ }
98
+
99
+ @Test
100
+ fun `check lao access returns 400 when no crns are provided` () {
101
+ val person = LIMITED_ACCESS_USER
102
+ mockMvc
103
+ .perform(
104
+ MockMvcRequestBuilders .post(" /user/${person.username} /access" ).withToken()
105
+ .withJson(emptyList<String >())
106
+ )
107
+ .andExpect(status().isBadRequest)
108
+ }
68
109
}
0 commit comments