From 265f39432a1ed5ba50741521eb53daabf93fcab6 Mon Sep 17 00:00:00 2001 From: BushraAbdullahi <103956365+BushraAbdullahi@users.noreply.github.com> Date: Tue, 11 Mar 2025 10:59:53 +0000 Subject: [PATCH] HMAI-286 Make LinkedPrisoner and PrisonerContactRestrictions models consistent with new naming (#727) * change model names to adhere to naming convention * update class names * update class name * fix tests * refactor models --- .../v1/person/VisitRestrictionsController.kt | 2 +- .../gateways/PersonalRelationshipsGateway.kt | 16 ++-- .../PrisonerContactRestrictions.kt | 2 +- ...{LinkedPrisoner.kt => PRLinkedPrisoner.kt} | 6 +- .../PRPrisonerContactRestrictions.kt | 93 +++++++++++++++++++ .../PrisonerContactRestrictionsResponse.kt | 6 -- .../services/GetVisitorRestrictionsService.kt | 9 +- .../person/VisitRestrictionsControllerTest.kt | 6 +- .../GetVisitorRestrictionsServiceTest.kt | 65 +++++++------ 9 files changed, 151 insertions(+), 54 deletions(-) rename src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/{personalRelationships => hmpps}/PrisonerContactRestrictions.kt (98%) rename src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/{LinkedPrisoner.kt => PRLinkedPrisoner.kt} (88%) create mode 100644 src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PRPrisonerContactRestrictions.kt delete mode 100644 src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PrisonerContactRestrictionsResponse.kt diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/VisitRestrictionsController.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/VisitRestrictionsController.kt index 5c4e90057..58d0f9b0e 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/VisitRestrictionsController.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/VisitRestrictionsController.kt @@ -16,8 +16,8 @@ import org.springframework.web.bind.annotation.RestController import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonVisitRestriction +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestrictions import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictions import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig.ConsumerFilters import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetVisitRestrictionsForPersonService import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetVisitorRestrictionsService diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/PersonalRelationshipsGateway.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/PersonalRelationshipsGateway.kt index 845c4c1ce..b4c5f1912 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/PersonalRelationshipsGateway.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/PersonalRelationshipsGateway.kt @@ -10,10 +10,10 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrap import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper.WebClientWrapperResponse import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.LinkedPrisoner import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRDetailedContact +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRLinkedPrisoner import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRPaginatedPrisonerContacts -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictionsResponse +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRPrisonerContactRestrictions @Component class PersonalRelationshipsGateway( @@ -25,9 +25,9 @@ class PersonalRelationshipsGateway( @Autowired lateinit var hmppsAuthGateway: HmppsAuthGateway - fun getLinkedPrisoner(contactId: Long): Response> { + fun getLinkedPrisoner(contactId: Long): Response> { val result = - webClient.request>( + webClient.request>( HttpMethod.GET, "/contact/$contactId/linked-prisoners", authenticationHeader(), @@ -48,9 +48,9 @@ class PersonalRelationshipsGateway( } } - fun getPrisonerContactRestrictions(prisonerContactId: Long): Response { + fun getPrisonerContactRestrictions(prisonerContactId: Long): Response { val result = - webClient.request( + webClient.request( HttpMethod.GET, "/prisoner-contact/$prisonerContactId/restriction", authenticationHeader(), @@ -129,8 +129,8 @@ class PersonalRelationshipsGateway( } } - fun mapToLinkedPrisoner(result: WebClientWrapper.WebClientWrapperResponse.Success>): List { - val mappedResult: List = mapper.convertValue(result.data, object : TypeReference>() {}) + fun mapToLinkedPrisoner(result: WebClientWrapper.WebClientWrapperResponse.Success>): List { + val mappedResult: List = mapper.convertValue(result.data, object : TypeReference>() {}) return mappedResult } diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PrisonerContactRestrictions.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/hmpps/PrisonerContactRestrictions.kt similarity index 98% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PrisonerContactRestrictions.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/hmpps/PrisonerContactRestrictions.kt index 05d6d600f..285ec3dc7 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PrisonerContactRestrictions.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/hmpps/PrisonerContactRestrictions.kt @@ -1,4 +1,4 @@ -package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships +package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps import com.fasterxml.jackson.annotation.JsonProperty diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/LinkedPrisoner.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PRLinkedPrisoner.kt similarity index 88% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/LinkedPrisoner.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PRLinkedPrisoner.kt index ba7528d31..82809f058 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/LinkedPrisoner.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PRLinkedPrisoner.kt @@ -3,7 +3,7 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelation import com.fasterxml.jackson.annotation.JsonProperty import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.interfaces.IRelationship -data class LinkedPrisoner( +data class PRLinkedPrisoner( @JsonProperty("prisonerNumber") val prisonerNumber: String, @JsonProperty("lastName") @@ -13,10 +13,10 @@ data class LinkedPrisoner( @JsonProperty("middleNames") val middleNames: String?, @JsonProperty("relationships") - val relationships: List?, + val relationships: List?, ) -data class LinkedPrisonerRelationship( +data class PRLinkedPrisonerRelationship( @JsonProperty("relationshipTypeCode") override val relationshipTypeCode: String?, @JsonProperty("relationshipTypeDescription") diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PRPrisonerContactRestrictions.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PRPrisonerContactRestrictions.kt new file mode 100644 index 000000000..6e3c33878 --- /dev/null +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PRPrisonerContactRestrictions.kt @@ -0,0 +1,93 @@ +package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships + +import com.fasterxml.jackson.annotation.JsonProperty +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ContactGlobalRestriction +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestriction + +data class PRPrisonerContactRestrictions( + var prisonerContactRestrictions: MutableList? = mutableListOf(), + var contactGlobalRestrictions: List? = listOf(), +) + +data class PRPrisonerContactRestriction( + val prisonerContactRestrictionId: Long, + val prisonerContactId: Long, + val contactId: Long, + val prisonerNumber: String, + val restrictionType: String, + val restrictionTypeDescription: String, + val startDate: String, + val expiryDate: String, + val comments: String, + val enteredByUsername: String, + val enteredByDisplayName: String, + val createdBy: String, + val createdTime: String, + val updatedBy: String, + val updatedTime: String, +) { + fun toPrisonerContactRestriction() = + PrisonerContactRestriction( + prisonerContactRestrictionId = this.prisonerContactRestrictionId, + prisonerContactId = this.prisonerContactId, + contactId = this.contactId, + prisonerNumber = this.prisonerNumber, + restrictionType = this.restrictionType, + restrictionTypeDescription = this.restrictionTypeDescription, + startDate = this.startDate, + expiryDate = this.expiryDate, + comments = this.comments, + enteredByUsername = this.enteredByUsername, + enteredByDisplayName = this.enteredByDisplayName, + createdBy = this.createdBy, + createdTime = this.createdTime, + updatedBy = this.updatedBy, + updatedTime = this.updatedTime, + ) +} + +data class PRContactGlobalRestriction( + @JsonProperty("contactRestrictionId") + val contactRestrictionId: Long, + @JsonProperty("contactId") + val contactId: Long, + @JsonProperty("restrictionType") + val restrictionType: String, + @JsonProperty("restrictionTypeDescription") + val restrictionTypeDescription: String, + @JsonProperty("startDate") + val startDate: String, + @JsonProperty("expiryDate") + val expiryDate: String, + @JsonProperty("comments") + val comments: String, + @JsonProperty("enteredByUsername") + val enteredByUsername: String, + @JsonProperty("enteredByDisplayName") + val enteredByDisplayName: String, + @JsonProperty("createdBy") + val createdBy: String, + @JsonProperty("createdTime") + val createdTime: String, + @JsonProperty("updatedBy") + val updatedBy: String, + @JsonProperty("updatedTime") + val updatedTime: String, +) { + fun toContactGlobalRestriction() = + ContactGlobalRestriction( + contactRestrictionId = this.contactRestrictionId, + contactId = this.contactId, + restrictionType = this.restrictionType, + restrictionTypeDescription = this.restrictionTypeDescription, + startDate = this.startDate, + expiryDate = this.expiryDate, + comments = this.comments, + enteredByUsername = this.enteredByUsername, + enteredByDisplayName = this.enteredByDisplayName, + createdBy = this.createdBy, + createdTime = this.createdTime, + updatedBy = this.updatedBy, + updatedTime = this.updatedTime, + ) +} diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PrisonerContactRestrictionsResponse.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PrisonerContactRestrictionsResponse.kt deleted file mode 100644 index b3599eed8..000000000 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/personalRelationships/PrisonerContactRestrictionsResponse.kt +++ /dev/null @@ -1,6 +0,0 @@ -package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships - -data class PrisonerContactRestrictionsResponse( - var prisonerContactRestrictions: MutableList? = mutableListOf(), - var contactGlobalRestrictions: List? = listOf(), -) diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetVisitorRestrictionsService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetVisitorRestrictionsService.kt index dd157ff83..f4610b56a 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetVisitorRestrictionsService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetVisitorRestrictionsService.kt @@ -4,10 +4,10 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service import uk.gov.justice.digital.hmpps.hmppsintegrationapi.common.ConsumerPrisonAccessService import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.PersonalRelationshipsGateway +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestrictions import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictions import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig.ConsumerFilters @Service @@ -52,9 +52,12 @@ class GetVisitorRestrictionsService( for (prisonerContactId in linkedPrisonerIds) { val gatewayResult = personalRelationshipsGateway.getPrisonerContactRestrictions(prisonerContactId!!) if (gatewayResult.errors.isEmpty() && gatewayResult.data != null) { - gatewayResult.data.prisonerContactRestrictions?.let { restrictionsResult.prisonerContactRestrictions?.addAll(it) } + gatewayResult.data.prisonerContactRestrictions?.let { it -> restrictionsResult.prisonerContactRestrictions?.addAll(it.map { it.toPrisonerContactRestriction() }) } if (prisonerContactId == linkedPrisonerIds.first()) { - restrictionsResult.contactGlobalRestrictions = gatewayResult.data.contactGlobalRestrictions?.first() + restrictionsResult.contactGlobalRestrictions = + gatewayResult.data.contactGlobalRestrictions + ?.first() + ?.toContactGlobalRestriction() } } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/VisitRestrictionsControllerTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/VisitRestrictionsControllerTest.kt index 5729bc58c..9af940c74 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/VisitRestrictionsControllerTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/VisitRestrictionsControllerTest.kt @@ -15,13 +15,13 @@ import org.springframework.test.web.servlet.MockMvc import uk.gov.justice.digital.hmpps.hmppsintegrationapi.common.ConsumerPrisonAccessService import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines import uk.gov.justice.digital.hmpps.hmppsintegrationapi.helpers.IntegrationAPIMockMvc +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ContactGlobalRestriction import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonVisitRestriction +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestriction +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestrictions import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.ContactGlobalRestriction -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestriction -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictions import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig.ConsumerFilters import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetVisitRestrictionsForPersonService import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetVisitorRestrictionsService diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetVisitorRestrictionsServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetVisitorRestrictionsServiceTest.kt index 2d54f0be0..a2f0fe97e 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetVisitorRestrictionsServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetVisitorRestrictionsServiceTest.kt @@ -11,15 +11,16 @@ import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.bean.override.mockito.MockitoBean import uk.gov.justice.digital.hmpps.hmppsintegrationapi.common.ConsumerPrisonAccessService import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.PersonalRelationshipsGateway +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestriction +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestrictions import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.ContactGlobalRestriction -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.LinkedPrisoner -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.LinkedPrisonerRelationship -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestriction -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictions -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictionsResponse +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRContactGlobalRestriction +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRLinkedPrisoner +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRLinkedPrisonerRelationship +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRPrisonerContactRestriction +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRPrisonerContactRestrictions import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffendersearch.POSPrisoner import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig.ConsumerFilters @@ -39,11 +40,11 @@ class GetVisitorRestrictionsServiceTest( val contactId = 123456L val filters = ConsumerFilters(null) val posPrisoner = POSPrisoner(firstName = "Test", lastName = "Person", prisonId = prisonId, prisonerNumber = hmppsId) - val listOfRelationships = listOf(LinkedPrisonerRelationship(prisonerContactId = contactId, relationshipTypeCode = "FAM", relationshipTypeDescription = "Family", relationshipToPrisonerCode = "SON", relationshipToPrisonerDescription = "Son")) - val listOfLinkedPrisoners = listOf(LinkedPrisoner(prisonerNumber = hmppsId, relationships = listOfRelationships, firstName = "Test", lastName = "Person", middleNames = null)) + val listOfRelationships = listOf(PRLinkedPrisonerRelationship(prisonerContactId = contactId, relationshipTypeCode = "FAM", relationshipTypeDescription = "Family", relationshipToPrisonerCode = "SON", relationshipToPrisonerDescription = "Son")) + val listOfLinkedPrisoners = listOf(PRLinkedPrisoner(prisonerNumber = hmppsId, relationships = listOfRelationships, firstName = "Test", lastName = "Person", middleNames = null)) val prisonerContactRestrictionsResponse = mutableListOf( - PrisonerContactRestriction( + PRPrisonerContactRestriction( prisonerContactRestrictionId = 1L, prisonerContactId = contactId, contactId = contactId, @@ -60,7 +61,7 @@ class GetVisitorRestrictionsServiceTest( updatedBy = "admin", updatedTime = "2024-01-02T12:00:00Z", ), - PrisonerContactRestriction( + PRPrisonerContactRestriction( prisonerContactRestrictionId = 2L, prisonerContactId = contactId, contactId = contactId, @@ -80,23 +81,26 @@ class GetVisitorRestrictionsServiceTest( ) val contactGlobalRestrictionsResponse = - ContactGlobalRestriction( - contactRestrictionId = 1L, - contactId = contactId, - restrictionType = "Restriction 1", - restrictionTypeDescription = "Description for Restriction 1", - startDate = "2024-01-01", - expiryDate = "2025-01-01", - comments = "Some comments", - enteredByUsername = "user123", - enteredByDisplayName = "User Name", - createdBy = "admin", - createdTime = "2024-01-01T12:00:00Z", - updatedBy = "admin", - updatedTime = "2024-01-02T12:00:00Z", + listOf( + PRContactGlobalRestriction( + contactRestrictionId = 1L, + contactId = contactId, + restrictionType = "Restriction 1", + restrictionTypeDescription = "Description for Restriction 1", + startDate = "2024-01-01", + expiryDate = "2025-01-01", + comments = "Some comments", + enteredByUsername = "user123", + enteredByDisplayName = "User Name", + createdBy = "admin", + createdTime = "2024-01-01T12:00:00Z", + updatedBy = "admin", + updatedTime = "2024-01-02T12:00:00Z", + ), ) - val prisonerContactRestrictions = PrisonerContactRestrictionsResponse(prisonerContactRestrictionsResponse, listOf(contactGlobalRestrictionsResponse)) + val prisonerContactRestrictions = PRPrisonerContactRestrictions(prisonerContactRestrictionsResponse, contactGlobalRestrictionsResponse) + beforeEach { Mockito.reset(personalRelationshipsGateway) Mockito.reset(getPersonService) @@ -156,10 +160,13 @@ class GetVisitorRestrictionsServiceTest( whenever(personalRelationshipsGateway.getLinkedPrisoner(contactId)).thenReturn(Response(data = listOfLinkedPrisoners, errors = emptyList())) whenever(personalRelationshipsGateway.getPrisonerContactRestrictions(contactId)).thenReturn(Response(data = prisonerContactRestrictions, errors = emptyList())) + val prisonerContactRestrictionsList = mutableListOf() + prisonerContactRestrictionsList.addAll(prisonerContactRestrictionsResponse.map { it.toPrisonerContactRestriction() }) + val expectedMappedResponse = PrisonerContactRestrictions( - prisonerContactRestrictions = prisonerContactRestrictionsResponse, - contactGlobalRestrictions = contactGlobalRestrictionsResponse, + prisonerContactRestrictions = prisonerContactRestrictionsList, + contactGlobalRestrictions = contactGlobalRestrictionsResponse.first().toContactGlobalRestriction(), ) val response = getVisitorRestrictionsService.execute(hmppsId, contactId, filters) @@ -169,8 +176,8 @@ class GetVisitorRestrictionsServiceTest( it("returns multiple relationships and queries getPrisonerContactRestrictions accordingly") { val scopedPrisonerContactId = 123457L - val listOfManyRelationships = listOf(LinkedPrisonerRelationship(prisonerContactId = contactId, relationshipTypeCode = "FAM", relationshipTypeDescription = "Family", relationshipToPrisonerCode = "SON", relationshipToPrisonerDescription = "Son"), LinkedPrisonerRelationship(prisonerContactId = scopedPrisonerContactId, relationshipTypeCode = "FAM", relationshipTypeDescription = "Family", relationshipToPrisonerCode = "BRO", relationshipToPrisonerDescription = "Brother")) - val listOfLinkedPrisonerWithManyRelationships = listOf(LinkedPrisoner(prisonerNumber = "A1234AA", relationships = listOfManyRelationships, firstName = "Test", lastName = "Person", middleNames = null)) + val listOfManyRelationships = listOf(PRLinkedPrisonerRelationship(prisonerContactId = contactId, relationshipTypeCode = "FAM", relationshipTypeDescription = "Family", relationshipToPrisonerCode = "SON", relationshipToPrisonerDescription = "Son"), PRLinkedPrisonerRelationship(prisonerContactId = scopedPrisonerContactId, relationshipTypeCode = "FAM", relationshipTypeDescription = "Family", relationshipToPrisonerCode = "BRO", relationshipToPrisonerDescription = "Brother")) + val listOfLinkedPrisonerWithManyRelationships = listOf(PRLinkedPrisoner(prisonerNumber = "A1234AA", relationships = listOfManyRelationships, firstName = "Test", lastName = "Person", middleNames = null)) whenever(personalRelationshipsGateway.getLinkedPrisoner(contactId)).thenReturn(Response(data = listOfLinkedPrisonerWithManyRelationships, errors = emptyList())) whenever(personalRelationshipsGateway.getPrisonerContactRestrictions(contactId)).thenReturn(Response(data = prisonerContactRestrictions, errors = emptyList()))