Skip to content

Commit fd3a6a4

Browse files
committed
Updated tests
1 parent cba37c4 commit fd3a6a4

File tree

5 files changed

+22
-57
lines changed

5 files changed

+22
-57
lines changed

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/PersonControllerTest.kt

+10-45
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal class PersonControllerTest(
4848
val basePath = "/v1/persons"
4949
val firstName = "Barry"
5050
val lastName = "Allen"
51-
val dateOfBirth = LocalDate.parse("2023-03-01")
51+
val dateOfBirth = "2023-03-01"
5252
val mockMvc = IntegrationAPIMockMvc(springMockMvc)
5353

5454
describe("GET $basePath") {
@@ -114,48 +114,6 @@ internal class PersonControllerTest(
114114
verify(getPersonsService, times(1)).execute(firstName, null, null, null)
115115
}
116116

117-
it("returns a person with matching first and last name") {
118-
val result = mockMvc.performAuthorised("$basePath?first_name=$firstName&last_name=$lastName")
119-
result.response.contentAsString.shouldContain(
120-
"""
121-
"data": [
122-
{
123-
"firstName":"Barry",
124-
"lastName":"Allen",
125-
"middleName":"Jonas",
126-
"dateOfBirth":"2023-03-01",
127-
"gender": null,
128-
"ethnicity": null,
129-
"aliases":[],
130-
"identifiers": {
131-
"nomisNumber": null,
132-
"croNumber": null,
133-
"deliusCrn": null
134-
},
135-
"pncId": null,
136-
"hmppsId": null
137-
},
138-
{
139-
"firstName":"Barry",
140-
"lastName":"Allen",
141-
"middleName":"Rock",
142-
"dateOfBirth":"2022-07-22",
143-
"gender": null,
144-
"ethnicity": null,
145-
"aliases":[],
146-
"identifiers": {
147-
"nomisNumber": null,
148-
"croNumber": null,
149-
"deliusCrn": null
150-
},
151-
"pncId": null,
152-
"hmppsId": null
153-
}
154-
]
155-
""".removeWhitespaceAndNewlines(),
156-
)
157-
}
158-
159117
it("logs audit") {
160118
mockMvc.performAuthorised("$basePath?first_name=$firstName&last_name=$lastName&pnc_number=$pncNumber&date_of_birth=$dateOfBirth")
161119
verify(auditService, times(1)).createEvent("SEARCH_PERSON", "Person searched with first name: $firstName, last name: $lastName, search within aliases: false, pnc number: $pncNumber, date of birth: $dateOfBirth")
@@ -175,7 +133,7 @@ internal class PersonControllerTest(
175133
),
176134
)
177135

178-
val result = mockMvc.performAuthorised("$basePath?first_name=$firstName&last_name=$lastName&page=3&perPage=5")
136+
val result = mockMvc.performAuthorised("$basePath?first_name=$firstName&last_name=$lastName&date_of_birth=$dateOfBirth&page=3&perPage=5")
179137

180138
result.response.contentAsString.shouldContainJsonKeyValue("$.pagination.page", 3)
181139
result.response.contentAsString.shouldContainJsonKeyValue("$.pagination.totalPages", 4)
@@ -197,7 +155,7 @@ internal class PersonControllerTest(
197155
}
198156

199157
it("returns a 200 OK status code") {
200-
val result = mockMvc.performAuthorised("$basePath?first_name=$firstName&last_name=$lastName")
158+
val result = mockMvc.performAuthorised("$basePath?first_name=$firstName&last_name=$lastName&date_of_birth=$dateOfBirth")
201159

202160
result.response.status.shouldBe(HttpStatus.OK.value())
203161
}
@@ -208,6 +166,13 @@ internal class PersonControllerTest(
208166
result.response.status.shouldBe(HttpStatus.BAD_REQUEST.value())
209167
result.response.contentAsString.shouldContain("No query parameters specified.")
210168
}
169+
170+
it("returns a 400 BAD REQUEST status code when no search criteria provided") {
171+
val result = mockMvc.performAuthorised("$basePath?date_of_birth=12323423234")
172+
173+
result.response.status.shouldBe(HttpStatus.BAD_REQUEST.value())
174+
result.response.contentAsString.shouldContain("Invalid date format. Please use yyyy-MM-dd.")
175+
}
211176
}
212177

213178
describe("GET $basePath/{id}") {

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/prisoneroffendersearch/PrisonerOffenderSearchGatewayTest.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class PrisonerOffenderSearchGatewayTest(
4646
val firstName = "JAMES"
4747
val lastName = "HOWLETT"
4848
val hmppsId = "B9731BB"
49-
val dateOfBirth = LocalDate.parse("1975-02-28")
49+
val dateOfBirth = "1975-02-28"
5050

5151
beforeEach {
5252
prisonerOffenderSearchApiMockServer.stubPostPrisonerSearch(
@@ -175,7 +175,6 @@ class PrisonerOffenderSearchGatewayTest(
175175
prisonerOffenderSearchApiMockServer.stubPostPrisonerSearch(
176176
"""
177177
{
178-
"lastName": "Binks",
179178
"includeAliases": false,
180179
"dateOfBirth": "1975-02-28"
181180
}
@@ -185,19 +184,20 @@ class PrisonerOffenderSearchGatewayTest(
185184
"content": [
186185
{
187186
"firstName": "Jar Jar",
188-
"lastName": "Binks"
187+
"lastName": "Binks",
188+
"dateOfBirth": "1975-02-28"
189189
}
190190
]
191191
}
192192
""".trimIndent(),
193193
)
194194

195195
val response = prisonerOffenderSearchGateway.getPersons(null, null, null, dateOfBirth)
196-
196+
println(response)
197197
response.data.count().shouldBe(1)
198198
response.data.first().firstName.shouldBe("Jar Jar")
199199
response.data.first().lastName.shouldBe("Binks")
200-
response.data.first().dateOfBirth.shouldBe(dateOfBirth)
200+
response.data.first().dateOfBirth.shouldBe(LocalDate.parse(dateOfBirth))
201201
}
202202

203203
it("returns person(s) when searching within aliases") {

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/probationoffendersearch/ProbationOffenderSearchGatewayTest.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
2222
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
2323
import java.io.File
2424
import java.time.LocalDate
25+
import java.time.format.DateTimeFormatter
2526

2627
@ActiveProfiles("test")
2728
@ContextConfiguration(
@@ -49,7 +50,8 @@ class ProbationOffenderSearchGatewayTest(
4950
val firstName = "Matt"
5051
val surname = "Nolan"
5152
val pncNumber = "2018/0123456X"
52-
val dateOfBirth = LocalDate.parse("1966-10-25")
53+
val dateOfBirth = "1966-10-25"
54+
val dateOfBirthString = dateOfBirth.format(DateTimeFormatter.ISO_DATE)
5355

5456
beforeEach {
5557
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
@@ -58,7 +60,7 @@ class ProbationOffenderSearchGatewayTest(
5860
"firstName": "$firstName",
5961
"surname": "$surname",
6062
"pncNumber": "$pncNumber",
61-
"dateOfBirth": "$dateOfBirth",
63+
"dateOfBirth": "$dateOfBirthString",
6264
"includeAliases": false
6365
}
6466
""".removeWhitespaceAndNewlines(),
@@ -78,7 +80,7 @@ class ProbationOffenderSearchGatewayTest(
7880
response.data.first().firstName.shouldBe(firstName)
7981
response.data.first().lastName.shouldBe(surname)
8082
response.data.first().pncId.shouldBe(pncNumber)
81-
response.data.first().dateOfBirth.shouldBe(dateOfBirth)
83+
response.data.first().dateOfBirth.shouldBe(LocalDate.parse(dateOfBirth))
8284
}
8385

8486
it("returns person(s) when searching on first name and last name") {

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetPersonServiceTest.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
1414
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
1515
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
1616
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
17-
import java.time.LocalDate
1817

1918
@ContextConfiguration(
2019
initializers = [ConfigDataApplicationContextInitializer::class],
@@ -31,7 +30,7 @@ internal class GetPersonServiceTest(
3130
Mockito.reset(prisonerOffenderSearchGateway)
3231
Mockito.reset(probationOffenderSearchGateway)
3332

34-
whenever(prisonerOffenderSearchGateway.getPersons("Qui-gon", "Jin", hmppsId, LocalDate.parse("1966-10-25"))).thenReturn(
33+
whenever(prisonerOffenderSearchGateway.getPersons("Qui-gon", "Jin", hmppsId, "1966-10-25")).thenReturn(
3534
Response(data = listOf(Person(firstName = "Qui-gon", lastName = "Jin", identifiers = Identifiers(nomisNumber = "A1234AA")))),
3635
)
3736
whenever(probationOffenderSearchGateway.getPerson(id = hmppsId)).thenReturn(

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetPersonsServiceTest.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
1414
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
1515
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
1616
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
17-
import java.time.LocalDate
1817

1918
@ContextConfiguration(
2019
initializers = [ConfigDataApplicationContextInitializer::class],
@@ -29,7 +28,7 @@ internal class GetPersonsServiceTest(
2928
val lastName = "Wayne"
3029
val pncNumber = "2003/13116M"
3130
val hmppsId = "A1234AA"
32-
val dateOfBirth = LocalDate.parse("2004-04-19")
31+
val dateOfBirth = "2004-04-19"
3332

3433
beforeEach {
3534
Mockito.reset(prisonerOffenderSearchGateway)

0 commit comments

Comments
 (0)