diff --git a/projects/subject-access-requests-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/GetPersonByCRNIntegrationTest.kt b/projects/subject-access-requests-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/GetPersonByCRNIntegrationTest.kt index 71b4486a35..464c4fa154 100644 --- a/projects/subject-access-requests-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/GetPersonByCRNIntegrationTest.kt +++ b/projects/subject-access-requests-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/GetPersonByCRNIntegrationTest.kt @@ -12,6 +12,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status +import uk.gov.justice.digital.hmpps.api.model.Name import uk.gov.justice.digital.hmpps.api.model.Person import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.PERSON1 import uk.gov.justice.digital.hmpps.telemetry.TelemetryService @@ -46,7 +47,7 @@ internal class GetPersonByCRNIntegrationTest { @Test fun `API call return person data`() { - val expectedResponse = Person("Jon Harry Fred Smith") + val expectedResponse = Person(Name("Jon", "Harry Fred", "Smith")) val response = mockMvc .perform(get("/probation-case/$crn").withToken()) diff --git a/projects/subject-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Person.kt b/projects/subject-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Person.kt index 66f47f81c9..3fc5e07c37 100644 --- a/projects/subject-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Person.kt +++ b/projects/subject-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Person.kt @@ -1,5 +1,11 @@ package uk.gov.justice.digital.hmpps.api.model data class Person( - val fullName: String + val name: Name ) + +data class Name( + val forename: String, + val middleName: String? = null, + val surname: String +) \ No newline at end of file diff --git a/projects/subject-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsService.kt b/projects/subject-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsService.kt index e25d179944..5771f2094e 100644 --- a/projects/subject-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsService.kt +++ b/projects/subject-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsService.kt @@ -1,6 +1,7 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Service +import uk.gov.justice.digital.hmpps.api.model.Name import uk.gov.justice.digital.hmpps.integration.delius.person.entity.PersonRepository import uk.gov.justice.digital.hmpps.integration.delius.person.entity.getPerson import uk.gov.justice.digital.hmpps.integration.delius.person.entity.Person as PersonEntity @@ -14,8 +15,13 @@ class SubjectAccessRequestsService(private val personRepository: PersonRepositor } } -fun PersonEntity.toPerson(): Person = Person(getName()) +fun PersonEntity.toPerson(): Person { + val middleName = listOfNotNull(secondName, thirdName).let { + when (it.size) { + 0 -> null + else -> it.joinToString(" ") + } + } -fun PersonEntity.getName(): String { - return listOfNotNull(forename, secondName, thirdName, surname).joinToString(" ") -} \ No newline at end of file + return Person(Name(forename, middleName, surname)) +} diff --git a/projects/subject-access-requests-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsServiceTest.kt b/projects/subject-access-requests-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsServiceTest.kt index 62fbb0ee9c..622b9c63d8 100644 --- a/projects/subject-access-requests-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsServiceTest.kt +++ b/projects/subject-access-requests-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsServiceTest.kt @@ -8,8 +8,10 @@ import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension import org.mockito.kotlin.whenever +import uk.gov.justice.digital.hmpps.api.model.Name +import uk.gov.justice.digital.hmpps.api.model.Person import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator -import uk.gov.justice.digital.hmpps.integration.delius.person.entity.Person +import uk.gov.justice.digital.hmpps.integration.delius.person.entity.Person as PersonEntity import uk.gov.justice.digital.hmpps.integration.delius.person.entity.PersonRepository @ExtendWith(MockitoExtension::class) @@ -36,10 +38,12 @@ class SubjectAccessRequestsServiceTest { val response = subjectAccessRequestsService.getPersonDetailsByCrn(crn) - assertEquals(fullName, response.fullName) + val expectedResponse = Person(getName(fullName)) + + assertEquals(expectedResponse, response) } - private fun getPerson(person: Int): Person { + private fun getPerson(person: Int): PersonEntity { return when (person) { 1 -> PersonGenerator.PERSON1 2 -> PersonGenerator.PERSON2 @@ -47,4 +51,13 @@ class SubjectAccessRequestsServiceTest { else -> PersonGenerator.PERSON4 } } + + private fun getName(fullName: String): Name { + val name = fullName.split(" ") + return when (name.size) { + 4 -> Name(name[0], name[1] + " " + name[2], name[3]) + 3 -> Name(name[0], name[1], name[2]) + else -> Name(name[0], surname = name[1]) + } + } } \ No newline at end of file