Skip to content

Commit

Permalink
PI-2395 split name into separate fields (#4077)
Browse files Browse the repository at this point in the history
* PI-2395 split name into separate fields

* Formatting changes

* Empty-Commit

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
achimber-moj and github-actions[bot] authored Jul 29, 2024
1 parent edebd3e commit 9412145
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(" ")
}
return Person(Name(forename, middleName, surname))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,15 +38,26 @@ 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
3 -> PersonGenerator.PERSON3
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])
}
}
}

0 comments on commit 9412145

Please sign in to comment.