Skip to content

Commit 06d882d

Browse files
committed
CDPS-1090: Edit country of birth
1 parent f1f6d00 commit 06d882d

File tree

6 files changed

+79
-19
lines changed

6 files changed

+79
-19
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/common/client/PrisonApiClient.kt

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.springframework.web.bind.annotation.PathVariable
55
import org.springframework.web.bind.annotation.RequestBody
66
import org.springframework.web.service.annotation.HttpExchange
77
import org.springframework.web.service.annotation.PutExchange
8+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthCountry
89
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthPlace
910
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateNationality
1011

@@ -16,6 +17,12 @@ interface PrisonApiClient {
1617
@RequestBody updateBirthPlace: UpdateBirthPlace,
1718
): ResponseEntity<Void>
1819

20+
@PutExchange("/{offenderNo}/birth-country")
21+
fun updateBirthCountryForWorkingName(
22+
@PathVariable offenderNo: String,
23+
@RequestBody updateBirthCountry: UpdateBirthCountry,
24+
): ResponseEntity<Void>
25+
1926
@PutExchange("/{offenderNo}/nationality")
2027
fun updateNationalityForWorkingName(
2128
@PathVariable offenderNo: String,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto
2+
3+
import io.swagger.v3.oas.annotations.media.Schema
4+
5+
@Schema(description = "Update to prisoner birth country")
6+
data class UpdateBirthCountry(
7+
@Schema(description = "Country code", example = "GBR", required = true, nullable = true)
8+
val countryCode: String?,
9+
)

src/main/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/corepersonrecord/service/CorePersonRecordService.kt

+3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.servi
22

33
import org.springframework.stereotype.Service
44
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.PrisonApiClient
5+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthCountry
56
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthPlace
67
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateNationality
78
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.BirthplaceUpdateDto
89
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CorePersonRecordV1UpdateRequestDto
10+
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CountryOfBirthUpdateDto
911
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.NationalityUpdateDto
1012
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.exception.UnknownCorePersonFieldException
1113

@@ -17,6 +19,7 @@ class CorePersonRecordService(
1719
fun updateCorePersonRecordField(prisonerNumber: String, updateRequestDto: CorePersonRecordV1UpdateRequestDto) {
1820
when (updateRequestDto) {
1921
is BirthplaceUpdateDto -> prisonApiClient.updateBirthPlaceForWorkingName(prisonerNumber, UpdateBirthPlace(updateRequestDto.value))
22+
is CountryOfBirthUpdateDto -> prisonApiClient.updateBirthCountryForWorkingName(prisonerNumber, UpdateBirthCountry(updateRequestDto.value))
2023
is NationalityUpdateDto -> prisonApiClient.updateNationalityForWorkingName(prisonerNumber, UpdateNationality(updateRequestDto.value))
2124
else -> throw UnknownCorePersonFieldException("Field '${updateRequestDto.fieldName}' cannot be updated.")
2225
}

src/test/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/corepersonrecord/resource/CorePersonRecordV1ResourceIntTest.kt

+36-19
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,39 @@ class CorePersonRecordV1ResourceIntTest : IntegrationTestBase() {
5151

5252
@Test
5353
fun `can patch core person record birthplace by prisoner number`() {
54-
webTestClient.patch().uri("/v1/core-person-record?prisonerNumber=$PRISONER_NUMBER")
55-
.contentType(MediaType.APPLICATION_JSON)
56-
.headers(setAuthorisation(roles = listOf(CorePersonRecordRoleConstants.CORE_PERSON_RECORD_READ_WRITE_ROLE)))
57-
.bodyValue(BIRTHPLACE_PATCH_REQUEST_BODY)
58-
.exchange()
59-
.expectStatus().isNoContent
54+
expectSuccessfulRequestWith(BIRTHPLACE_PATCH_REQUEST_BODY)
6055
}
6156

6257
@Test
6358
fun `patch core person record birthplace accepts null value`() {
64-
webTestClient.patch().uri("/v1/core-person-record?prisonerNumber=$PRISONER_NUMBER")
65-
.contentType(MediaType.APPLICATION_JSON)
66-
.headers(setAuthorisation(roles = listOf(CorePersonRecordRoleConstants.CORE_PERSON_RECORD_READ_WRITE_ROLE)))
67-
.bodyValue(NULL_BIRTHPLACE_PATCH_REQUEST_BODY)
68-
.exchange()
69-
.expectStatus().isNoContent
59+
expectSuccessfulRequestWith(NULL_BIRTHPLACE_PATCH_REQUEST_BODY)
60+
}
61+
62+
@Test
63+
fun `can patch core person record country of birth by prisoner number`() {
64+
expectSuccessfulRequestWith(COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY)
65+
}
66+
67+
@Test
68+
fun `patch core person record country of birth accepts null value`() {
69+
expectSuccessfulRequestWith(NULL_COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY)
7070
}
7171

7272
@Test
7373
fun `can patch core person record nationality by prisoner number`() {
74-
webTestClient.patch().uri("/v1/core-person-record?prisonerNumber=$PRISONER_NUMBER")
75-
.contentType(MediaType.APPLICATION_JSON)
76-
.headers(setAuthorisation(roles = listOf(CorePersonRecordRoleConstants.CORE_PERSON_RECORD_READ_WRITE_ROLE)))
77-
.bodyValue(NATIONALITY_PATCH_REQUEST_BODY)
78-
.exchange()
79-
.expectStatus().isNoContent
74+
expectSuccessfulRequestWith(NATIONALITY_PATCH_REQUEST_BODY)
8075
}
8176

8277
@Test
8378
fun `patch core person record nationality accepts null value`() {
79+
expectSuccessfulRequestWith(NULL_NATIONALITY_PATCH_REQUEST_BODY)
80+
}
81+
82+
private fun expectSuccessfulRequestWith(body: Any) {
8483
webTestClient.patch().uri("/v1/core-person-record?prisonerNumber=$PRISONER_NUMBER")
8584
.contentType(MediaType.APPLICATION_JSON)
8685
.headers(setAuthorisation(roles = listOf(CorePersonRecordRoleConstants.CORE_PERSON_RECORD_READ_WRITE_ROLE)))
87-
.bodyValue(NULL_NATIONALITY_PATCH_REQUEST_BODY)
86+
.bodyValue(body)
8887
.exchange()
8988
.expectStatus().isNoContent
9089
}
@@ -211,6 +210,24 @@ class CorePersonRecordV1ResourceIntTest : IntegrationTestBase() {
211210
}
212211
""".trimIndent()
213212

213+
val COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY =
214+
// language=json
215+
"""
216+
{
217+
"fieldName": "COUNTRY_OF_BIRTH",
218+
"value": "London"
219+
}
220+
""".trimIndent()
221+
222+
val NULL_COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY =
223+
// language=json
224+
"""
225+
{
226+
"fieldName": "BIRTHPLACE",
227+
"value": null
228+
}
229+
""".trimIndent()
230+
214231
val NATIONALITY_PATCH_REQUEST_BODY =
215232
// language=json
216233
"""

src/test/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/corepersonrecord/service/CorePersonRecordServiceTest.kt

+11
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import org.mockito.kotlin.reset
1313
import org.mockito.kotlin.whenever
1414
import org.springframework.http.ResponseEntity
1515
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.PrisonApiClient
16+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthCountry
1617
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthPlace
1718
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateNationality
1819
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.BirthplaceUpdateDto
20+
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CountryOfBirthUpdateDto
1921
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.DateOfBirthUpdateDto
2022
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.NationalityUpdateDto
2123
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.exception.UnknownCorePersonFieldException
@@ -39,6 +41,8 @@ class CorePersonRecordServiceTest {
3941
fun beforeEach() {
4042
whenever(prisonApiClient.updateBirthPlaceForWorkingName(PRISONER_NUMBER, TEST_BIRTHPLACE_BODY))
4143
.thenReturn(ResponseEntity.noContent().build())
44+
whenever(prisonApiClient.updateBirthCountryForWorkingName(PRISONER_NUMBER, TEST_COUNTRY_OF_BIRTH_BODY))
45+
.thenReturn(ResponseEntity.noContent().build())
4246
whenever(prisonApiClient.updateNationalityForWorkingName(PRISONER_NUMBER, TEST_NATIONALITY_BODY))
4347
.thenReturn(ResponseEntity.noContent().build())
4448
}
@@ -50,6 +54,11 @@ class CorePersonRecordServiceTest {
5054
underTest.updateCorePersonRecordField(PRISONER_NUMBER, BirthplaceUpdateDto(TEST_BIRTHPLACE_VALUE))
5155
}
5256

57+
@Test
58+
fun `can update the country of birth field`() {
59+
underTest.updateCorePersonRecordField(PRISONER_NUMBER, CountryOfBirthUpdateDto(TEST_COUNTRY_OF_BIRTH_VALUE))
60+
}
61+
5362
@Test
5463
fun `can update the nationality field`() {
5564
underTest.updateCorePersonRecordField(PRISONER_NUMBER, NationalityUpdateDto(TEST_NATIONALITY_VALUE))
@@ -66,8 +75,10 @@ class CorePersonRecordServiceTest {
6675
private companion object {
6776
const val PRISONER_NUMBER = "A1234AA"
6877
const val TEST_BIRTHPLACE_VALUE = "London"
78+
const val TEST_COUNTRY_OF_BIRTH_VALUE = "ENG"
6979
const val TEST_NATIONALITY_VALUE = "BRIT"
7080
val TEST_BIRTHPLACE_BODY = UpdateBirthPlace("London")
81+
val TEST_COUNTRY_OF_BIRTH_BODY = UpdateBirthCountry("ENG")
7182
val TEST_NATIONALITY_BODY = UpdateNationality("BRIT")
7283
}
7384
}

src/test/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/integration/wiremock/PrisonApiMockServer.kt

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ class PrisonApiMockServer : WireMockServer(8082) {
4545
)
4646
}
4747

48+
fun stubUpdateBirthCountryForWorkingName() {
49+
val endpoint = "birth-country"
50+
stubOffenderEndpoint(endpoint, HttpStatus.NO_CONTENT, PRISONER_NUMBER)
51+
stubOffenderEndpoint(endpoint, HttpStatus.INTERNAL_SERVER_ERROR, PRISONER_NUMBER_THROW_EXCEPTION)
52+
stubOffenderEndpoint(
53+
endpoint,
54+
HttpStatus.NOT_FOUND,
55+
PRISONER_NUMBER_NOT_FOUND,
56+
PRISON_API_NOT_FOUND_RESPONSE.trimIndent(),
57+
)
58+
}
59+
4860
fun stubUpdateNationalityForWorkingName() {
4961
val endpoint = "nationality"
5062
stubOffenderEndpoint(endpoint, HttpStatus.NO_CONTENT, PRISONER_NUMBER)
@@ -78,6 +90,7 @@ class PrisonApiExtension : BeforeAllCallback, AfterAllCallback, BeforeEachCallba
7890
override fun beforeEach(context: ExtensionContext) {
7991
prisonApi.resetAll()
8092
prisonApi.stubUpdateBirthPlaceForWorkingName()
93+
prisonApi.stubUpdateBirthCountryForWorkingName()
8194
prisonApi.stubUpdateNationalityForWorkingName()
8295
}
8396

0 commit comments

Comments
 (0)