-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProbationStatusIntegrationTest.kt
142 lines (127 loc) · 5.85 KB
/
ProbationStatusIntegrationTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package uk.gov.justice.hmpps.probationsearch.controllers
import io.restassured.RestAssured
import net.javacrumbs.jsonunit.assertj.assertThatJson
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.springframework.http.MediaType
import uk.gov.justice.hmpps.probationsearch.util.PersonSearchHelper
class ProbationStatusIntegrationTest : ElasticIntegrationBase() {
@BeforeEach
fun `load offenders`() {
PersonSearchHelper(openSearchClient).loadData()
}
@Nested
inner class OffenderSearch {
@Test
fun `ProbationStatus is returned from the search`() {
val response = RestAssured.given()
.auth()
.oauth2(jwtAuthenticationHelper.createJwt("ROLE_PROBATION__SEARCH_PERSON"))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body("""{"crn": "X00001"}""")
.post("/search")
.then()
.statusCode(200)
.extract()
.body().asString()
assertThatJson(response).node("[0].otherIds.crn").isEqualTo("X00001")
assertThatJson(response).node("[0].probationStatus.status").isEqualTo("CURRENT")
assertThatJson(response).node("[0].probationStatus.inBreach").isEqualTo(true)
assertThatJson(response).node("[0].probationStatus.preSentenceActivity").isEqualTo(false)
assertThatJson(response).node("[0].probationStatus.awaitingPsr").isEqualTo(true)
assertThatJson(response).node("[0].probationStatus.previouslyKnownTerminationDate").isEqualTo("2021-02-08")
}
@Test
fun `ProbationStatus with null fields is handled in the response`() {
val response = RestAssured.given()
.auth()
.oauth2(jwtAuthenticationHelper.createJwt("ROLE_PROBATION__SEARCH_PERSON"))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body("""{"crn": "X00004"}""")
.post("/search")
.then()
.statusCode(200)
.extract()
.body().asString()
assertThatJson(response).node("[0].otherIds.crn").isEqualTo("X00004")
assertThatJson(response).node("[0].probationStatus.status").isEqualTo("PREVIOUSLY_KNOWN")
assertThatJson(response).node("[0].probationStatus.inBreach").isAbsent()
assertThatJson(response).node("[0].probationStatus.preSentenceActivity").isEqualTo(false)
assertThatJson(response).node("[0].probationStatus.awaitingPsr").isEqualTo(true)
assertThatJson(response).node("[0].probationStatus.previouslyKnownTerminationDate").isAbsent()
}
@Test
fun `Missing ProbationStatus is not included in the response`() {
val response = RestAssured.given()
.auth()
.oauth2(jwtAuthenticationHelper.createJwt("ROLE_PROBATION__SEARCH_PERSON"))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body("""{"crn": "X00002"}""")
.post("/search")
.then()
.statusCode(200)
.extract()
.body().asString()
assertThatJson(response).node("[0].otherIds.crn").isEqualTo("X00002")
assertThatJson(response).node("[0].probationStatus").isAbsent()
}
}
@Nested
inner class OffenderMatch {
@Test
fun `ProbationStatus is returned from the match`() {
val response = RestAssured.given()
.auth()
.oauth2(jwtAuthenticationHelper.createJwt("ROLE_PROBATION__SEARCH_PERSON"))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body("""{"surname": "Smith", "dateOfBirth": "1978-01-06"}""")
.post("/match")
.then()
.statusCode(200)
.extract()
.body().asString()
assertThatJson(response).node("matches[0].offender.otherIds.crn").isEqualTo("X00001")
assertThatJson(response).node("matches[0].offender.probationStatus.status").isEqualTo("CURRENT")
assertThatJson(response).node("matches[0].offender.probationStatus.inBreach").isEqualTo(true)
assertThatJson(response).node("matches[0].offender.probationStatus.awaitingPsr").isEqualTo(true)
assertThatJson(response).node("matches[0].offender.probationStatus.preSentenceActivity").isEqualTo(false)
assertThatJson(response).node("matches[0].offender.probationStatus.previouslyKnownTerminationDate")
.isEqualTo("2021-02-08")
}
@Test
fun `ProbationStatus with null fields is returned from the match`() {
val response = RestAssured.given()
.auth()
.oauth2(jwtAuthenticationHelper.createJwt("ROLE_PROBATION__SEARCH_PERSON"))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body("""{"surname": "Gramsci", "dateOfBirth": "1988-01-06"}""")
.post("/match")
.then()
.statusCode(200)
.extract()
.body().asString()
assertThatJson(response).node("matches[0].offender.otherIds.crn").isEqualTo("X00004")
assertThatJson(response).node("matches[0].offender.probationStatus.status").isEqualTo("PREVIOUSLY_KNOWN")
assertThatJson(response).node("matches[0].offender.probationStatus.inBreach").isAbsent()
assertThatJson(response).node("matches[0].offender.probationStatus.preSentenceActivity").isEqualTo(false)
assertThatJson(response).node("matches[0].offender.probationStatus.awaitingPsr").isEqualTo(true)
assertThatJson(response).node("matches[0].offender.probationStatus.previouslyKnownTerminationDate").isAbsent()
}
@Test
fun `Missing ProbationStatus is not included in the response`() {
val response = RestAssured.given()
.auth()
.oauth2(jwtAuthenticationHelper.createJwt("ROLE_PROBATION__SEARCH_PERSON"))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body("""{"surname": "Smith", "dateOfBirth": "1978-01-16"}""")
.post("/match")
.then()
.statusCode(200)
.extract()
.body().asString()
assertThatJson(response).node("matches[0].offender.otherIds.crn").isEqualTo("X00002")
assertThatJson(response).node("matches[0].offender.probationStatus").isAbsent()
}
}
}