Skip to content

Commit a6ed9d6

Browse files
committed
CDPS-1090: Edit country of birth
1 parent a30f7c1 commit a6ed9d6

File tree

6 files changed

+86
-22
lines changed

6 files changed

+86
-22
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.request.UpdateBirthPlace
910
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.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

+7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.servi
33
import org.springframework.http.ResponseEntity
44
import org.springframework.stereotype.Service
55
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.PrisonApiClient
6+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthCountry
67
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.ReferenceDataClient
78
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateBirthPlace
89
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateNationality
910
import uk.gov.justice.digital.hmpps.personintegrationapi.common.dto.ReferenceDataCodeDto
1011
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.BirthplaceUpdateDto
1112
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CorePersonRecordV1UpdateRequestDto
13+
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CountryOfBirthUpdateDto
1214
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.NationalityUpdateDto
1315
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.exception.UnknownCorePersonFieldException
1416

@@ -25,6 +27,11 @@ class CorePersonRecordService(
2527
UpdateBirthPlace(updateRequestDto.value),
2628
)
2729

30+
is CountryOfBirthUpdateDto -> prisonApiClient.updateBirthCountryForWorkingName(
31+
prisonerNumber,
32+
UpdateBirthCountry(updateRequestDto.value),
33+
)
34+
2835
is NationalityUpdateDto -> prisonApiClient.updateNationalityForWorkingName(
2936
prisonerNumber,
3037
UpdateNationality(updateRequestDto.value),

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
}
@@ -217,6 +216,24 @@ class CorePersonRecordV1ResourceIntTest : IntegrationTestBase() {
217216
}
218217
""".trimIndent()
219218

219+
val COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY =
220+
// language=json
221+
"""
222+
{
223+
"fieldName": "COUNTRY_OF_BIRTH",
224+
"value": "London"
225+
}
226+
""".trimIndent()
227+
228+
val NULL_COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY =
229+
// language=json
230+
"""
231+
{
232+
"fieldName": "BIRTHPLACE",
233+
"value": null
234+
}
235+
""".trimIndent()
236+
220237
val NATIONALITY_PATCH_REQUEST_BODY =
221238
// language=json
222239
"""

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ import org.mockito.kotlin.whenever
1717
import org.springframework.http.HttpStatus
1818
import org.springframework.http.ResponseEntity
1919
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.PrisonApiClient
20+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthCountry
2021
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.ReferenceDataClient
2122
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateBirthPlace
2223
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateNationality
2324
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.ReferenceDataCode
2425
import uk.gov.justice.digital.hmpps.personintegrationapi.common.dto.ReferenceDataCodeDto
2526
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.BirthplaceUpdateDto
27+
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CountryOfBirthUpdateDto
2628
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.DateOfBirthUpdateDto
2729
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.NationalityUpdateDto
2830
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.exception.UnknownCorePersonFieldException
@@ -51,15 +53,22 @@ class CorePersonRecordServiceTest {
5153
fun beforeEach() {
5254
whenever(prisonApiClient.updateBirthPlaceForWorkingName(PRISONER_NUMBER, TEST_BIRTHPLACE_BODY))
5355
.thenReturn(ResponseEntity.noContent().build())
54-
whenever(prisonApiClient.updateNationalityForWorkingName(PRISONER_NUMBER, TEST_NATIONALITY_BODY))
55-
.thenReturn(ResponseEntity.noContent().build())
56-
}
56+
whenever(prisonApiClient.updateBirthCountryForWorkingName(PRISONER_NUMBER, TEST_COUNTRY_OF_BIRTH_BODY))
57+
.thenReturn(ResponseEntity.noContent().build())
58+
whenever(prisonApiClient.updateNationalityForWorkingName(PRISONER_NUMBER, TEST_NATIONALITY_BODY))
59+
.thenReturn(ResponseEntity.noContent().build())
60+
}
5761

5862
@Test
5963
fun `can update the birthplace field`() {
6064
underTest.updateCorePersonRecordField(PRISONER_NUMBER, BirthplaceUpdateDto(TEST_BIRTHPLACE_VALUE))
6165
}
6266

67+
@Test
68+
fun `can update the country of birth field`() {
69+
underTest.updateCorePersonRecordField(PRISONER_NUMBER, CountryOfBirthUpdateDto(TEST_COUNTRY_OF_BIRTH_VALUE))
70+
}
71+
6372
@Test
6473
fun `can update the nationality field`() {
6574
underTest.updateCorePersonRecordField(PRISONER_NUMBER, NationalityUpdateDto(TEST_NATIONALITY_VALUE))
@@ -113,8 +122,10 @@ class CorePersonRecordServiceTest {
113122
private companion object {
114123
const val PRISONER_NUMBER = "A1234AA"
115124
const val TEST_BIRTHPLACE_VALUE = "London"
125+
const val TEST_COUNTRY_OF_BIRTH_VALUE = "ENG"
116126
const val TEST_NATIONALITY_VALUE = "BRIT"
117127
val TEST_BIRTHPLACE_BODY = UpdateBirthPlace("London")
128+
val TEST_COUNTRY_OF_BIRTH_BODY = UpdateBirthCountry("ENG")
118129
val TEST_NATIONALITY_BODY = UpdateNationality("BRIT")
119130
}
120131
}

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

+13
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ class PrisonApiMockServer : WireMockServer(8082) {
6565
)
6666
}
6767

68+
fun stubUpdateBirthCountryForWorkingName() {
69+
val endpoint = "birth-country"
70+
stubOffenderEndpoint(endpoint, HttpStatus.NO_CONTENT, PRISONER_NUMBER)
71+
stubOffenderEndpoint(endpoint, HttpStatus.INTERNAL_SERVER_ERROR, PRISONER_NUMBER_THROW_EXCEPTION)
72+
stubOffenderEndpoint(
73+
endpoint,
74+
HttpStatus.NOT_FOUND,
75+
PRISONER_NUMBER_NOT_FOUND,
76+
PRISON_API_NOT_FOUND_RESPONSE.trimIndent(),
77+
)
78+
}
79+
6880
fun stubUpdateNationalityForWorkingName() {
6981
val endpoint = "nationality"
7082
stubOffenderEndpoint(endpoint, HttpStatus.NO_CONTENT, PRISONER_NUMBER)
@@ -108,6 +120,7 @@ class PrisonApiExtension : BeforeAllCallback, AfterAllCallback, BeforeEachCallba
108120
override fun beforeEach(context: ExtensionContext) {
109121
prisonApi.resetAll()
110122
prisonApi.stubUpdateBirthPlaceForWorkingName()
123+
prisonApi.stubUpdateBirthCountryForWorkingName()
111124
prisonApi.stubUpdateNationalityForWorkingName()
112125
prisonApi.stubReferenceDataCodes()
113126
}

0 commit comments

Comments
 (0)