Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDPS-1090: Edit country of birth #16

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.service.annotation.HttpExchange
import org.springframework.web.service.annotation.PutExchange
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthCountry
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateBirthPlace
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateNationality

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

@PutExchange("/{offenderNo}/birth-country")
fun updateBirthCountryForWorkingName(
@PathVariable offenderNo: String,
@RequestBody updateBirthCountry: UpdateBirthCountry,
): ResponseEntity<Void>

@PutExchange("/{offenderNo}/nationality")
fun updateNationalityForWorkingName(
@PathVariable offenderNo: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto

import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "Update to prisoner birth country")
data class UpdateBirthCountry(
@Schema(description = "Country code", example = "GBR", required = true, nullable = true)
val countryCode: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.security.oauth2.client.endpoint.OAuth2ClientCredentia
import org.springframework.util.MultiValueMap
import java.util.Objects

@SuppressWarnings("unchecked")
@Suppress("UNCHECKED_CAST")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't know why this suddenly started complaining 🤷‍♂️

class UserEnhancedOAuth2ClientCredentialGrantRequestConverter :
OAuth2ClientCredentialsGrantRequestEntityConverter() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.PrisonApiClient
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.ReferenceDataClient
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthCountry
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateBirthPlace
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateNationality
import uk.gov.justice.digital.hmpps.personintegrationapi.common.dto.ReferenceDataCodeDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.BirthplaceUpdateDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CorePersonRecordV1UpdateRequestDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CountryOfBirthUpdateDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.NationalityUpdateDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.exception.UnknownCorePersonFieldException

Expand All @@ -25,6 +27,11 @@ class CorePersonRecordService(
UpdateBirthPlace(updateRequestDto.value),
)

is CountryOfBirthUpdateDto -> prisonApiClient.updateBirthCountryForWorkingName(
prisonerNumber,
UpdateBirthCountry(updateRequestDto.value),
)

is NationalityUpdateDto -> prisonApiClient.updateNationalityForWorkingName(
prisonerNumber,
UpdateNationality(updateRequestDto.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,39 @@ class CorePersonRecordV1ResourceIntTest : IntegrationTestBase() {

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

@Test
fun `patch core person record birthplace accepts null value`() {
webTestClient.patch().uri("/v1/core-person-record?prisonerNumber=$PRISONER_NUMBER")
.contentType(MediaType.APPLICATION_JSON)
.headers(setAuthorisation(roles = listOf(CorePersonRecordRoleConstants.CORE_PERSON_RECORD_READ_WRITE_ROLE)))
.bodyValue(NULL_BIRTHPLACE_PATCH_REQUEST_BODY)
.exchange()
.expectStatus().isNoContent
expectSuccessfulRequestWith(NULL_BIRTHPLACE_PATCH_REQUEST_BODY)
}

@Test
fun `can patch core person record country of birth by prisoner number`() {
expectSuccessfulRequestWith(COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY)
}

@Test
fun `patch core person record country of birth accepts null value`() {
expectSuccessfulRequestWith(NULL_COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY)
}

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

@Test
fun `patch core person record nationality accepts null value`() {
expectSuccessfulRequestWith(NULL_NATIONALITY_PATCH_REQUEST_BODY)
}

private fun expectSuccessfulRequestWith(body: Any) {
webTestClient.patch().uri("/v1/core-person-record?prisonerNumber=$PRISONER_NUMBER")
.contentType(MediaType.APPLICATION_JSON)
.headers(setAuthorisation(roles = listOf(CorePersonRecordRoleConstants.CORE_PERSON_RECORD_READ_WRITE_ROLE)))
.bodyValue(NULL_NATIONALITY_PATCH_REQUEST_BODY)
.bodyValue(body)
.exchange()
.expectStatus().isNoContent
}
Expand Down Expand Up @@ -217,6 +216,24 @@ class CorePersonRecordV1ResourceIntTest : IntegrationTestBase() {
}
""".trimIndent()

val COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY =
// language=json
"""
{
"fieldName": "COUNTRY_OF_BIRTH",
"value": "London"
}
""".trimIndent()

val NULL_COUNTRY_OF_BIRTH_PATCH_REQUEST_BODY =
// language=json
"""
{
"fieldName": "BIRTHPLACE",
"value": null
}
""".trimIndent()

val NATIONALITY_PATCH_REQUEST_BODY =
// language=json
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.PrisonApiClient
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.ReferenceDataClient
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthCountry
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateBirthPlace
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateNationality
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.ReferenceDataCode
import uk.gov.justice.digital.hmpps.personintegrationapi.common.dto.ReferenceDataCodeDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.BirthplaceUpdateDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CountryOfBirthUpdateDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.DateOfBirthUpdateDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.NationalityUpdateDto
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.exception.UnknownCorePersonFieldException
Expand Down Expand Up @@ -51,6 +53,8 @@ class CorePersonRecordServiceTest {
fun beforeEach() {
whenever(prisonApiClient.updateBirthPlaceForWorkingName(PRISONER_NUMBER, TEST_BIRTHPLACE_BODY))
.thenReturn(ResponseEntity.noContent().build())
whenever(prisonApiClient.updateBirthCountryForWorkingName(PRISONER_NUMBER, TEST_COUNTRY_OF_BIRTH_BODY))
.thenReturn(ResponseEntity.noContent().build())
whenever(prisonApiClient.updateNationalityForWorkingName(PRISONER_NUMBER, TEST_NATIONALITY_BODY))
.thenReturn(ResponseEntity.noContent().build())
}
Expand All @@ -60,6 +64,11 @@ class CorePersonRecordServiceTest {
underTest.updateCorePersonRecordField(PRISONER_NUMBER, BirthplaceUpdateDto(TEST_BIRTHPLACE_VALUE))
}

@Test
fun `can update the country of birth field`() {
underTest.updateCorePersonRecordField(PRISONER_NUMBER, CountryOfBirthUpdateDto(TEST_COUNTRY_OF_BIRTH_VALUE))
}

@Test
fun `can update the nationality field`() {
underTest.updateCorePersonRecordField(PRISONER_NUMBER, NationalityUpdateDto(TEST_NATIONALITY_VALUE))
Expand Down Expand Up @@ -113,8 +122,10 @@ class CorePersonRecordServiceTest {
private companion object {
const val PRISONER_NUMBER = "A1234AA"
const val TEST_BIRTHPLACE_VALUE = "London"
const val TEST_COUNTRY_OF_BIRTH_VALUE = "ENG"
const val TEST_NATIONALITY_VALUE = "BRIT"
val TEST_BIRTHPLACE_BODY = UpdateBirthPlace("London")
val TEST_COUNTRY_OF_BIRTH_BODY = UpdateBirthCountry("ENG")
val TEST_NATIONALITY_BODY = UpdateNationality("BRIT")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ class PrisonApiMockServer : WireMockServer(8082) {
)
}

fun stubUpdateBirthCountryForWorkingName() {
val endpoint = "birth-country"
stubOffenderEndpoint(endpoint, HttpStatus.NO_CONTENT, PRISONER_NUMBER)
stubOffenderEndpoint(endpoint, HttpStatus.INTERNAL_SERVER_ERROR, PRISONER_NUMBER_THROW_EXCEPTION)
stubOffenderEndpoint(
endpoint,
HttpStatus.NOT_FOUND,
PRISONER_NUMBER_NOT_FOUND,
PRISON_API_NOT_FOUND_RESPONSE.trimIndent(),
)
}

fun stubUpdateNationalityForWorkingName() {
val endpoint = "nationality"
stubOffenderEndpoint(endpoint, HttpStatus.NO_CONTENT, PRISONER_NUMBER)
Expand Down Expand Up @@ -108,6 +120,7 @@ class PrisonApiExtension : BeforeAllCallback, AfterAllCallback, BeforeEachCallba
override fun beforeEach(context: ExtensionContext) {
prisonApi.resetAll()
prisonApi.stubUpdateBirthPlaceForWorkingName()
prisonApi.stubUpdateBirthCountryForWorkingName()
prisonApi.stubUpdateNationalityForWorkingName()
prisonApi.stubReferenceDataCodes()
}
Expand Down
Loading