diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/PremisesEntity.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/PremisesEntity.kt index fa02bca2aa..d1f283a6d4 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/PremisesEntity.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/PremisesEntity.kt @@ -203,6 +203,7 @@ interface ApprovedPremisesRepository : JpaRepository { private var localAuthorityArea: Yielded? = null private var id: Yielded = { UUID.randomUUID() } private var name: Yielded = { randomStringMultiCaseWithNumbers(8) } + private var fullAddress: Yielded = { randomStringUpperCase(10) } private var apCode: Yielded = { randomStringUpperCase(10) } private var postcode: Yielded = { randomPostCode() } private var latitude: Yielded = { randomDouble(53.50, 54.99) } @@ -57,6 +58,10 @@ class ApprovedPremisesEntityFactory : Factory { this.name = { name } } + fun withFullAddress(fullAddress: String?) = apply { + this.fullAddress = { fullAddress } + } + fun withApCode(apCode: String) = apply { this.apCode = { apCode } } @@ -202,5 +207,6 @@ class ApprovedPremisesEntityFactory : Factory { gender = this.gender(), supportsSpaceBookings = this.supportsSpaceBookings(), managerDetails = this.managerDetails(), + fullAddress = this.fullAddress(), ) } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/Cas1SpaceSearchTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/Cas1SpaceSearchTest.kt index cdccc7c4a9..0e625aa69d 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/Cas1SpaceSearchTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/Cas1SpaceSearchTest.kt @@ -350,6 +350,7 @@ class Cas1SpaceSearchTest : InitialiseDatabasePerClassTestBase() { assertThat(premises.id).isEqualTo(expected.id) assertThat(premises.apType).isEqualTo(expectedApType) assertThat(premises.name).isEqualTo(expected.name) + assertThat(premises.fullAddress).isEqualTo(expected.fullAddress) assertThat(premises.addressLine1).isEqualTo(expected.addressLine1) assertThat(premises.addressLine2).isEqualTo(expected.addressLine2) assertThat(premises.town).isEqualTo(expected.town) diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/Cas1SeedPremisesFromCsvTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/Cas1SeedPremisesFromCsvTest.kt index d051a99d8e..edb0aa2b1e 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/Cas1SeedPremisesFromCsvTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/Cas1SeedPremisesFromCsvTest.kt @@ -202,7 +202,7 @@ class Cas1SeedPremisesFromCsvTest : SeedTestBase() { "acceptsNonSexualChildOffenders, acceptsHateCrimeOffenders, isCatered, hasWideStepFreeAccess, " + "hasWideAccessToCommunalAreas, hasStepFreeAccessToCommunalAreas, hasWheelChairAccessibleBathrooms, " + "hasLift, hasTactileFlooring, hasBrailleSignage, hasHearingLoop, status, latitude, longitude, gender, " + - "supportsSpaceBookings, managerDetails]" + "supportsSpaceBookings, managerDetails, fullAddress]" assertThat(logEntries) .withFailMessage("-> logEntries actually contains: $logEntries") @@ -235,6 +235,7 @@ class Cas1SeedPremisesFromCsvTest : SeedTestBase() { } val csvRow = ApprovedPremisesSeedCsvRowFactory() + .withFullAddress("The full address") .withProbationRegion(probationRegion.name) .withLocalAuthorityArea(localAuthorityArea.name) .withIsCatered("yes") @@ -260,6 +261,7 @@ class Cas1SeedPremisesFromCsvTest : SeedTestBase() { assertThat(persistedApprovedPremises).isNotNull assertThat(persistedApprovedPremises!!.apCode).isEqualTo(csvRow.apCode) assertThat(persistedApprovedPremises.name).isEqualTo(csvRow.name) + assertThat(persistedApprovedPremises.fullAddress).isEqualTo("The full address") assertThat(persistedApprovedPremises.addressLine1).isEqualTo(csvRow.addressLine1) assertThat(persistedApprovedPremises.addressLine2).isEqualTo(csvRow.addressLine2) assertThat(persistedApprovedPremises.town).isEqualTo(csvRow.town) @@ -372,6 +374,7 @@ class Cas1SeedPremisesFromCsvTest : SeedTestBase() { "gender", "supportsSpaceBookings", "managerDetails", + "fullAddress", ) .newRow() @@ -413,6 +416,7 @@ class Cas1SeedPremisesFromCsvTest : SeedTestBase() { .withQuotedField(it.gender) .withQuotedField(it.supportsSpaceBookings) .withQuotedField(it.managerDetails) + .withQuotedField(it.fullAddress ?: "") .newRow() } @@ -422,6 +426,7 @@ class Cas1SeedPremisesFromCsvTest : SeedTestBase() { class ApprovedPremisesSeedCsvRowFactory : Factory { private var name: Yielded = { randomStringMultiCaseWithNumbers(10) } + private var fullAddress: Yielded = { null } private var addressLine1: Yielded = { randomStringMultiCaseWithNumbers(10) } private var addressLine2: Yielded = { randomStringMultiCaseWithNumbers(10) } private var town: Yielded = { randomStringMultiCaseWithNumbers(10) } @@ -462,6 +467,10 @@ class ApprovedPremisesSeedCsvRowFactory : Factory { this.name = { name } } + fun withFullAddress(fullAddress: String?) = apply { + this.fullAddress = { fullAddress } + } + fun withAddressLine1(addressLine1: String) = apply { this.addressLine1 = { addressLine1 } } @@ -523,6 +532,7 @@ class ApprovedPremisesSeedCsvRowFactory : Factory { override fun produce() = ApprovedPremisesSeedCsvRow( name = this.name(), + fullAddress = this.fullAddress(), addressLine1 = this.addressLine1(), addressLine2 = this.addressLine2(), town = this.town(), diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/SeedCas1PremiseFromSiteSurveyXlsxTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/SeedCas1PremiseFromSiteSurveyXlsxTest.kt index 59dca3ee42..7c9c39b0d0 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/SeedCas1PremiseFromSiteSurveyXlsxTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/SeedCas1PremiseFromSiteSurveyXlsxTest.kt @@ -36,7 +36,7 @@ class SeedCas1PremiseFromSiteSurveyXlsxTest : SeedTestBase() { "Probation Region", "Yorks & The Humber", "Local Authority Area", "Bournemouth", "Town / City", "Narnia", - "Address", "123 Made Up Town", + "Address", "123 Made Up Town, Narnia", "Postcode", "LE12 ABC", "Male / Female AP?", "Male", "Total number of beds (including any beds out of service)", "22", @@ -74,7 +74,8 @@ class SeedCas1PremiseFromSiteSurveyXlsxTest : SeedTestBase() { val createdPremise = approvedPremisesRepository.findByQCode("Q123")!! assertThat(createdPremise.name).isEqualTo("The Premise Name") - assertThat(createdPremise.addressLine1).isEqualTo("123 Made Up Town") + assertThat(createdPremise.addressLine1).isEqualTo("123 Made Up Town, Narnia") + assertThat(createdPremise.addressLine1).isEqualTo("123 Made Up Town, Narnia") assertThat(createdPremise.addressLine2).isNull() assertThat(createdPremise.town).isEqualTo("Narnia") assertThat(createdPremise.postcode).isEqualTo("LE12 ABC") @@ -194,6 +195,7 @@ class SeedCas1PremiseFromSiteSurveyXlsxTest : SeedTestBase() { val existingPremises = approvedPremisesEntityFactory.produceAndPersist { withQCode("QExisting") withName("Old Name") + withFullAddress("Old Full Address") withAddressLine1("Old Address Line 1") withAddressLine2("Old Address Line 2") withTown("Old Town") @@ -239,7 +241,7 @@ class SeedCas1PremiseFromSiteSurveyXlsxTest : SeedTestBase() { "Probation Region", "Yorks & The Humber", "Local Authority Area", "Windsor and Maidenhead", "Town / City", "Narnia", - "Address", "123 Made Up Town", + "Address", "123 Made Up Town, Narnia", "Postcode", "LE12 ABC", "Male / Female AP?", "Male", "Total number of beds (including any beds out of service)", "22", @@ -277,7 +279,8 @@ class SeedCas1PremiseFromSiteSurveyXlsxTest : SeedTestBase() { val createdPremise = approvedPremisesRepository.findByQCode("QExisting")!! assertThat(createdPremise.name).isEqualTo("The Premise Name") - assertThat(createdPremise.addressLine1).isEqualTo("123 Made Up Town") + assertThat(createdPremise.fullAddress).isEqualTo("123 Made Up Town, Narnia") + assertThat(createdPremise.addressLine1).isEqualTo("123 Made Up Town, Narnia") assertThat(createdPremise.addressLine2).isNull() assertThat(createdPremise.town).isEqualTo("Narnia") assertThat(createdPremise.postcode).isEqualTo("LE12 ABC") diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas1/Cas1SpaceSearchServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas1/Cas1SpaceSearchServiceTest.kt index de65d4a7c4..5a52002097 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas1/Cas1SpaceSearchServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas1/Cas1SpaceSearchServiceTest.kt @@ -86,6 +86,7 @@ class Cas1SpaceSearchServiceTest { 1.0f, ApprovedPremisesType.NORMAL, "Some AP", + fullAddress = "the full address", "1 The Street", null, "Townsbury", @@ -100,6 +101,7 @@ class Cas1SpaceSearchServiceTest { 2.0f, ApprovedPremisesType.ESAP, "Some Other AP", + fullAddress = "the full address", "2 The Street", null, "Townsbury", @@ -114,6 +116,7 @@ class Cas1SpaceSearchServiceTest { 3.0f, ApprovedPremisesType.PIPE, "Some AP", + fullAddress = "the full address", "3 The Street", null, "Townsbury", @@ -196,6 +199,7 @@ class Cas1SpaceSearchServiceTest { 1.0f, ApprovedPremisesType.NORMAL, "Some AP", + fullAddress = "the full address", "1 The Street", null, "Townsbury", @@ -210,6 +214,7 @@ class Cas1SpaceSearchServiceTest { 2.0f, ApprovedPremisesType.ESAP, "Some Other AP", + fullAddress = "the full address", "2 The Street", null, "Townsbury", @@ -224,6 +229,7 @@ class Cas1SpaceSearchServiceTest { 3.0f, ApprovedPremisesType.PIPE, "Some AP", + fullAddress = "the full address", "3 The Street", null, "Townsbury", @@ -298,6 +304,7 @@ class Cas1SpaceSearchServiceTest { 1.0f, ApprovedPremisesType.NORMAL, "Some AP", + fullAddress = "the full address", "1 The Street", null, "Townsbury", @@ -312,6 +319,7 @@ class Cas1SpaceSearchServiceTest { 2.0f, ApprovedPremisesType.ESAP, "Some Other AP", + fullAddress = "the full address", "2 The Street", null, "Townsbury", @@ -326,6 +334,7 @@ class Cas1SpaceSearchServiceTest { 3.0f, ApprovedPremisesType.PIPE, "Some AP", + fullAddress = "the full address", "3 The Street", null, "Townsbury", @@ -399,6 +408,7 @@ class Cas1SpaceSearchServiceTest { 1.0f, ApprovedPremisesType.NORMAL, "Some AP", + fullAddress = "the full address", "1 The Street", null, "Townsbury", @@ -413,6 +423,7 @@ class Cas1SpaceSearchServiceTest { 2.0f, ApprovedPremisesType.ESAP, "Some Other AP", + fullAddress = "the full address", "2 The Street", null, "Townsbury", @@ -427,6 +438,7 @@ class Cas1SpaceSearchServiceTest { 3.0f, ApprovedPremisesType.PIPE, "Some AP", + fullAddress = "the full address", "3 The Street", null, "Townsbury", @@ -512,7 +524,6 @@ class Cas1SpaceSearchServiceTest { @JvmStatic fun spaceCharacteristicArgs(): Stream = generateListEnumArgs() - @OptIn(ExperimentalStdlibApi::class) private inline fun > generateListEnumArgs(): Stream = Stream.concat( enumEntries().map { Arguments.of(listOf(it)) }.stream(), Stream.of(Arguments.of(enumEntries())), diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/cas1/Cas1SpaceSearchResultsTransformerTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/cas1/Cas1SpaceSearchResultsTransformerTest.kt index 41094ae7ae..2a66808aeb 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/cas1/Cas1SpaceSearchResultsTransformerTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/cas1/Cas1SpaceSearchResultsTransformerTest.kt @@ -9,11 +9,10 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.Cas1SpaceSearc import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.Gender import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas1.CandidatePremises import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.ApprovedPremisesType -import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.asApiType import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas1.Cas1SpaceSearchResultsTransformer +import java.math.BigDecimal import java.time.LocalDate import java.util.UUID -import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.Cas1SpaceSearchResult as ApiSpaceSearchResult class Cas1SpaceSearchResultsTransformerTest { private val transformer = Cas1SpaceSearchResultsTransformer() @@ -32,77 +31,82 @@ class Cas1SpaceSearchResultsTransformerTest { ), ) - val candidatePremises1 = CandidatePremises( - UUID.randomUUID(), - 1.0f, - ApprovedPremisesType.NORMAL, - "Some AP", - "1 The Street", - null, - "Townsbury", - "TB1 2AB", - UUID.randomUUID(), - "Some AP Area", - characteristics = emptyList(), - ) - - val candidatePremises2 = CandidatePremises( - UUID.randomUUID(), - 2.0f, - ApprovedPremisesType.NORMAL, - "Some Other AP", - "2 The Street", - null, - "Townsbury", - "TB1 2AB", - UUID.randomUUID(), - "Some AP Area", - characteristics = emptyList(), - ) + val candidatePremise1Id = UUID.randomUUID() + val apAreaId1 = UUID.randomUUID() - val candidatePremises3 = CandidatePremises( - UUID.randomUUID(), - 3.0f, - ApprovedPremisesType.NORMAL, - "Some AP", - "3 The Street", - null, - "Townsbury", - "TB1 2AB", - UUID.randomUUID(), - "Some AP Area", - characteristics = emptyList(), - ) + val candidatePremise2Id = UUID.randomUUID() + val apAreaId2 = UUID.randomUUID() val searchResults = listOf( - candidatePremises1, - candidatePremises2, - candidatePremises3, + CandidatePremises( + premisesId = candidatePremise1Id, + distanceInMiles = 1.0f, + apType = ApprovedPremisesType.NORMAL, + fullAddress = null, + name = "Some AP 1", + addressLine1 = "1 The Street", + addressLine2 = null, + town = "Townsbury", + postcode = "TB1 2AB", + apAreaId = apAreaId1, + apAreaName = "Some AP Area 1", + characteristics = emptyList(), + ), + CandidatePremises( + premisesId = candidatePremise2Id, + distanceInMiles = 2.0f, + apType = ApprovedPremisesType.ESAP, + fullAddress = "The full address, not quite the same, somewhere", + name = "Some Other AP", + addressLine1 = "2 The Street", + addressLine2 = "Additional Bit", + town = "Townton", + postcode = "TB1 2AC", + apAreaId = apAreaId2, + apAreaName = "Some AP Area 2", + characteristics = emptyList(), + ), ) val actual = transformer.transformDomainToApi(searchParameters, searchResults) assertThat(actual.searchCriteria).isNotNull assertThat(actual.searchCriteria).isEqualTo(searchParameters) - assertThat(actual.resultsCount).isEqualTo(3) - assertThatTransformedResultMatches(actual.results[0], candidatePremises1) - assertThatTransformedResultMatches(actual.results[1], candidatePremises2) - assertThatTransformedResultMatches(actual.results[2], candidatePremises3) - } + assertThat(actual.resultsCount).isEqualTo(2) + + val premises1 = actual.results[0].premises + assertThat(premises1).isNotNull + premises1!! + assertThat(premises1.id).isEqualTo(candidatePremise1Id) + assertThat(premises1.apType).isEqualTo(ApType.normal) + assertThat(premises1.name).isEqualTo("Some AP 1") + assertThat(premises1.fullAddress).isEqualTo("1 The Street, Townsbury") + assertThat(premises1.addressLine1).isEqualTo("1 The Street") + assertThat(premises1.addressLine2).isNull() + assertThat(premises1.town).isEqualTo("Townsbury") + assertThat(premises1.postcode).isEqualTo("TB1 2AB") + assertThat(premises1.apArea.id).isEqualTo(apAreaId1) + assertThat(premises1.apArea.name).isEqualTo("Some AP Area 1") + assertThat(premises1.premisesCharacteristics).isEmpty() + assertThat(premises1.characteristics).isEmpty() + assertThat(actual.results[0].distanceInMiles).isEqualTo(BigDecimal.valueOf(1.0)) + assertThat(actual.results[0].spacesAvailable).isEmpty() - private fun assertThatTransformedResultMatches(actual: ApiSpaceSearchResult, expected: CandidatePremises) { - assertThat(actual.premises).isNotNull - assertThat(actual.premises!!.id).isEqualTo(expected.premisesId) - assertThat(actual.premises!!.apType).isEqualTo(expected.apType.asApiType()) - assertThat(actual.premises!!.name).isEqualTo(expected.name) - assertThat(actual.premises!!.addressLine1).isEqualTo(expected.addressLine1) - assertThat(actual.premises!!.addressLine2).isEqualTo(expected.addressLine2) - assertThat(actual.premises!!.town).isEqualTo(expected.town) - assertThat(actual.premises!!.postcode).isEqualTo(expected.postcode) - assertThat(actual.premises!!.apArea).isNotNull - assertThat(actual.premises!!.apArea!!.id).isEqualTo(expected.apAreaId) - assertThat(actual.premises!!.apArea!!.name).isEqualTo(expected.apAreaName) - assertThat(actual.premises!!.premisesCharacteristics).isEmpty() - assertThat(actual.distanceInMiles).isEqualTo(expected.distanceInMiles.toBigDecimal()) - assertThat(actual.spacesAvailable).isEmpty() + val premises2 = actual.results[1].premises + assertThat(premises2).isNotNull + premises2!! + assertThat(premises2.id).isEqualTo(candidatePremise2Id) + assertThat(premises2.apType).isEqualTo(ApType.esap) + assertThat(premises2.name).isEqualTo("Some Other AP") + assertThat(premises2.fullAddress).isEqualTo("The full address, not quite the same, somewhere") + assertThat(premises2.addressLine1).isEqualTo("2 The Street") + assertThat(premises2.addressLine2).isEqualTo("Additional Bit") + assertThat(premises2.town).isEqualTo("Townton") + assertThat(premises2.postcode).isEqualTo("TB1 2AC") + assertThat(premises2.apArea.id).isEqualTo(apAreaId2) + assertThat(premises2.apArea.name).isEqualTo("Some AP Area 2") + assertThat(premises2.premisesCharacteristics).isEmpty() + assertThat(premises2.characteristics).isEmpty() + assertThat(actual.results[1].distanceInMiles).isEqualTo(BigDecimal.valueOf(2.0)) + assertThat(actual.results[1].spacesAvailable).isEmpty() } }