diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/PremisesController.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/PremisesController.kt index dad9755378..b4d862fadc 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/PremisesController.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/PremisesController.kt @@ -68,8 +68,8 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.UserAccessServic import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.UserService import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1.Cas1WithdrawableService import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3.Cas3BookingService -import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3.Cas3LostBedService import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3.Cas3PremisesService +import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3.Cas3VoidBedspaceService import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ArrivalTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.BedDetailTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.BedSummaryTransformer @@ -84,8 +84,8 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.PremisesTran import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.RoomTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.StaffMemberTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.TurnaroundTransformer -import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedCancellationTransformer -import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedsTransformer +import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspaceCancellationTransformer +import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspacesTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.extractEntityFromAuthorisableActionResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.extractEntityFromCasResult import java.time.LocalDate @@ -102,12 +102,12 @@ class PremisesController( private val offenderService: OffenderService, private val bookingService: BookingService, private val cas3BookingService: Cas3BookingService, - private val lostBedsService: Cas3LostBedService, + private val cas3VoidBedspaceService: Cas3VoidBedspaceService, private val bedService: BedService, private val premisesTransformer: PremisesTransformer, private val premisesSummaryTransformer: PremisesSummaryTransformer, private val bookingTransformer: BookingTransformer, - private val cas3LostBedsTransformer: Cas3LostBedsTransformer, + private val cas3VoidBedspacesTransformer: Cas3VoidBedspacesTransformer, private val arrivalTransformer: ArrivalTransformer, private val cancellationTransformer: CancellationTransformer, private val confirmationTransformer: ConfirmationTransformer, @@ -117,7 +117,7 @@ class PremisesController( private val staffMemberService: StaffMemberService, private val roomService: RoomService, private val roomTransformer: RoomTransformer, - private val cas3LostBedCancellationTransformer: Cas3LostBedCancellationTransformer, + private val cas3VoidBedspaceCancellationTransformer: Cas3VoidBedspaceCancellationTransformer, private val turnaroundTransformer: TurnaroundTransformer, private val bedSummaryTransformer: BedSummaryTransformer, private val bedDetailTransformer: BedDetailTransformer, @@ -690,7 +690,7 @@ class PremisesController( val premises = premisesService.getPremises(premisesId) ?: throw NotFoundProblem(premisesId, "Premises") - if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) { + if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) { throw ForbiddenProblem() } @@ -707,9 +707,9 @@ class PremisesController( bedId = body.bedId, ) - val lostBeds = extractResultEntityOrThrow(result) + val voidBedspaces = extractResultEntityOrThrow(result) - return ResponseEntity.ok(cas3LostBedsTransformer.transformJpaToApi(lostBeds)) + return ResponseEntity.ok(cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspaces)) } override fun premisesPremisesIdLostBedsGet(premisesId: UUID): ResponseEntity> { @@ -718,13 +718,13 @@ class PremisesController( val premises = cas3PremisesService.getPremises(premisesId) ?: throw NotFoundProblem(premisesId, "Premises") - val lostBeds = lostBedsService.getActiveLostBedsForPremisesId(premisesId) + val voidBedspaces = cas3VoidBedspaceService.getActiveVoidBedspacesForPremisesId(premisesId) - if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) { + if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) { throw ForbiddenProblem() } - return ResponseEntity.ok(lostBeds.map(cas3LostBedsTransformer::transformJpaToApi)) + return ResponseEntity.ok(voidBedspaces.map(cas3VoidBedspacesTransformer::transformJpaToApi)) } override fun premisesPremisesIdLostBedsLostBedIdGet(premisesId: UUID, lostBedId: UUID): ResponseEntity { @@ -733,14 +733,14 @@ class PremisesController( val premises = cas3PremisesService.getPremises(premisesId) ?: throw NotFoundProblem(premisesId, "Premises") - if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) { + if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) { throw ForbiddenProblem() } - val lostBed = premises.lostBeds.firstOrNull { it.id == lostBedId } + val voidBedspace = premises.voidBedspaces.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "LostBed") - return ResponseEntity.ok(cas3LostBedsTransformer.transformJpaToApi(lostBed)) + return ResponseEntity.ok(cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspace)) } override fun premisesPremisesIdLostBedsLostBedIdPut( @@ -751,16 +751,16 @@ class PremisesController( throwIfRequestIsForApprovedPremises("PUT /cas1/premises/$premisesId/lost-beds/$lostBedId") val premises = cas3PremisesService.getPremises(premisesId) ?: throw NotFoundProblem(premisesId, "Premises") - val lostBed = premises.lostBeds.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "LostBed") + val voidBedspace = premises.voidBedspaces.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "VoidBedspace") - if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) { + if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) { throw ForbiddenProblem() } - throwIfBookingDatesConflict(body.startDate, body.endDate, null, lostBed.bed.id) - throwIfVoidBedspaceDatesConflict(body.startDate, body.endDate, lostBedId, lostBed.bed.id) + throwIfBookingDatesConflict(body.startDate, body.endDate, null, voidBedspace.bed.id) + throwIfVoidBedspaceDatesConflict(body.startDate, body.endDate, lostBedId, voidBedspace.bed.id) - val updateLostBedResult = cas3PremisesService + val updateVoidBedspaceResult = cas3PremisesService .updateVoidBedspaces( lostBedId, body.startDate, @@ -770,13 +770,13 @@ class PremisesController( body.notes, ) - val validationResult = when (updateLostBedResult) { - is AuthorisableActionResult.NotFound -> throw NotFoundProblem(lostBedId, "LostBed") + val validationResult = when (updateVoidBedspaceResult) { + is AuthorisableActionResult.NotFound -> throw NotFoundProblem(lostBedId, "VoidBedspace") is AuthorisableActionResult.Unauthorised -> throw ForbiddenProblem() - is AuthorisableActionResult.Success -> updateLostBedResult.entity + is AuthorisableActionResult.Success -> updateVoidBedspaceResult.entity } - val updatedLostBed = when (validationResult) { + val updatedVoidBedspace = when (validationResult) { is ValidatableActionResult.GeneralValidationError -> throw BadRequestProblem(errorDetail = validationResult.message) is ValidatableActionResult.FieldValidationError -> throw BadRequestProblem(invalidParams = validationResult.validationMessages) is ValidatableActionResult.ConflictError -> throw ConflictProblem( @@ -787,7 +787,7 @@ class PremisesController( is ValidatableActionResult.Success -> validationResult.entity } - return ResponseEntity.ok(cas3LostBedsTransformer.transformJpaToApi(updatedLostBed)) + return ResponseEntity.ok(cas3VoidBedspacesTransformer.transformJpaToApi(updatedVoidBedspace)) } override fun premisesPremisesIdLostBedsLostBedIdCancellationsPost( @@ -798,9 +798,9 @@ class PremisesController( throwIfRequestIsForApprovedPremises("POST /cas1/premises/$premisesId/lost-beds/$lostBedId/cancellations") val premises = cas3PremisesService.getPremises(premisesId) ?: throw NotFoundProblem(premisesId, "Premises") - val voidBedspace = premises.lostBeds.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "LostBed") + val voidBedspace = premises.voidBedspaces.firstOrNull { it.id == lostBedId } ?: throw NotFoundProblem(lostBedId, "VoidBedspace") - if (!userAccessService.currentUserCanManagePremisesLostBeds(premises)) { + if (!userAccessService.currentUserCanManagePremisesVoidBedspaces(premises)) { throw ForbiddenProblem() } @@ -820,7 +820,7 @@ class PremisesController( is ValidatableActionResult.Success -> cancelVoidBedspaceResult.entity } - return ResponseEntity.ok(cas3LostBedCancellationTransformer.transformJpaToApi(cancellation)) + return ResponseEntity.ok(cas3VoidBedspaceCancellationTransformer.transformJpaToApi(cancellation)) } override fun premisesPremisesIdStaffGet(premisesId: UUID): ResponseEntity> { @@ -1059,7 +1059,7 @@ class PremisesController( thisEntityId: UUID?, bedId: UUID, ) { - bookingService.getLostBedWithConflictingDates(startDate, endDate, thisEntityId, bedId)?.let { + bookingService.getVoidBedspaceWithConflictingDates(startDate, endDate, thisEntityId, bedId)?.let { throw ConflictProblem( it.id, "A Lost Bed already exists for dates from ${it.startDate} to ${it.endDate} which overlaps with the desired dates", diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/ReferenceDataController.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/ReferenceDataController.kt index 431b1b3c95..1f216969bd 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/ReferenceDataController.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/ReferenceDataController.kt @@ -27,7 +27,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.NonArrivalRea import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationDeliveryUnitRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationRegionRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ReferralRejectionReasonRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.problem.ForbiddenProblem import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ApAreaTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.CancellationReasonTransformer @@ -40,7 +40,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.NonArrivalRe import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ProbationDeliveryUnitTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ProbationRegionTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ReferralRejectionReasonTransformer -import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedReasonTransformer +import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspaceReasonTransformer import java.util.UUID @Service @@ -49,7 +49,7 @@ class ReferenceDataController( private val moveOnCategoryRepository: MoveOnCategoryRepository, private val destinationProviderRepository: DestinationProviderRepository, private val cancellationReasonRepository: CancellationReasonRepository, - private val cas3LostBedReasonRepository: Cas3LostBedReasonRepository, + private val cas3VoidBedspaceReasonRepository: Cas3VoidBedspaceReasonRepository, private val localAuthorityAreaRepository: LocalAuthorityAreaRepository, private val characteristicRepository: CharacteristicRepository, private val probationRegionRepository: ProbationRegionRepository, @@ -60,7 +60,7 @@ class ReferenceDataController( private val moveOnCategoryTransformer: MoveOnCategoryTransformer, private val destinationProviderTransformer: DestinationProviderTransformer, private val cancellationReasonTransformer: CancellationReasonTransformer, - private val cas3LostBedReasonTransformer: Cas3LostBedReasonTransformer, + private val cas3VoidBedspaceReasonTransformer: Cas3VoidBedspaceReasonTransformer, private val localAuthorityAreaTransformer: LocalAuthorityAreaTransformer, private val characteristicTransformer: CharacteristicTransformer, private val probationRegionTransformer: ProbationRegionTransformer, @@ -144,12 +144,12 @@ class ReferenceDataController( } override fun referenceDataLostBedReasonsGet(xServiceName: ServiceName?): ResponseEntity> { - val lostBedReasons = when (xServiceName == ServiceName.temporaryAccommodation) { - true -> cas3LostBedReasonRepository.findAllByServiceScope(xServiceName.value) + val voidBedspaceReasons = when (xServiceName == ServiceName.temporaryAccommodation) { + true -> cas3VoidBedspaceReasonRepository.findAllByServiceScope(xServiceName.value) false -> throw ForbiddenProblem() } - return ResponseEntity.ok(lostBedReasons.map(cas3LostBedReasonTransformer::transformJpaToApi)) + return ResponseEntity.ok(voidBedspaceReasons.map(cas3VoidBedspaceReasonTransformer::transformJpaToApi)) } override fun referenceDataProbationRegionsGet(): ResponseEntity> { diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/cas1/Cas1ReportsController.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/cas1/Cas1ReportsController.kt index 3348a0bc00..d45eccc244 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/cas1/Cas1ReportsController.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/controller/cas1/Cas1ReportsController.kt @@ -11,7 +11,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.controller.generateStrea import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserPermission import uk.gov.justice.digital.hmpps.approvedpremisesapi.problem.BadRequestProblem import uk.gov.justice.digital.hmpps.approvedpremisesapi.problem.NotAllowedProblem -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.LostBedReportProperties +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.VoidBedspaceReportProperties import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.UserAccessService import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1.Cas1ReportService import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1.Cas1ReportService.MonthSpecificReportParams @@ -75,7 +75,7 @@ class Cas1ReportsController( contentType = ContentType.XLSX, fileName = createCas1ReportName("lost-beds", year, month, ContentType.XLSX), ) { outputStream -> - cas1ReportService.createLostBedReport(LostBedReportProperties(xServiceName, null, year, month), outputStream) + cas1ReportService.createLostBedReport(VoidBedspaceReportProperties(xServiceName, null, year, month), outputStream) } Cas1ReportName.outOfServiceBeds -> return generateStreamingResponse( contentType = ContentType.XLSX, 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 cb4937b750..42c98ba806 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 @@ -21,7 +21,7 @@ import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.BookingStatus import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.PropertyStatus -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity import java.time.LocalDate import java.util.UUID @@ -242,7 +242,7 @@ abstract class PremisesEntity( @OneToMany(mappedBy = "premises") val bookings: MutableList, @OneToMany(mappedBy = "premises") - val lostBeds: MutableList, + val voidBedspaces: MutableList, @OneToMany(mappedBy = "premises") val rooms: MutableList, @ManyToMany @@ -275,7 +275,7 @@ class ApprovedPremisesEntity( probationRegion: ProbationRegionEntity, localAuthorityArea: LocalAuthorityAreaEntity, bookings: MutableList, - lostBeds: MutableList, + lostBeds: MutableList, var apCode: String, var qCode: String, rooms: MutableList, @@ -337,7 +337,7 @@ class TemporaryAccommodationPremisesEntity( probationRegion: ProbationRegionEntity, localAuthorityArea: LocalAuthorityAreaEntity?, bookings: MutableList, - lostBeds: MutableList, + lostBeds: MutableList, rooms: MutableList, characteristics: MutableList, status: PropertyStatus, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedCancellationEntity.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspaceCancellationEntity.kt similarity index 73% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedCancellationEntity.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspaceCancellationEntity.kt index 8c0ee5e866..8dfe8e3181 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedCancellationEntity.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspaceCancellationEntity.kt @@ -12,22 +12,22 @@ import java.util.Objects import java.util.UUID @Repository -interface Cas3LostBedCancellationRepository : JpaRepository +interface Cas3VoidBedspaceCancellationRepository : JpaRepository @Entity @Table(name = "lost_bed_cancellations") -data class Cas3LostBedCancellationEntity( +data class Cas3VoidBedspaceCancellationEntity( @Id val id: UUID, val createdAt: OffsetDateTime, val notes: String?, @OneToOne @JoinColumn(name = "lost_bed_id") - val lostBed: Cas3LostBedsEntity, + val voidBedspace: Cas3VoidBedspacesEntity, ) { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Cas3LostBedCancellationEntity) return false + if (other !is Cas3VoidBedspaceCancellationEntity) return false if (id != other.id) return false if (notes != other.notes) return false @@ -38,5 +38,5 @@ data class Cas3LostBedCancellationEntity( override fun hashCode() = Objects.hash(notes, createdAt) - override fun toString() = "Cas3LostBedCancellationEntity:$id" + override fun toString() = "Cas3VoidBedspaceCancellationEntity:$id" } diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedReasonEntity.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspaceReasonEntity.kt similarity index 61% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedReasonEntity.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspaceReasonEntity.kt index a623301f8f..e02d38d942 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedReasonEntity.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspaceReasonEntity.kt @@ -10,20 +10,20 @@ import org.springframework.stereotype.Repository import java.util.UUID @Repository -interface Cas3LostBedReasonRepository : JpaRepository { - @Query("SELECT l FROM Cas3LostBedReasonEntity l WHERE l.serviceScope = :serviceName OR l.serviceScope = '*'") - fun findAllByServiceScope(serviceName: String): List +interface Cas3VoidBedspaceReasonRepository : JpaRepository { + @Query("SELECT l FROM Cas3VoidBedspaceReasonEntity l WHERE l.serviceScope = :serviceName OR l.serviceScope = '*'") + fun findAllByServiceScope(serviceName: String): List } @Entity @Table(name = "lost_bed_reasons") @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY) -data class Cas3LostBedReasonEntity( +data class Cas3VoidBedspaceReasonEntity( @Id val id: UUID, val name: String, val isActive: Boolean, val serviceScope: String, ) { - override fun toString() = "Cas3LostBedReasonEntity:$id" + override fun toString() = "Cas3VoidBedspaceReasonEntity:$id" } diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedsEntity.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspacesEntity.kt similarity index 60% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedsEntity.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspacesEntity.kt index bea4bcb2ce..16e076da4d 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3LostBedsEntity.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/jpa/entity/cas3/Cas3VoidBedspacesEntity.kt @@ -16,20 +16,20 @@ import java.util.Objects import java.util.UUID @Repository -interface Cas3LostBedsRepository : JpaRepository { - @Query("SELECT lb FROM Cas3LostBedsEntity lb WHERE lb.premises.id = :premisesId AND lb.startDate <= :endDate AND lb.endDate >= :startDate") - fun findAllByPremisesIdAndOverlappingDate(premisesId: UUID, startDate: LocalDate, endDate: LocalDate): List +interface Cas3VoidBedspacesRepository : JpaRepository { + @Query("SELECT lb FROM Cas3VoidBedspacesEntity lb WHERE lb.premises.id = :premisesId AND lb.startDate <= :endDate AND lb.endDate >= :startDate") + fun findAllByPremisesIdAndOverlappingDate(premisesId: UUID, startDate: LocalDate, endDate: LocalDate): List - @Query("SELECT MAX(lb.endDate) FROM Cas3LostBedsEntity lb WHERE lb.premises.id = :premisesId") + @Query("SELECT MAX(lb.endDate) FROM Cas3VoidBedspacesEntity lb WHERE lb.premises.id = :premisesId") fun getHighestBookingDate(premisesId: UUID): LocalDate? - @Query("SELECT lb FROM Cas3LostBedsEntity lb WHERE lb.bed.id IN :lostBedIds") - fun findByBedIds(lostBedIds: List): List + @Query("SELECT lb FROM Cas3VoidBedspacesEntity lb WHERE lb.bed.id IN :voidBedspaceIds") + fun findByBedIds(voidBedspaceIds: List): List @Query( """ SELECT lb - FROM Cas3LostBedsEntity lb + FROM Cas3VoidBedspacesEntity lb LEFT JOIN lb.cancellation c WHERE lb.bed.id = :bedId AND lb.startDate <= :endDate AND @@ -38,40 +38,40 @@ interface Cas3LostBedsRepository : JpaRepository { c is NULL """, ) - fun findByBedIdAndOverlappingDate(bedId: UUID, startDate: LocalDate, endDate: LocalDate, thisEntityId: UUID?): List + fun findByBedIdAndOverlappingDate(bedId: UUID, startDate: LocalDate, endDate: LocalDate, thisEntityId: UUID?): List - @Query("SELECT lb FROM Cas3LostBedsEntity lb LEFT JOIN lb.cancellation c WHERE lb.startDate <= :endDate AND lb.endDate >= :startDate AND lb.bed = :bed AND c is NULL") - fun findAllByOverlappingDateForBed(startDate: LocalDate, endDate: LocalDate, bed: BedEntity): List + @Query("SELECT lb FROM Cas3VoidBedspacesEntity lb LEFT JOIN lb.cancellation c WHERE lb.startDate <= :endDate AND lb.endDate >= :startDate AND lb.bed = :bed AND c is NULL") + fun findAllByOverlappingDateForBed(startDate: LocalDate, endDate: LocalDate, bed: BedEntity): List - @Query("SELECT lb FROM Cas3LostBedsEntity lb LEFT JOIN lb.cancellation c WHERE lb.premises.id = :premisesId AND c is NULL") - fun findAllActiveForPremisesId(premisesId: UUID): List + @Query("SELECT lb FROM Cas3VoidBedspacesEntity lb LEFT JOIN lb.cancellation c WHERE lb.premises.id = :premisesId AND c is NULL") + fun findAllActiveForPremisesId(premisesId: UUID): List } @SuppressWarnings("LongParameterList") @Entity @Table(name = "lost_beds") -class Cas3LostBedsEntity( +class Cas3VoidBedspacesEntity( @Id val id: UUID, var startDate: LocalDate, var endDate: LocalDate, @ManyToOne @JoinColumn(name = "lost_bed_reason_id") - var reason: Cas3LostBedReasonEntity, + var reason: Cas3VoidBedspaceReasonEntity, var referenceNumber: String?, var notes: String?, @ManyToOne @JoinColumn(name = "premises_id") var premises: PremisesEntity, - @OneToOne(mappedBy = "lostBed") - var cancellation: Cas3LostBedCancellationEntity?, + @OneToOne(mappedBy = "voidBedspace") + var cancellation: Cas3VoidBedspaceCancellationEntity?, @ManyToOne @JoinColumn(name = "bed_id") var bed: BedEntity, ) { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Cas3LostBedsEntity) return false + if (other !is Cas3VoidBedspacesEntity) return false if (id != other.id) return false if (startDate != other.startDate) return false @@ -85,5 +85,5 @@ class Cas3LostBedsEntity( override fun hashCode() = Objects.hash(id, startDate, endDate, reason, referenceNumber, notes) - override fun toString() = "Cas3LostBedsEntity:$id" + override fun toString() = "Cas3VoidBedspacesEntity:$id" } diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/model/Availability.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/model/Availability.kt index 81938ae135..4f3dae5c27 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/model/Availability.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/model/Availability.kt @@ -8,7 +8,7 @@ data class Availability( val arrivedBookings: Int, val nonArrivedBookings: Int, val cancelledBookings: Int, - val lostBeds: Int, + val voidBedspaces: Int, ) { - fun getFreeCapacity(totalBeds: Int) = ((totalBeds - pendingBookings) - arrivedBookings) - lostBeds + fun getFreeCapacity(totalBeds: Int) = ((totalBeds - pendingBookings) - arrivedBookings) - voidBedspaces } diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/BedUsageReportGenerator.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/BedUsageReportGenerator.kt index d3a2f0bd6b..5173f1649a 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/BedUsageReportGenerator.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/BedUsageReportGenerator.kt @@ -3,7 +3,7 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BedEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationPremisesEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUsageReportRow import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUsageType import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.BedUsageReportProperties @@ -15,7 +15,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.getDaysUntilExclusi class BedUsageReportGenerator( private val bookingTransformer: BookingTransformer, private val bookingRepository: BookingRepository, - private val lostBedsRepository: Cas3LostBedsRepository, + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, private val workingDayService: WorkingDayService, ) : ReportGenerator(BedUsageReportRow::class) { override fun filter(properties: BedUsageReportProperties): (BedEntity) -> Boolean = { @@ -25,7 +25,7 @@ class BedUsageReportGenerator( override val convert: BedEntity.(properties: BedUsageReportProperties) -> List = { properties -> val bookings = bookingRepository.findAllByOverlappingDateForBed(properties.startDate, properties.endDate, this) - val voids = lostBedsRepository.findAllByOverlappingDateForBed(properties.startDate, properties.endDate, this) + val voids = cas3VoidBedspacesRepository.findAllByOverlappingDateForBed(properties.startDate, properties.endDate, this) val premises = this.room.premises val temporaryAccommodationPremisesEntity = premises as? TemporaryAccommodationPremisesEntity diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/BedUtilisationReportGenerator.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/BedUtilisationReportGenerator.kt index a2e368365e..56a604fc53 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/BedUtilisationReportGenerator.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/BedUtilisationReportGenerator.kt @@ -36,7 +36,7 @@ class BedUtilisationReportGenerator( .groupBy { it.bookingId } .mapValues { it.value.sortedByDescending { it.arrivalCreatedAt }.take(1) } .map { it.value.first() } - val nonCancelledVoids = this.lostBedReportData.filter { it.cancellationId == null } + val nonCancelledVoids = this.voidBedspaceReportData.filter { it.cancellationId == null } nonCancelledBookings .forEach { booking -> diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/LostBedsReportGenerator.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/VoidBedspacesReportGenerator.kt similarity index 68% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/LostBedsReportGenerator.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/VoidBedspacesReportGenerator.kt index 6867e2beb7..10453513c3 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/LostBedsReportGenerator.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/generator/VoidBedspacesReportGenerator.kt @@ -1,34 +1,34 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BedEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.LostBedReportRow -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.LostBedReportProperties +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.VoidBedspaceReportRow +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.VoidBedspaceReportProperties import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.earliestDateOf import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.getDaysUntilInclusive import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.latestDateOf import java.time.LocalDate -class LostBedsReportGenerator( - private val lostBedsRepository: Cas3LostBedsRepository, -) : ReportGenerator(LostBedReportRow::class) { - override fun filter(properties: LostBedReportProperties): (BedEntity) -> Boolean = { +class VoidBedspacesReportGenerator( + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, +) : ReportGenerator(VoidBedspaceReportRow::class) { + override fun filter(properties: VoidBedspaceReportProperties): (BedEntity) -> Boolean = { checkServiceType(properties.serviceName, it.room.premises) && (properties.probationRegionId == null || it.room.premises.probationRegion.id == properties.probationRegionId) } - override val convert: BedEntity.(properties: LostBedReportProperties) -> List = { properties -> + override val convert: BedEntity.(properties: VoidBedspaceReportProperties) -> List = { properties -> val startOfMonth = LocalDate.of(properties.year, properties.month, 1) val endOfMonth = LocalDate.of(properties.year, properties.month, startOfMonth.month.length(startOfMonth.isLeapYear)) - val lostBeds = lostBedsRepository.findAllByOverlappingDateForBed(startOfMonth, endOfMonth, this) + val voidBedspaces = cas3VoidBedspacesRepository.findAllByOverlappingDateForBed(startOfMonth, endOfMonth, this) - lostBeds.map { + voidBedspaces.map { val bed = it.bed val room = bed.room val premises = room.premises - LostBedReportRow( + VoidBedspaceReportRow( roomName = room.name, bedName = bed.name, id = it.id.toString(), diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/BedUtilisationReportData.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/BedUtilisationReportData.kt index 51a53a6375..40008fd4e9 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/BedUtilisationReportData.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/BedUtilisationReportData.kt @@ -4,12 +4,12 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisatio import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationBookingCancellationReportData import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationBookingReportData import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationBookingTurnaroundReportData -import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationLostBedReportData +import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationVoidBedspaceReportData data class BedUtilisationReportData( val bedspaceReportData: BedUtilisationBedspaceReportData, val bookingsReportData: List, val bookingCancellationReportData: List, val bookingTurnaroundReportData: List, - val lostBedReportData: List, + val voidBedspaceReportData: List, ) diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/LostBedReportRow.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/VoidBedspaceReportRow.kt similarity index 90% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/LostBedReportRow.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/VoidBedspaceReportRow.kt index defc98fd04..48fb64875c 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/LostBedReportRow.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/model/VoidBedspaceReportRow.kt @@ -2,7 +2,7 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model import java.time.LocalDate -data class LostBedReportRow( +data class VoidBedspaceReportRow( val roomName: String, val bedName: String, val id: String, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/properties/LostBedReportProperties.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/properties/VoidBedspaceReportProperties.kt similarity index 87% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/properties/LostBedReportProperties.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/properties/VoidBedspaceReportProperties.kt index c3ee9d21c0..bde3280149 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/properties/LostBedReportProperties.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/reporting/properties/VoidBedspaceReportProperties.kt @@ -3,7 +3,7 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.ServiceName import java.util.UUID -data class LostBedReportProperties( +data class VoidBedspaceReportProperties( val serviceName: ServiceName, val probationRegionId: UUID?, val year: Int, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/BedUtilisationReportRepository.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/BedUtilisationReportRepository.kt index 2241d7b2be..9af4f77db4 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/BedUtilisationReportRepository.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/BedUtilisationReportRepository.kt @@ -131,7 +131,7 @@ interface BedUtilisationReportRepository : JpaRepository { """, nativeQuery = true, ) - fun findAllLostBedByOverlappingDate(probationRegionId: UUID?, startDate: LocalDate, endDate: LocalDate): List + fun findAllVoidBedspaceByOverlappingDate(probationRegionId: UUID?, startDate: LocalDate, endDate: LocalDate): List } interface BedUtilisationBedspaceReportData { val bedId: String @@ -174,7 +174,7 @@ interface BedUtilisationBookingTurnaroundReportData { val createdAt: Instant } -interface BedUtilisationLostBedReportData { +interface BedUtilisationVoidBedspaceReportData { val bedId: String val startDate: LocalDate val endDate: LocalDate diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/BookingService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/BookingService.kt index 815635b4a7..912e0f29a3 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/BookingService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/BookingService.kt @@ -31,7 +31,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAcco import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserPermission import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserQualification -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.serviceScopeMatches import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.PersonInfoResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.validated @@ -67,7 +67,7 @@ class BookingService( private val cancellationReasonRepository: CancellationReasonRepository, private val bedRepository: BedRepository, private val placementRequestRepository: PlacementRequestRepository, - private val lostBedsRepository: Cas3LostBedsRepository, + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, private val premisesRepository: PremisesRepository, private val userService: UserService, private val userAccessService: UserAccessService, @@ -142,7 +142,7 @@ class BookingService( return@validated it.id hasConflictError "A Booking already exists for dates from ${it.arrivalDate} to ${it.departureDate} which overlaps with the desired dates" } - getLostBedWithConflictingDates(arrivalDate, departureDate, null, bedId)?.let { + getVoidBedspaceWithConflictingDates(arrivalDate, departureDate, null, bedId)?.let { return@validated it.id hasConflictError "A Lost Bed already exists for dates from ${it.startDate} to ${it.endDate} which overlaps with the desired dates" } @@ -443,7 +443,7 @@ class BookingService( return@validatedCasResult it.id hasConflictError "A Booking already exists for dates from ${it.arrivalDate} to ${it.lastUnavailableDate} which overlaps with the desired dates" } - getLostBedWithConflictingDates(effectiveNewArrivalDate, expectedLastUnavailableDate, null, bedId)?.let { + getVoidBedspaceWithConflictingDates(effectiveNewArrivalDate, expectedLastUnavailableDate, null, bedId)?.let { return@validatedCasResult it.id hasConflictError "A Lost Bed already exists for dates from ${it.startDate} to ${it.endDate} which overlaps with the desired dates" } } @@ -528,12 +528,12 @@ class BookingService( return candidateBookings.firstOrNull { it.lastUnavailableDate >= arrivalDate } } - fun getLostBedWithConflictingDates( + fun getVoidBedspaceWithConflictingDates( startDate: LocalDate, endDate: LocalDate, thisEntityId: UUID?, bedId: UUID, - ) = lostBedsRepository.findByBedIdAndOverlappingDate( + ) = cas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bedId, startDate, endDate, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/PremisesService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/PremisesService.kt index cebaa86e59..f26fdc60d0 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/PremisesService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/PremisesService.kt @@ -21,7 +21,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationDeli import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationRegionRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.RoomRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationPremisesEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.Availability import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.ValidationErrors import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.validated @@ -34,7 +34,7 @@ import java.util.UUID @Service class PremisesService( private val premisesRepository: PremisesRepository, - private val lostBedsRepository: Cas3LostBedsRepository, + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, private val bookingRepository: BookingRepository, private val localAuthorityAreaRepository: LocalAuthorityAreaRepository, private val probationRegionRepository: ProbationRegionRepository, @@ -73,7 +73,7 @@ class PremisesService( fun getPremisesSummary(premisesId: UUID): List = premisesRepository.getBookingSummariesForPremisesId(premisesId) fun getLastBookingDate(premises: PremisesEntity) = bookingRepository.getHighestBookingDate(premises.id) - fun getLastLostBedsDate(premises: PremisesEntity) = lostBedsRepository.getHighestBookingDate(premises.id) + fun getLastLostBedsDate(premises: PremisesEntity) = cas3VoidBedspacesRepository.getHighestBookingDate(premises.id) fun getAvailabilityForRange( premises: PremisesEntity, @@ -83,7 +83,7 @@ class PremisesService( if (endDate.isBefore(startDate)) throw RuntimeException("startDate must be before endDate when calculating availability for range") val bookings = bookingRepository.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) - val lostBeds = lostBedsRepository.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) + val lostBeds = cas3VoidBedspacesRepository.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) return startDate.getDaysUntilExclusiveEnd(endDate).map { date -> val bookingsOnDay = bookings.filter { booking -> booking.getArrivalDate() <= date && booking.getDepartureDate() > date } @@ -95,7 +95,7 @@ class PremisesService( arrivedBookings = bookingsOnDay.count { it.getArrived() }, nonArrivedBookings = bookingsOnDay.count { it.getIsNotArrived() }, cancelledBookings = bookingsOnDay.count { it.getCancelled() }, - lostBeds = lostBedsOnDay.size, + voidBedspaces = lostBedsOnDay.size, ) }.associateBy { it.date } } @@ -305,8 +305,8 @@ class PremisesService( return premises.id hasConflictError "A premises cannot be hard-deleted if it has any bookings associated with it" } - premises.lostBeds.forEach { lostBed -> - lostBedsRepository.delete(lostBed) + premises.voidBedspaces.forEach { lostBed -> + cas3VoidBedspacesRepository.delete(lostBed) } premises.rooms.forEach { room -> diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/RoomService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/RoomService.kt index 62e71ca3eb..1d9661e6c6 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/RoomService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/RoomService.kt @@ -10,7 +10,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.PremisesEntit import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.RoomEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.RoomRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationPremisesEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.ValidationErrors import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.validated import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.AuthorisableActionResult @@ -24,7 +24,7 @@ class RoomService( private val roomRepository: RoomRepository, private val bedRepository: BedRepository, private val bookingRepository: BookingRepository, - private val lostBedsRepository: Cas3LostBedsRepository, + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, private val characteristicService: CharacteristicService, ) { fun getRoom(roomId: UUID) = roomRepository.findByIdOrNull(roomId) @@ -201,8 +201,8 @@ class RoomService( return room.id hasConflictError "A room cannot be hard-deleted if it has any bookings associated with it" } - lostBedsRepository.findByBedIds(bedIds).forEach { lostBed -> - lostBedsRepository.delete(lostBed) + cas3VoidBedspacesRepository.findByBedIds(bedIds).forEach { voidBedspace -> + cas3VoidBedspacesRepository.delete(voidBedspace) } room.beds.forEach { bed -> diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/UserAccessService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/UserAccessService.kt index 424227d16e..f89cfbc81e 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/UserAccessService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/UserAccessService.kt @@ -93,10 +93,10 @@ class UserAccessService( else -> false } - fun currentUserCanManagePremisesLostBeds(premises: PremisesEntity) = - userCanManagePremisesLostBeds(userService.getUserForRequest(), premises) + fun currentUserCanManagePremisesVoidBedspaces(premises: PremisesEntity) = + userCanManagePremisesVoidBedspaces(userService.getUserForRequest(), premises) - fun userCanManagePremisesLostBeds(user: UserEntity, premises: PremisesEntity) = when (premises) { + fun userCanManagePremisesVoidBedspaces(user: UserEntity, premises: PremisesEntity) = when (premises) { is TemporaryAccommodationPremisesEntity -> userCanAccessRegion(user, premises.probationRegion.id) && user.hasRole(UserRole.CAS3_ASSESSOR) else -> false } diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1ReportService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1ReportService.kt index 2b82a0935a..cfa026c93f 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1ReportService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1ReportService.kt @@ -13,14 +13,14 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas1.Cas1Appl import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas1.Cas1PlacementMatchingOutcomesReportRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas1.Cas1PlacementMatchingOutcomesV2ReportRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas1.Cas1RequestForPlacementReportRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.ApplicationReportGenerator import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.Cas1OutOfServiceBedsReportGenerator import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.DailyMetricsReportGenerator -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.LostBedsReportGenerator import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.PlacementApplicationReportGenerator +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.VoidBedspacesReportGenerator import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.ApprovedPremisesApplicationMetricsSummaryDto -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.LostBedReportProperties +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.VoidBedspaceReportProperties import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.util.CsvJdbcResultSetConsumer import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.util.ExcelJdbcResultSetConsumer import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.toLocalDate @@ -39,7 +39,7 @@ class Cas1ReportService( private val cas1ApplicationV2ReportRepository: Cas1ApplicationV2ReportRepository, private val cas1PlacementRequestReportRepository: Cas1RequestForPlacementReportRepository, private val domainEventRepository: DomainEventRepository, - private val lostBedsRepository: Cas3LostBedsRepository, + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, private val cas1OutOfServiceBedRepository: Cas1OutOfServiceBedRepository, private val domainEventService: Cas1DomainEventService, private val placementApplicationEntityReportRowRepository: PlacementApplicationEntityReportRowRepository, @@ -108,8 +108,8 @@ class Cas1ReportService( ) } - fun createLostBedReport(properties: LostBedReportProperties, outputStream: OutputStream) { - LostBedsReportGenerator(lostBedsRepository) + fun createLostBedReport(properties: VoidBedspaceReportProperties, outputStream: OutputStream) { + VoidBedspacesReportGenerator(cas3VoidBedspacesRepository) .createReport(bedRepository.findAll(), properties) .writeExcel( outputStream = outputStream, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3BookingService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3BookingService.kt index 9a5ea517c0..49047c1fab 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3BookingService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3BookingService.kt @@ -30,7 +30,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TurnaroundEnt import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TurnaroundRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserQualification -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.serviceScopeMatches import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.PersonInfoResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.validated @@ -60,7 +60,7 @@ class Cas3BookingService( private val moveOnCategoryRepository: MoveOnCategoryRepository, private val cancellationRepository: CancellationRepository, private val cancellationReasonRepository: CancellationReasonRepository, - private val cas3LostBedsRepository: Cas3LostBedsRepository, + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, private val turnaroundRepository: TurnaroundRepository, private val extensionRepository: ExtensionRepository, private val cas3PremisesService: Cas3PremisesService, @@ -545,7 +545,7 @@ class Cas3BookingService( endDate: LocalDate, thisEntityId: UUID?, bedId: UUID, - ) = cas3LostBedsRepository.findByBedIdAndOverlappingDate( + ) = cas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bedId, startDate, endDate, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3LostBedService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3LostBedService.kt deleted file mode 100644 index da063337b1..0000000000 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3LostBedService.kt +++ /dev/null @@ -1,12 +0,0 @@ -package uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3 - -import org.springframework.stereotype.Service -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository -import java.util.UUID - -@Service -class Cas3LostBedService( - private val lostBedsRepository: Cas3LostBedsRepository, -) { - fun getActiveLostBedsForPremisesId(premisesId: UUID) = lostBedsRepository.findAllActiveForPremisesId(premisesId) -} diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3PremisesService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3PremisesService.kt index 68148a1cce..ee826a0a51 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3PremisesService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3PremisesService.kt @@ -14,11 +14,11 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationDeli import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationRegionRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationPremisesEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationPremisesSummary -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedCancellationEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedCancellationRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceCancellationEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceCancellationRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.Availability import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.ValidationErrors import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.validated @@ -33,9 +33,9 @@ import java.util.UUID @Service class Cas3PremisesService( private val premisesRepository: PremisesRepository, - private val cas3LostBedsRepository: Cas3LostBedsRepository, - private val cas3LostBedReasonRepository: Cas3LostBedReasonRepository, - private val cas3LostBedCancellationRepository: Cas3LostBedCancellationRepository, + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, + private val cas3VoidBedspaceReasonRepository: Cas3VoidBedspaceReasonRepository, + private val cas3VoidBedspaceCancellationRepository: Cas3VoidBedspaceCancellationRepository, private val bookingRepository: BookingRepository, private val localAuthorityAreaRepository: LocalAuthorityAreaRepository, private val probationRegionRepository: ProbationRegionRepository, @@ -292,7 +292,7 @@ class Cas3PremisesService( if (endDate.isBefore(startDate)) throw RuntimeException("startDate must be before endDate when calculating availability for range") val bookings = bookingRepository.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) - val voidBedspaces = cas3LostBedsRepository.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) + val voidBedspaces = cas3VoidBedspacesRepository.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) return startDate.getDaysUntilExclusiveEnd(endDate).map { date -> val bookingsOnDay = bookings.filter { booking -> booking.getArrivalDate() <= date && booking.getDepartureDate() > date } @@ -304,7 +304,7 @@ class Cas3PremisesService( arrivedBookings = bookingsOnDay.count { it.getArrived() }, nonArrivedBookings = bookingsOnDay.count { it.getIsNotArrived() }, cancelledBookings = bookingsOnDay.count { it.getCancelled() }, - lostBeds = voidBedspacesOnDay.size, + voidBedspaces = voidBedspacesOnDay.size, ) }.associateBy { it.date } } @@ -317,7 +317,7 @@ class Cas3PremisesService( referenceNumber: String?, notes: String?, bedId: UUID, - ): ValidatableActionResult = + ): ValidatableActionResult = validated { if (endDate.isBefore(startDate)) { "$.endDate" hasValidationError "beforeStartDate" @@ -328,7 +328,7 @@ class Cas3PremisesService( "$.bedId" hasValidationError "doesNotExist" } - val reason = cas3LostBedReasonRepository.findByIdOrNull(reasonId) + val reason = cas3VoidBedspaceReasonRepository.findByIdOrNull(reasonId) if (reason == null) { "$.reason" hasValidationError "doesNotExist" } else if (!serviceScopeMatches(reason.serviceScope)) { @@ -339,8 +339,8 @@ class Cas3PremisesService( return fieldValidationError } - val voidBedspacesEntity = cas3LostBedsRepository.save( - Cas3LostBedsEntity( + val voidBedspacesEntity = cas3VoidBedspacesRepository.save( + Cas3VoidBedspacesEntity( id = UUID.randomUUID(), premises = premises, startDate = startDate, @@ -363,8 +363,8 @@ class Cas3PremisesService( reasonId: UUID, referenceNumber: String?, notes: String?, - ): AuthorisableActionResult> { - val voidBedspace = cas3LostBedsRepository.findByIdOrNull(voidBedspaceId) + ): AuthorisableActionResult> { + val voidBedspace = cas3VoidBedspacesRepository.findByIdOrNull(voidBedspaceId) ?: return AuthorisableActionResult.NotFound() return AuthorisableActionResult.Success( @@ -373,7 +373,7 @@ class Cas3PremisesService( "$.endDate" hasValidationError "beforeStartDate" } - val reason = cas3LostBedReasonRepository.findByIdOrNull(reasonId) + val reason = cas3VoidBedspaceReasonRepository.findByIdOrNull(reasonId) if (reason == null) { "$.reason" hasValidationError "doesNotExist" } else if (!serviceScopeMatches(reason.serviceScope)) { @@ -384,7 +384,7 @@ class Cas3PremisesService( return@validated fieldValidationError } - val updatedVoidBedspacesEntity = cas3LostBedsRepository.save( + val updatedVoidBedspacesEntity = cas3VoidBedspacesRepository.save( voidBedspace.apply { this.startDate = startDate this.endDate = endDate @@ -400,17 +400,17 @@ class Cas3PremisesService( } fun cancelVoidBedspace( - voidBedspace: Cas3LostBedsEntity, + voidBedspace: Cas3VoidBedspacesEntity, notes: String?, - ) = validated { + ) = validated { if (voidBedspace.cancellation != null) { return generalError("This Void Bedspace already has a cancellation set") } - val cancellationEntity = cas3LostBedCancellationRepository.save( - Cas3LostBedCancellationEntity( + val cancellationEntity = cas3VoidBedspaceCancellationRepository.save( + Cas3VoidBedspaceCancellationEntity( id = UUID.randomUUID(), - lostBed = voidBedspace, + voidBedspace = voidBedspace, notes = notes, createdAt = OffsetDateTime.now(), ), diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3ReportService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3ReportService.kt index 29bd806965..753fe74957 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3ReportService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3ReportService.kt @@ -8,7 +8,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.ServiceName import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3BookingGapReportRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3FutureBookingsReportRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.PersonSummaryInfoResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.BedUsageReportGenerator import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.BedUtilisationReportGenerator @@ -46,7 +46,7 @@ class Cas3ReportService( private val userService: UserService, private val transitionalAccommodationReferralReportRowRepository: TransitionalAccommodationReferralReportRepository, private val bookingsReportRepository: BookingsReportRepository, - private val cas3LostBedsRepository: Cas3LostBedsRepository, + private val cas3VoidBedspacesRepository: Cas3VoidBedspacesRepository, private val bookingTransformer: BookingTransformer, private val workingDayService: WorkingDayService, private val bookingRepository: BookingRepository, @@ -119,7 +119,7 @@ class Cas3ReportService( probationRegionId = properties.probationRegionId, ) - BedUsageReportGenerator(bookingTransformer, bookingRepository, cas3LostBedsRepository, workingDayService) + BedUsageReportGenerator(bookingTransformer, bookingRepository, cas3VoidBedspacesRepository, workingDayService) .createReport(bedspacesInScope, properties) .writeExcel( outputStream = outputStream, @@ -151,7 +151,7 @@ class Cas3ReportService( properties.endDate, ) - val lostBedspaceInScope = bedUtilisationReportRepository.findAllLostBedByOverlappingDate( + val voidBedspaceInScope = bedUtilisationReportRepository.findAllVoidBedspaceByOverlappingDate( probationRegionId = properties.probationRegionId, properties.startDate, properties.endDate, @@ -162,13 +162,13 @@ class Cas3ReportService( val bedspaceBookings = bedspaceBookingsInScope.filter { it.bedId == bedId } val bedspaceBookingsCancellation = bedspaceBookingsCancellationInScope.filter { it.bedId == bedId } val bedspaceBookingsTurnaround = bedspaceBookingsTurnaroundInScope.filter { it.bedId == bedId } - val lostBedspace = lostBedspaceInScope.filter { it.bedId == bedId } + val voidBedspace = voidBedspaceInScope.filter { it.bedId == bedId } BedUtilisationReportData( it, bedspaceBookings, bedspaceBookingsCancellation, bedspaceBookingsTurnaround, - lostBedspace, + voidBedspace, ) } diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3VoidBedspaceService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3VoidBedspaceService.kt new file mode 100644 index 0000000000..b7c1f4505b --- /dev/null +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas3/Cas3VoidBedspaceService.kt @@ -0,0 +1,12 @@ +package uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas3 + +import org.springframework.stereotype.Service +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository +import java.util.UUID + +@Service +class Cas3VoidBedspaceService( + private val voidBedspacesRepository: Cas3VoidBedspacesRepository, +) { + fun getActiveVoidBedspacesForPremisesId(premisesId: UUID) = voidBedspacesRepository.findAllActiveForPremisesId(premisesId) +} diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedCancellationTransformer.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspaceCancellationTransformer.kt similarity index 67% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedCancellationTransformer.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspaceCancellationTransformer.kt index 364f55ba0a..24753662de 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedCancellationTransformer.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspaceCancellationTransformer.kt @@ -2,11 +2,11 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3 import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.LostBedCancellation -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedCancellationEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceCancellationEntity @Component -class Cas3LostBedCancellationTransformer { - fun transformJpaToApi(jpa: Cas3LostBedCancellationEntity) = LostBedCancellation( +class Cas3VoidBedspaceCancellationTransformer { + fun transformJpaToApi(jpa: Cas3VoidBedspaceCancellationEntity) = LostBedCancellation( id = jpa.id, createdAt = jpa.createdAt.toInstant(), notes = jpa.notes, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedReasonTransformer.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspaceReasonTransformer.kt similarity index 71% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedReasonTransformer.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspaceReasonTransformer.kt index b95ada7b2f..54fcb2bdda 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedReasonTransformer.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspaceReasonTransformer.kt @@ -2,11 +2,11 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3 import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.LostBedReason -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonEntity @Component -class Cas3LostBedReasonTransformer { - fun transformJpaToApi(jpa: Cas3LostBedReasonEntity) = LostBedReason( +class Cas3VoidBedspaceReasonTransformer { + fun transformJpaToApi(jpa: Cas3VoidBedspaceReasonEntity) = LostBedReason( id = jpa.id, name = jpa.name, isActive = jpa.isActive, diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedsTransformer.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspacesTransformer.kt similarity index 55% rename from src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedsTransformer.kt rename to src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspacesTransformer.kt index 31f99347ea..9a8941a800 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3LostBedsTransformer.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/transformer/cas3/Cas3VoidBedspacesTransformer.kt @@ -3,28 +3,28 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3 import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.LostBed import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.LostBedStatus -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity @Component -class Cas3LostBedsTransformer( - private val cas3LostBedReasonTransformer: Cas3LostBedReasonTransformer, - private val cas3LostBedCancellationTransformer: Cas3LostBedCancellationTransformer, +class Cas3VoidBedspacesTransformer( + private val cas3VoidBedspaceReasonTransformer: Cas3VoidBedspaceReasonTransformer, + private val cas3VoidBedspaceCancellationTransformer: Cas3VoidBedspaceCancellationTransformer, ) { - fun transformJpaToApi(jpa: Cas3LostBedsEntity) = LostBed( + fun transformJpaToApi(jpa: Cas3VoidBedspacesEntity) = LostBed( id = jpa.id, startDate = jpa.startDate, endDate = jpa.endDate, - reason = cas3LostBedReasonTransformer.transformJpaToApi(jpa.reason), + reason = cas3VoidBedspaceReasonTransformer.transformJpaToApi(jpa.reason), referenceNumber = jpa.referenceNumber, notes = jpa.notes, status = determineStatus(jpa), - cancellation = jpa.cancellation?.let { cas3LostBedCancellationTransformer.transformJpaToApi(it) }, + cancellation = jpa.cancellation?.let { cas3VoidBedspaceCancellationTransformer.transformJpaToApi(it) }, bedId = jpa.bed.id, bedName = jpa.bed.name, roomName = jpa.bed.room.name, ) - private fun determineStatus(jpa: Cas3LostBedsEntity) = when { + private fun determineStatus(jpa: Cas3VoidBedspacesEntity) = when { jpa.cancellation != null -> LostBedStatus.cancelled else -> LostBedStatus.active } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedCancellationEntityFactory.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspaceCancellationEntityFactory.kt similarity index 61% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedCancellationEntityFactory.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspaceCancellationEntityFactory.kt index 4f06ae0b2c..02dce79d21 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedCancellationEntityFactory.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspaceCancellationEntityFactory.kt @@ -2,17 +2,17 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3 import io.github.bluegroundltd.kfactory.Factory import io.github.bluegroundltd.kfactory.Yielded -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedCancellationEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceCancellationEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.randomDateTimeBefore import java.time.OffsetDateTime import java.util.UUID -class Cas3LostBedCancellationEntityFactory : Factory { +class Cas3VoidBedspaceCancellationEntityFactory : Factory { private var id: Yielded = { UUID.randomUUID() } private var createdAt: Yielded = { OffsetDateTime.now().randomDateTimeBefore(14) } private var notes: Yielded? = null - private var lostBed: Yielded? = null + private var voidBedspace: Yielded? = null fun withId(id: UUID) = apply { this.id = { id } @@ -26,19 +26,19 @@ class Cas3LostBedCancellationEntityFactory : Factory) = apply { - this.lostBed = lostBed + fun withYieldedVoidBedspace(voidBedspace: Yielded) = apply { + this.voidBedspace = voidBedspace } - fun withLostBed(lostBed: Cas3LostBedsEntity) = apply { - this.lostBed = { lostBed } + fun withVoidBedspace(voidBedspace: Cas3VoidBedspacesEntity) = apply { + this.voidBedspace = { voidBedspace } } @Suppress("TooGenericExceptionThrown") - override fun produce() = Cas3LostBedCancellationEntity( + override fun produce() = Cas3VoidBedspaceCancellationEntity( id = this.id(), createdAt = this.createdAt(), notes = this.notes?.invoke(), - lostBed = this.lostBed?.invoke() ?: throw RuntimeException("Lost Bed must be provided"), + voidBedspace = this.voidBedspace?.invoke() ?: throw RuntimeException("Lost Bed must be provided"), ) } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedReasonEntityFactory.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspaceReasonEntityFactory.kt similarity index 84% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedReasonEntityFactory.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspaceReasonEntityFactory.kt index 134c9f410f..ba906fb58f 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedReasonEntityFactory.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspaceReasonEntityFactory.kt @@ -2,12 +2,12 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3 import io.github.bluegroundltd.kfactory.Factory import io.github.bluegroundltd.kfactory.Yielded -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.randomStringMultiCaseWithNumbers import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.randomStringUpperCase import java.util.UUID -class Cas3LostBedReasonEntityFactory : Factory { +class Cas3VoidBedspaceReasonEntityFactory : Factory { private var id: Yielded = { UUID.randomUUID() } private var name: Yielded = { randomStringMultiCaseWithNumbers(6) } private var isActive: Yielded = { true } @@ -29,7 +29,7 @@ class Cas3LostBedReasonEntityFactory : Factory { this.serviceScope = { serviceScope } } - override fun produce(): Cas3LostBedReasonEntity = Cas3LostBedReasonEntity( + override fun produce(): Cas3VoidBedspaceReasonEntity = Cas3VoidBedspaceReasonEntity( id = this.id(), name = this.name(), isActive = this.isActive(), diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedsEntityFactory.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspacesEntityFactory.kt similarity index 74% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedsEntityFactory.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspacesEntityFactory.kt index e93fb9a7c2..8b400b6332 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3LostBedsEntityFactory.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/factory/cas3/Cas3VoidBedspacesEntityFactory.kt @@ -4,24 +4,24 @@ import io.github.bluegroundltd.kfactory.Factory import io.github.bluegroundltd.kfactory.Yielded import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BedEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.PremisesEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedCancellationEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceCancellationEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.randomDateAfter import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.randomDateBefore import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.randomStringMultiCaseWithNumbers import java.time.LocalDate import java.util.UUID -class Cas3LostBedsEntityFactory : Factory { +class Cas3VoidBedspacesEntityFactory : Factory { private var id: Yielded = { UUID.randomUUID() } private var startDate: Yielded = { LocalDate.now().randomDateBefore(6) } private var endDate: Yielded = { LocalDate.now().randomDateAfter(6) } - private var reason: Yielded? = null + private var reason: Yielded? = null private var referenceNumber: Yielded = { UUID.randomUUID().toString() } private var notes: Yielded = { randomStringMultiCaseWithNumbers(20) } private var premises: Yielded? = null - private var lostBedCancellation: Yielded? = null + private var voidBedspaceCancellation: Yielded? = null private var bed: Yielded? = null fun withId(id: UUID) = apply { @@ -36,7 +36,7 @@ class Cas3LostBedsEntityFactory : Factory { this.endDate = { endDate } } - fun withYieldedReason(reason: Yielded) = apply { + fun withYieldedReason(reason: Yielded) = apply { this.reason = reason } @@ -56,12 +56,12 @@ class Cas3LostBedsEntityFactory : Factory { this.premises = { premises } } - fun withYieldedLostBedCancellation(lostBedCancellation: Yielded) = apply { - this.lostBedCancellation = lostBedCancellation + fun withYieldedVoidBedspaceCancellation(voidBedspaceCancellation: Yielded) = apply { + this.voidBedspaceCancellation = voidBedspaceCancellation } - fun withLostBedCancellation(lostBedCancellation: Cas3LostBedCancellationEntity) = apply { - this.lostBedCancellation = { lostBedCancellation } + fun withVoidBedspaceCancellation(voidBedspaceCancellation: Cas3VoidBedspaceCancellationEntity) = apply { + this.voidBedspaceCancellation = { voidBedspaceCancellation } } fun withBed(bed: BedEntity) = apply { @@ -73,7 +73,7 @@ class Cas3LostBedsEntityFactory : Factory { } @SuppressWarnings("TooGenericExceptionThrown") - override fun produce() = Cas3LostBedsEntity( + override fun produce() = Cas3VoidBedspacesEntity( id = this.id(), startDate = this.startDate(), endDate = this.endDate(), @@ -82,6 +82,6 @@ class Cas3LostBedsEntityFactory : Factory { notes = this.notes(), premises = this.premises?.invoke() ?: throw RuntimeException("Must provide a Premises"), bed = this.bed?.invoke() ?: throw RuntimeException("Must provide a Bed"), - cancellation = this.lostBedCancellation?.invoke(), + cancellation = this.voidBedspaceCancellation?.invoke(), ) } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSearchRepositoryTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSearchRepositoryTest.kt index cbcf0c99e9..2347024227 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSearchRepositoryTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSearchRepositoryTest.kt @@ -153,10 +153,10 @@ class BedSearchRepositoryTest : IntegrationTestBase() { withRoom(roomInPremisesOneInPdu) } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premisesOneInPdu) withBed(bedFiveInRoomInPremisesOneInPdu) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.parse("2023-03-08")) withEndDate(LocalDate.parse("2023-03-10")) } @@ -168,10 +168,10 @@ class BedSearchRepositoryTest : IntegrationTestBase() { withRoom(roomInPremisesOneInPdu) } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premisesOneInPdu) withBed(bedSixInRoomInPremisesOneInPdu) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.parse("2023-03-14")) withEndDate(LocalDate.parse("2023-03-16")) } @@ -183,10 +183,10 @@ class BedSearchRepositoryTest : IntegrationTestBase() { withRoom(roomInPremisesOneInPdu) } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premisesOneInPdu) withBed(bedSevenInRoomInPremisesOneInPdu) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.parse("2023-03-10")) withEndDate(LocalDate.parse("2023-03-12")) } @@ -198,10 +198,10 @@ class BedSearchRepositoryTest : IntegrationTestBase() { withRoom(roomInPremisesOneInPdu) } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premisesOneInPdu) withBed(bedEightInRoomInPremisesOneInPdu) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.parse("2023-03-08")) withEndDate(LocalDate.parse("2023-03-16")) } @@ -253,16 +253,16 @@ class BedSearchRepositoryTest : IntegrationTestBase() { withRoom(roomInPremisesThreeInPdu) } - val cancelledLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val cancelledLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premisesThreeInPdu) withBed(bedWithCancelledLostBed) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.parse("2023-03-08")) withEndDate(LocalDate.parse("2023-03-10")) } - cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(cancelledLostBed) + cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(cancelledLostBed) } bedsThatShouldAppearInSearchResults += bedWithCancelledLostBed @@ -469,16 +469,16 @@ class BedSearchRepositoryTest : IntegrationTestBase() { withRoom(roomInPremisesThreeInPdu) } - val cancelledLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val cancelledLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premisesThreeInPdu) withBed(bedWithCancelledLostBed) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.parse("2024-08-08")) withEndDate(LocalDate.parse("2024-09-10")) } - cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(cancelledLostBed) + cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(cancelledLostBed) } bedsThatShouldAppearInSearchResults += bedWithCancelledLostBed @@ -667,16 +667,16 @@ class BedSearchRepositoryTest : IntegrationTestBase() { withRoom(roomInPremisesThreeInPdu) } - val cancelledLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val cancelledLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premisesThreeInPdu) withBed(bedWithCancelledLostBed) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.parse("2024-08-08")) withEndDate(LocalDate.parse("2024-09-10")) } - cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(cancelledLostBed) + cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(cancelledLostBed) } bedsThatShouldNotAppearInSearchResults += bedWithCancelledLostBed @@ -862,16 +862,16 @@ class BedSearchRepositoryTest : IntegrationTestBase() { withRoom(roomInPremisesThreeInPdu) } - val cancelledLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val cancelledLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premisesThreeInPdu) withBed(bedWithCancelledLostBed) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.parse("2024-08-08")) withEndDate(LocalDate.parse("2024-09-10")) } - cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(cancelledLostBed) + cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(cancelledLostBed) } bedsThatShouldNotAppearInSearchResults += bedWithCancelledLostBed diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSummaryQueryTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSummaryQueryTest.kt index 2f4707c8a2..a3d066ab04 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSummaryQueryTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSummaryQueryTest.kt @@ -96,10 +96,10 @@ class BedSummaryQueryTest : IntegrationTestBase() { withDepartureDate(LocalDate.now().plusDays((20).toLong())) } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bedWithLostBed) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.now().minusDays((7).toLong())) withEndDate(LocalDate.now().plusDays((20).toLong())) } @@ -130,16 +130,16 @@ class BedSummaryQueryTest : IntegrationTestBase() { } } - val cancelledLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val cancelledLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bedWithCancelledLostBed) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.now().minusDays((7).toLong())) withEndDate(LocalDate.now().plusDays((20).toLong())) } - cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(cancelledLostBed) + cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(cancelledLostBed) } val results: List = diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSummaryTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSummaryTest.kt index c8f4a01256..c970474d2c 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSummaryTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BedSummaryTest.kt @@ -81,10 +81,10 @@ class BedSummaryTest : InitialiseDatabasePerClassTestBase() { withDepartureDate(LocalDate.now().plusDays((20).toLong())) } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bedWithLostBed) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withStartDate(LocalDate.now().minusDays((7).toLong())) withEndDate(LocalDate.now().plusDays((20).toLong())) } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BookingTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BookingTest.kt index ae420b74c8..e9b800d659 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BookingTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/BookingTest.kt @@ -1604,7 +1604,7 @@ class BookingTest : IntegrationTestBase() { } @Test - fun `Create Temporary Accommodation Booking returns 409 Conflict when a lost bed for the same bed overlaps`() { + fun `Create Temporary Accommodation Booking returns 409 Conflict when a void bedspace for the same bed overlaps`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -1624,12 +1624,12 @@ class BookingTest : IntegrationTestBase() { } } - val existingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val existingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } govUKBankHolidaysAPIMockSuccessfullCallWithEmptyResponse() @@ -1659,7 +1659,7 @@ class BookingTest : IntegrationTestBase() { } @Test - fun `Create Temporary Accommodation Booking returns 409 Conflict when a lost bed for the same bed overlaps with the turnaround time`() { + fun `Create Temporary Accommodation Booking returns 409 Conflict when a void bedspace for the same bed overlaps with the turnaround time`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -1680,12 +1680,12 @@ class BookingTest : IntegrationTestBase() { } } - val existingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val existingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } govUKBankHolidaysAPIMockSuccessfullCallWithEmptyResponse() @@ -1716,7 +1716,7 @@ class BookingTest : IntegrationTestBase() { } @Test - fun `Create Temporary Accommodation Booking returns OK with correct body when only cancelled lost beds for the same bed overlap`() { + fun `Create Temporary Accommodation Booking returns OK with correct body when only cancelled void bedspaces for the same bed overlap`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -1736,18 +1736,18 @@ class BookingTest : IntegrationTestBase() { } } - val existingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val existingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist() + cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } - existingLostBed.cancellation = cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(existingLostBed) + existingLostBed.cancellation = cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(existingLostBed) withCreatedAt(OffsetDateTime.parse("2022-07-01T12:34:56.789Z")) } @@ -1913,7 +1913,7 @@ class BookingTest : IntegrationTestBase() { } @Test - fun `Create Temporary Accommodation Arrival returns 409 Conflict when a lost bed for the same bed overlaps with the arrival and expected departure dates`() { + fun `Create Temporary Accommodation Arrival returns 409 Conflict when a void bedspace for the same bed overlaps with the arrival and expected departure dates`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -1933,12 +1933,12 @@ class BookingTest : IntegrationTestBase() { } } - val conflictingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val conflictingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } val booking = bookingEntityFactory.produceAndPersist { @@ -3007,7 +3007,7 @@ class BookingTest : IntegrationTestBase() { } @Test - fun `Create CAS3 Extension returns 409 Conflict when a lost bed for the same bed overlaps with the new departure date`() { + fun `Create CAS3 Extension returns 409 Conflict when a void bedspace for the same bed overlaps with the new departure date`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { _, jwt -> givenAnOffender { offenderDetails, _ -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -3027,12 +3027,12 @@ class BookingTest : IntegrationTestBase() { } } - val conflictingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val conflictingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } val booking = bookingEntityFactory.produceAndPersist { @@ -3068,7 +3068,7 @@ class BookingTest : IntegrationTestBase() { } @Test - fun `Create CAS3 Extension returns 409 Conflict when a lost bed for the same bed overlaps with the updated booking's turnaround time`() { + fun `Create CAS3 Extension returns 409 Conflict when a void bedspace for the same bed overlaps with the updated booking's turnaround time`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { _, jwt -> givenAnOffender { offenderDetails, _ -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -3088,12 +3088,12 @@ class BookingTest : IntegrationTestBase() { } } - val conflictingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val conflictingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } val booking = bookingEntityFactory.produceAndPersist { diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/DeletePremisesTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/DeletePremisesTest.kt index fb30a70d9f..80f27eda5f 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/DeletePremisesTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/DeletePremisesTest.kt @@ -41,7 +41,7 @@ class DeletePremisesTest : IntegrationTestBase() { val premisesFromDatabase = temporaryAccommodationPremisesRepository.findByIdOrNull(premises.id) val roomsFromDatabase = rooms.map { roomRepository.findByIdOrNull(it.id) } val bedsFromDatabase = beds.map { bedRepository.findByIdOrNull(it.id) } - val lostBedFromDatabase = lostBedsRepository.findByIdOrNull(lostBed.id) + val lostBedFromDatabase = cas3VoidBedspacesTestRepository.findByIdOrNull(lostBed.id) assertThat(premisesFromDatabase).isNull() roomsFromDatabase.forEach { assertThat(it).isNull() } @@ -76,7 +76,7 @@ class DeletePremisesTest : IntegrationTestBase() { val premisesFromDatabase = temporaryAccommodationPremisesRepository.findByIdOrNull(premises.id) val roomsFromDatabase = rooms.map { roomRepository.findByIdOrNull(it.id) } val bedsFromDatabase = beds.map { bedRepository.findByIdOrNull(it.id) } - val lostBedFromDatabase = lostBedsRepository.findByIdOrNull(lostBed.id) + val lostBedFromDatabase = cas3VoidBedspacesTestRepository.findByIdOrNull(lostBed.id) assertThat(premisesFromDatabase).isNotNull roomsFromDatabase.forEach { assertThat(it).isNotNull } @@ -115,7 +115,7 @@ class DeletePremisesTest : IntegrationTestBase() { val roomsFromDatabase = rooms.map { roomRepository.findByIdOrNull(it.id) } val bedsFromDatabase = beds.map { bedRepository.findByIdOrNull(it.id) } val bookingFromDatabase = bookingRepository.findByIdOrNull(booking.id) - val lostBedFromDatabase = lostBedsRepository.findByIdOrNull(lostBed.id) + val lostBedFromDatabase = cas3VoidBedspacesTestRepository.findByIdOrNull(lostBed.id) assertThat(premisesFromDatabase).isNotNull roomsFromDatabase.forEach { assertThat(it).isNotNull } @@ -130,11 +130,11 @@ class DeletePremisesTest : IntegrationTestBase() { withLocalAuthorityArea(localAuthorityEntityFactory.produceAndPersist()) } - private fun createLostBed(premises: PremisesEntity, bed: BedEntity) = cas3LostBedsEntityFactory.produceAndPersist { + private fun createLostBed(premises: PremisesEntity, bed: BedEntity) = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bed) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist { + cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/DeleteRoomTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/DeleteRoomTest.kt index a0c04c2ffe..f726ad7b9c 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/DeleteRoomTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/DeleteRoomTest.kt @@ -34,7 +34,7 @@ class DeleteRoomTest : IntegrationTestBase() { val roomFromDatabase = roomRepository.findByIdOrNull(room.id) val bedsFromDatabase = beds.map { bedRepository.findByIdOrNull(it.id) } - val lostBedFromDatabase = lostBedsRepository.findByIdOrNull(lostBed.id) + val lostBedFromDatabase = cas3VoidBedspacesTestRepository.findByIdOrNull(lostBed.id) assertThat(roomFromDatabase).isNull() bedsFromDatabase.forEach { assertThat(it).isNull() } @@ -61,7 +61,7 @@ class DeleteRoomTest : IntegrationTestBase() { val roomFromDatabase = roomRepository.findByIdOrNull(room.id) val bedsFromDatabase = beds.map { bedRepository.findByIdOrNull(it.id) } - val lostBedFromDatabase = lostBedsRepository.findByIdOrNull(lostBed.id) + val lostBedFromDatabase = cas3VoidBedspacesTestRepository.findByIdOrNull(lostBed.id) assertThat(roomFromDatabase).isNotNull bedsFromDatabase.forEach { assertThat(it).isNotNull } @@ -92,7 +92,7 @@ class DeleteRoomTest : IntegrationTestBase() { val roomFromDatabase = roomRepository.findByIdOrNull(room.id) val bedsFromDatabase = beds.map { bedRepository.findByIdOrNull(it.id) } val bookingFromDatabase = bookingRepository.findByIdOrNull(booking.id) - val lostBedFromDatabase = lostBedsRepository.findByIdOrNull(lostBed.id) + val lostBedFromDatabase = cas3VoidBedspacesTestRepository.findByIdOrNull(lostBed.id) assertThat(roomFromDatabase).isNotNull bedsFromDatabase.forEach { assertThat(it).isNotNull } @@ -109,11 +109,11 @@ class DeleteRoomTest : IntegrationTestBase() { } } - private fun createLostBed(premises: PremisesEntity, bed: BedEntity) = cas3LostBedsEntityFactory.produceAndPersist { + private fun createLostBed(premises: PremisesEntity, bed: BedEntity) = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bed) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist { + cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/IntegrationTestBase.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/IntegrationTestBase.kt index 7b3d1629c2..5d8e18b635 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/IntegrationTestBase.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/IntegrationTestBase.kt @@ -98,9 +98,9 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.UserEntityFactor import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.UserQualificationAssignmentEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.UserRoleAssignmentEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas1.Cas1CruManagementAreaEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedCancellationEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedReasonEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedsEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceCancellationEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceReasonEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspacesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.integration.asserter.DomainEventAsserter import uk.gov.justice.digital.hmpps.approvedpremisesapi.integration.asserter.EmailNotificationAsserter import uk.gov.justice.digital.hmpps.approvedpremisesapi.integration.config.IntegrationTestDbManager @@ -192,9 +192,9 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TurnaroundEnt import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserQualificationAssignmentEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserRoleAssignmentEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedCancellationEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceCancellationEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.deliuscontext.StaffMember import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.deliuscontext.StaffMembersPage import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.hmppsauth.GetTokenResponse @@ -224,6 +224,9 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.Cas1OutOfServ import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.Cas2ApplicationJsonSchemaTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.Cas2ApplicationTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.Cas2StatusUpdateTestRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.Cas3VoidBedspaceCancellationTestRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.Cas3VoidBedspaceReasonTestRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.Cas3VoidBedspacesTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.ConfirmationTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.DepartureReasonTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.DepartureTestRepository @@ -232,9 +235,6 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.DomainEventTe import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.ExtensionTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.ExternalUserTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.LocalAuthorityAreaTestRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.LostBedCancellationTestRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.LostBedReasonTestRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.LostBedsTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.MoveOnCategoryTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.NomisUserTestRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.NonArrivalReasonTestRepository @@ -355,13 +355,13 @@ abstract class IntegrationTestBase { lateinit var cancellationReasonRepository: CancellationReasonTestRepository @Autowired - lateinit var lostBedReasonRepository: LostBedReasonTestRepository + lateinit var cas3VoidBedspaceReasonTestRepository: Cas3VoidBedspaceReasonTestRepository @Autowired - lateinit var lostBedsRepository: LostBedsTestRepository + lateinit var cas3VoidBedspacesTestRepository: Cas3VoidBedspacesTestRepository @Autowired - lateinit var lostBedCancellationRepository: LostBedCancellationTestRepository + lateinit var cas3VoidBedspaceCancellationTestRepository: Cas3VoidBedspaceCancellationTestRepository @Autowired lateinit var extensionRepository: ExtensionTestRepository @@ -558,9 +558,9 @@ abstract class IntegrationTestBase { lateinit var nonArrivalEntityFactory: PersistedFactory lateinit var cancellationEntityFactory: PersistedFactory lateinit var cancellationReasonEntityFactory: PersistedFactory - lateinit var cas3LostBedsEntityFactory: PersistedFactory - lateinit var cas3LostBedReasonEntityFactory: PersistedFactory - lateinit var cas3LostBedCancellationEntityFactory: PersistedFactory + lateinit var cas3VoidBedspacesEntityFactory: PersistedFactory + lateinit var cas3VoidBedspaceReasonEntityFactory: PersistedFactory + lateinit var cas3VoidBedspaceCancellationEntityFactory: PersistedFactory lateinit var extensionEntityFactory: PersistedFactory lateinit var dateChangeEntityFactory: PersistedFactory lateinit var nonArrivalReasonEntityFactory: PersistedFactory @@ -669,9 +669,9 @@ abstract class IntegrationTestBase { nonArrivalEntityFactory = PersistedFactory({ NonArrivalEntityFactory() }, nonArrivalRepository) cancellationEntityFactory = PersistedFactory({ CancellationEntityFactory() }, cancellationRepository) cancellationReasonEntityFactory = PersistedFactory({ CancellationReasonEntityFactory() }, cancellationReasonRepository) - cas3LostBedsEntityFactory = PersistedFactory({ Cas3LostBedsEntityFactory() }, lostBedsRepository) - cas3LostBedReasonEntityFactory = PersistedFactory({ Cas3LostBedReasonEntityFactory() }, lostBedReasonRepository) - cas3LostBedCancellationEntityFactory = PersistedFactory({ Cas3LostBedCancellationEntityFactory() }, lostBedCancellationRepository) + cas3VoidBedspacesEntityFactory = PersistedFactory({ Cas3VoidBedspacesEntityFactory() }, cas3VoidBedspacesTestRepository) + cas3VoidBedspaceReasonEntityFactory = PersistedFactory({ Cas3VoidBedspaceReasonEntityFactory() }, cas3VoidBedspaceReasonTestRepository) + cas3VoidBedspaceCancellationEntityFactory = PersistedFactory({ Cas3VoidBedspaceCancellationEntityFactory() }, cas3VoidBedspaceCancellationTestRepository) extensionEntityFactory = PersistedFactory({ ExtensionEntityFactory() }, extensionRepository) dateChangeEntityFactory = PersistedFactory({ DateChangeEntityFactory() }, dateChangeRepository) nonArrivalReasonEntityFactory = PersistedFactory({ NonArrivalReasonEntityFactory() }, nonArrivalReasonRepository) diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/PremisesTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/PremisesTest.kt index 1f19237530..9727655cc5 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/PremisesTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/PremisesTest.kt @@ -43,7 +43,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.RoomEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationPremisesEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserRole -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.deliuscontext.StaffMembersPage import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.BookingTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.PremisesTransformer @@ -1908,7 +1908,7 @@ class PremisesTest { lateinit var bookingTransformer: BookingTransformer private lateinit var premises: ApprovedPremisesEntity - private lateinit var lostBeds: List + private lateinit var voidBedspaces: List private lateinit var rooms: List private lateinit var bookings: List @@ -1932,36 +1932,36 @@ class PremisesTest { withStaffKeyWorkerCode(null) } - lostBeds = mutableListOf( - cas3LostBedsEntityFactory.produceAndPersist { + voidBedspaces = mutableListOf( + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withStartDate(startDate.plusDays(1)) withEndDate(startDate.plusDays(2)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withBed(rooms[0].beds[0]) }, - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withStartDate(startDate.plusDays(1)) withEndDate(startDate.plusDays(2)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withBed(rooms[1].beds[0]) }, ) - val cancelledLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val cancelledLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withStartDate(startDate.plusDays(1)) withEndDate(startDate.plusDays(2)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withBed(rooms[2].beds[0]) } - cancelledLostBed.cancellation = cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(cancelledLostBed) + cancelledLostBed.cancellation = cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(cancelledLostBed) } - lostBeds += cancelledLostBed + voidBedspaces += cancelledLostBed val arrivedBookingEntity = bookingEntityFactory.produceAndPersist { withPremises(premises) @@ -2135,11 +2135,11 @@ class PremisesTest { ) val getTotalBedsForDate = { date: LocalDate -> - val lostBedsForToday = lostBeds.filter { it.startDate <= date && it.endDate > date && it.cancellation == null } + val voidBedspacesForToday = voidBedspaces.filter { it.startDate <= date && it.endDate > date && it.cancellation == null } val bookingsForToday = bookings .filter { it.cancellation == null && it.nonArrival == null } .filter { it.arrivalDate <= date && it.departureDate > date } - (totalBeds - bookingsForToday.count()) - lostBedsForToday.count() + (totalBeds - bookingsForToday.count()) - voidBedspacesForToday.count() } assertThat(responseBody.dateCapacities?.get(0)).isEqualTo( diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/ReferenceDataTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/ReferenceDataTest.kt index 70cfab0fb2..9dbb9d69b0 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/ReferenceDataTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/ReferenceDataTest.kt @@ -22,7 +22,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ProbationDel import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ProbationRegionTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.ReferralRejectionReasonTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.StaffMemberTransformer -import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedReasonTransformer +import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspaceReasonTransformer import java.util.UUID class ReferenceDataTest : IntegrationTestBase() { @@ -30,7 +30,7 @@ class ReferenceDataTest : IntegrationTestBase() { lateinit var departureReasonTransformer: DepartureReasonTransformer @Autowired - lateinit var cas3LostBedReasonTransformer: Cas3LostBedReasonTransformer + lateinit var cas3VoidBedspaceReasonTransformer: Cas3VoidBedspaceReasonTransformer @Autowired lateinit var moveOnCategoryTransformer: MoveOnCategoryTransformer @@ -688,16 +688,16 @@ class ReferenceDataTest : IntegrationTestBase() { } @Test - fun `Get Lost Bed Reasons for only Temporary Accommodation returns 200 with correct body`() { - lostBedReasonRepository.deleteAll() + fun `Get Void Bedspace Reasons for only Temporary Accommodation returns 200 with correct body`() { + cas3VoidBedspaceReasonTestRepository.deleteAll() - cas3LostBedReasonEntityFactory.produceAndPersistMultiple(10) + cas3VoidBedspaceReasonEntityFactory.produceAndPersistMultiple(10) - val expectedLostBedReasons = cas3LostBedReasonEntityFactory.produceAndPersistMultiple(10) { + val expectedLostBedReasons = cas3VoidBedspaceReasonEntityFactory.produceAndPersistMultiple(10) { withServiceScope(ServiceName.temporaryAccommodation.value) } val expectedJson = objectMapper.writeValueAsString( - expectedLostBedReasons.map(cas3LostBedReasonTransformer::transformJpaToApi), + expectedLostBedReasons.map(cas3VoidBedspaceReasonTransformer::transformJpaToApi), ) val jwt = jwtAuthHelper.createValidAuthorizationCodeJwt() diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/ReportsTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/ReportsTest.kt index 8b27ee6663..99a7696d9f 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/ReportsTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/ReportsTest.kt @@ -24,18 +24,18 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationApplicationEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserRole -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.community.OffenderDetailSummary import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.BookingsReportGenerator -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.LostBedsReportGenerator +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.VoidBedspacesReportGenerator import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUsageReportRow import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUsageType import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUtilisationReportRow import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BookingsReportRow -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.LostBedReportRow import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.PersonInformationReportData +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.VoidBedspaceReportRow import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.BookingsReportProperties -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.LostBedReportProperties +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.VoidBedspaceReportProperties import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.util.toShortBase58 import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.BookingTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.randomDateBefore @@ -50,7 +50,7 @@ class ReportsTest : IntegrationTestBase() { lateinit var bookingTransformer: BookingTransformer @Autowired - lateinit var realLostBedsRepository: Cas3LostBedsRepository + lateinit var realLostBedsRepository: Cas3VoidBedspacesRepository @Nested inner class GetBookingReport { @@ -1275,11 +1275,11 @@ class ReportsTest : IntegrationTestBase() { } @Nested - inner class GetLostBedsReport { - private val lostBedsEndpoint = "/cas1/reports/${Cas1ReportName.lostBeds.value}" + inner class GetVoidBedspacesReport { + private val voidBedspacesEndpoint = "/cas1/reports/${Cas1ReportName.lostBeds.value}" @Test - fun `Get lost beds report returns OK with correct body`() { + fun `Get void bedspaces report returns OK with correct body`() { givenAUser(roles = listOf(UserRole.CAS1_REPORT_VIEWER)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = approvedPremisesEntityFactory.produceAndPersist { @@ -1311,48 +1311,48 @@ class ReportsTest : IntegrationTestBase() { ) } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bed1) withStartDate(LocalDate.of(2023, 4, 5)) withEndDate(LocalDate.of(2023, 7, 8)) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist() + cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bed2) withStartDate(LocalDate.of(2023, 4, 12)) withEndDate(LocalDate.of(2023, 7, 5)) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist() + cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } - val lostBed3 = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspace3 = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bed3) withStartDate(LocalDate.of(2023, 4, 1)) withEndDate(LocalDate.of(2023, 7, 5)) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist() + cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } - cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(lostBed3) + cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(voidBedspace3) } - val expectedDataFrame = LostBedsReportGenerator(realLostBedsRepository) + val expectedDataFrame = VoidBedspacesReportGenerator(realLostBedsRepository) .createReport( listOf(bed1, bed2), - LostBedReportProperties(ServiceName.approvedPremises, null, 2023, 4), + VoidBedspaceReportProperties(ServiceName.approvedPremises, null, 2023, 4), ) webTestClient.get() - .uri("$lostBedsEndpoint?year=2023&month=4") + .uri("$voidBedspacesEndpoint?year=2023&month=4") .header("Authorization", "Bearer $jwt") .header("X-Service-Name", ServiceName.approvedPremises.value) .exchange() @@ -1362,7 +1362,7 @@ class ReportsTest : IntegrationTestBase() { .consumeWith { val actual = DataFrame .readExcel(it.responseBody!!.inputStream()) - .convertTo(ExcessiveColumns.Remove) + .convertTo(ExcessiveColumns.Remove) Assertions.assertThat(actual).isEqualTo(expectedDataFrame) } } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/TurnaroundTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/TurnaroundTest.kt index 634cd15d44..de45b45285 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/TurnaroundTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/TurnaroundTest.kt @@ -174,13 +174,13 @@ class TurnaroundTest : InitialiseDatabasePerClassTestBase() { withDepartureDate(LocalDate.of(2023, 5, 3)) } - val conflictingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val conflictingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withPremises(premises) withBed(bed) withStartDate(LocalDate.of(2023, 5, 5)) withEndDate(LocalDate.of(2023, 5, 19)) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist() + cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/LostBedsTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/VoidBedspacesTest.kt similarity index 80% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/LostBedsTest.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/VoidBedspacesTest.kt index cd188c3363..cd4ca657fc 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/LostBedsTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/VoidBedspacesTest.kt @@ -13,15 +13,16 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.integration.givens.given import uk.gov.justice.digital.hmpps.approvedpremisesapi.integration.httpmocks.govUKBankHolidaysAPIMockSuccessfullCallWithEmptyResponse import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationRegionEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserRole -import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedsTransformer +import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspacesTransformer import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.util.withinSeconds import java.time.LocalDate import java.time.OffsetDateTime import java.util.UUID -class LostBedsTest : IntegrationTestBase() { +@SuppressWarnings("LargeClass") +class VoidBedspacesTest : IntegrationTestBase() { @Autowired - lateinit var cas3LostBedsTransformer: Cas3LostBedsTransformer + lateinit var cas3VoidBedspacesTransformer: Cas3VoidBedspacesTransformer lateinit var probationRegion: ProbationRegionEntity @@ -31,7 +32,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `List Lost Beds without JWT returns 401`() { + fun `List Void Bedspaces without JWT returns 401`() { val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } @@ -45,7 +46,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `List Lost Beds on non existent Premises returns 404`() { + fun `List Void Bedspaces on non existent Premises returns 404`() { val jwt = jwtAuthHelper.createValidAuthorizationCodeJwt() webTestClient.get() @@ -57,17 +58,17 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `List Lost Beds on Temporary Accommodation premises returns OK with correct body`() { + fun `List Void Bedspaces on Temporary Accommodation premises returns OK with correct body`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withBed( bedEntityFactory.produceAndPersist { withYieldedRoom { @@ -80,7 +81,7 @@ class LostBedsTest : IntegrationTestBase() { withPremises(premises) } - val expectedJson = objectMapper.writeValueAsString(listOf(cas3LostBedsTransformer.transformJpaToApi(lostBeds))) + val expectedJson = objectMapper.writeValueAsString(listOf(cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspaces))) webTestClient.get() .uri("/premises/${premises.id}/lost-beds") @@ -94,7 +95,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `List Lost Beds on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { + fun `List Void Bedspaces on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { givenAUser { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -109,10 +110,10 @@ class LostBedsTest : IntegrationTestBase() { } } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } @@ -128,16 +129,16 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Get Lost Bed without JWT returns 401`() { + fun `Get Void Bedspace without JWT returns 401`() { val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withBed( bedEntityFactory.produceAndPersist { withYieldedRoom { @@ -151,14 +152,14 @@ class LostBedsTest : IntegrationTestBase() { } webTestClient.get() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .exchange() .expectStatus() .isUnauthorized } @Test - fun `Get Lost Bed for non-existent premises returns 404`() { + fun `Get Void Bedspace for non-existent premises returns 404`() { val jwt = jwtAuthHelper.createValidAuthorizationCodeJwt() webTestClient.get() @@ -170,7 +171,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Get Lost Bed for non-existent lost bed returns 404`() { + fun `Get Void Bedspace for non-existent void bedspace returns 404`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -187,7 +188,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Get Lost Bed on Temporary Accommodation premises returns OK with correct body`() { + fun `Get Void Bedspace on Temporary Accommodation premises returns OK with correct body`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -202,18 +203,18 @@ class LostBedsTest : IntegrationTestBase() { } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val expectedJson = objectMapper.writeValueAsString(cas3LostBedsTransformer.transformJpaToApi(lostBeds)) + val expectedJson = objectMapper.writeValueAsString(cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspaces)) webTestClient.get() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .header("Authorization", "Bearer $jwt") .exchange() .expectStatus() @@ -224,7 +225,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Get Lost Bed on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { + fun `Get Void Bedspace on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { givenAUser { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -239,18 +240,18 @@ class LostBedsTest : IntegrationTestBase() { } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val expectedJson = objectMapper.writeValueAsString(cas3LostBedsTransformer.transformJpaToApi(lostBeds)) + val expectedJson = objectMapper.writeValueAsString(cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspaces)) webTestClient.get() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .header("Authorization", "Bearer $jwt") .header("X-Service-Name", ServiceName.temporaryAccommodation.value) .exchange() @@ -260,7 +261,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Create Lost Beds without JWT returns 401`() { + fun `Create Void Bedspaces without JWT returns 401`() { val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } @@ -288,14 +289,14 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Create Lost Beds on Temporary Accommodation premises returns 400 Bad Request if the bed ID does not reference a bed on the premises`() { + fun `Create Void Bedspaces on Temporary Accommodation premises returns 400 Bad Request if the bed ID does not reference a bed on the premises`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } @@ -322,7 +323,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Create Lost Beds on Temporary Accommodation premises returns OK with correct body when correct data is provided`() { + fun `Create Void Bedspaces on Temporary Accommodation premises returns OK with correct body when correct data is provided`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -339,7 +340,7 @@ class LostBedsTest : IntegrationTestBase() { } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } @@ -374,7 +375,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Create Lost Beds on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { + fun `Create Void Bedspaces on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { givenAUser { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -391,7 +392,7 @@ class LostBedsTest : IntegrationTestBase() { } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } @@ -416,16 +417,16 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Bed without JWT returns 401`() { + fun `Update Void Bedspace without JWT returns 401`() { val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withBed( bedEntityFactory.produceAndPersist { withYieldedRoom { @@ -447,7 +448,7 @@ class LostBedsTest : IntegrationTestBase() { } webTestClient.put() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .bodyValue( UpdateLostBed( startDate = LocalDate.parse("2022-08-15"), @@ -463,7 +464,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Bed for non-existent premises returns 404`() { + fun `Update Void Bedspace for non-existent premises returns 404`() { val jwt = jwtAuthHelper.createValidAuthorizationCodeJwt() webTestClient.put() @@ -484,7 +485,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Bed for non-existent lost bed returns 404`() { + fun `Update Void Bedspace for non-existent void bedspace returns 404`() { val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } @@ -510,7 +511,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Beds on Temporary Accommodation premises returns OK with correct body when correct data is provided`() { + fun `Update Void Bedspaces on Temporary Accommodation premises returns OK with correct body when correct data is provided`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -525,20 +526,20 @@ class LostBedsTest : IntegrationTestBase() { } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } webTestClient.put() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .header("Authorization", "Bearer $jwt") .bodyValue( UpdateLostBed( @@ -567,7 +568,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Beds on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { + fun `Update Void Bedspaces on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { givenAUser { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -582,20 +583,20 @@ class LostBedsTest : IntegrationTestBase() { } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } webTestClient.put() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .header("Authorization", "Bearer $jwt") .header("X-Service-Name", ServiceName.temporaryAccommodation.value) .bodyValue( @@ -614,16 +615,16 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Cancel Lost Bed without JWT returns 401`() { + fun `Cancel Void Bedspace without JWT returns 401`() { val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withBed( bedEntityFactory.produceAndPersist { withYieldedRoom { @@ -637,7 +638,7 @@ class LostBedsTest : IntegrationTestBase() { } webTestClient.post() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}/cancellations") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}/cancellations") .bodyValue( NewLostBedCancellation( notes = "Unauthorized", @@ -649,7 +650,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Cancel Lost Bed for non-existent premises returns 404`() { + fun `Cancel Void Bedspace for non-existent premises returns 404`() { val jwt = jwtAuthHelper.createValidAuthorizationCodeJwt() webTestClient.post() @@ -666,7 +667,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Cancel Lost Bed for non-existent lost bed returns 404`() { + fun `Cancel Void Bedspace for non-existent void bedspace returns 404`() { val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } withYieldedProbationRegion { probationRegion } @@ -688,7 +689,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Cancel Lost Bed on Temporary Accommodation premises returns OK with correct body when correct data is provided`() { + fun `Cancel Void Bedspace on Temporary Accommodation premises returns OK with correct body when correct data is provided`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -703,20 +704,20 @@ class LostBedsTest : IntegrationTestBase() { } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } webTestClient.post() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}/cancellations") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}/cancellations") .header("Authorization", "Bearer $jwt") .bodyValue( NewLostBedCancellation( @@ -733,7 +734,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Cancel Lost Bed on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { + fun `Cancel Void Bedspace on Temporary Accommodation premises that's not in the user's region returns 403 Forbidden`() { givenAUser { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -748,20 +749,20 @@ class LostBedsTest : IntegrationTestBase() { } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.now().plusDays(2)) withEndDate(LocalDate.now().plusDays(4)) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } webTestClient.post() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}/cancellations") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}/cancellations") .header("Authorization", "Bearer $jwt") .header("X-Service-Name", ServiceName.temporaryAccommodation.value) .bodyValue( @@ -776,7 +777,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Create Lost Bed on a Temporary Accommodation premises returns 409 Conflict when a booking for the same bed overlaps`() { + fun `Create Void Bedspace on a Temporary Accommodation premises returns 409 Conflict when a booking for the same bed overlaps`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -792,7 +793,7 @@ class LostBedsTest : IntegrationTestBase() { } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } @@ -832,7 +833,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Create Lost Bed on a Temporary Accommodation premises returns OK with correct body when only cancelled bookings for the same bed overlap`() { + fun `Create Void Bedspace on a Temporary Accommodation premises returns OK with correct body when only cancelled bookings for the same bed overlap`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -848,7 +849,7 @@ class LostBedsTest : IntegrationTestBase() { } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } @@ -899,7 +900,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Create Lost Bed on a Temporary Accommodation premises returns 409 Conflict when a lost bed for the same bed overlaps`() { + fun `Create Void Bedspace on a Temporary Accommodation premises returns 409 Conflict when a void bedspace for the same bed overlaps`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -915,16 +916,16 @@ class LostBedsTest : IntegrationTestBase() { } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } - val existingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val existingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } webTestClient.post() @@ -952,7 +953,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Create Lost Bed on a Temporary Accommodation premises returns OK with correct body when only cancelled lost beds for the same bed overlap`() { + fun `Create Void Bedspace on a Temporary Accommodation premises returns OK with correct body when only cancelled void bedspaces for the same bed overlap`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -968,22 +969,22 @@ class LostBedsTest : IntegrationTestBase() { } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } - val existingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val existingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist() + cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } - existingLostBed.cancellation = cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(existingLostBed) + existingLostBed.cancellation = cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(existingLostBed) withCreatedAt(OffsetDateTime.parse("2022-07-01T12:34:56.789Z")) } @@ -1019,7 +1020,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Beds on Temporary Accommodation premises returns 409 Conflict when a booking for the same bed overlaps`() { + fun `Update Void Bedspaces on Temporary Accommodation premises returns 409 Conflict when a booking for the same bed overlaps`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { withYieldedLocalAuthorityArea { localAuthorityEntityFactory.produceAndPersist() } @@ -1034,15 +1035,15 @@ class LostBedsTest : IntegrationTestBase() { } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.parse("2022-08-16")) withEndDate(LocalDate.parse("2022-08-30")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } @@ -1058,7 +1059,7 @@ class LostBedsTest : IntegrationTestBase() { govUKBankHolidaysAPIMockSuccessfullCallWithEmptyResponse() webTestClient.put() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .header("Authorization", "Bearer $jwt") .bodyValue( UpdateLostBed( @@ -1080,7 +1081,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Beds on Temporary Accommodation premises returns OK with correct body when only cancelled bookings for the same bed overlap`() { + fun `Update Void Bedspaces on Temporary Accommodation premises returns OK with correct body when only cancelled bookings for the same bed overlap`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -1096,15 +1097,15 @@ class LostBedsTest : IntegrationTestBase() { } } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.parse("2022-08-16")) withEndDate(LocalDate.parse("2022-08-30")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } @@ -1124,7 +1125,7 @@ class LostBedsTest : IntegrationTestBase() { }.toMutableList() webTestClient.put() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .header("Authorization", "Bearer $jwt") .bodyValue( UpdateLostBed( @@ -1154,7 +1155,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Beds on Temporary Accommodation premises returns 409 Conflict when a lost bed for the same bed overlaps`() { + fun `Update Void Bedspaces on Temporary Accommodation premises returns 409 Conflict when a void bedspace for the same bed overlaps`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -1170,28 +1171,28 @@ class LostBedsTest : IntegrationTestBase() { } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.parse("2022-08-16")) withEndDate(LocalDate.parse("2022-08-30")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val existingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val existingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } webTestClient.put() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .header("Authorization", "Bearer $jwt") .bodyValue( UpdateLostBed( @@ -1214,7 +1215,7 @@ class LostBedsTest : IntegrationTestBase() { } @Test - fun `Update Lost Beds on Temporary Accommodation premises returns OK with correct body when only cancelled lost beds for the same bed overlap`() { + fun `Update Void Bedspaces on Temporary Accommodation premises returns OK with correct body when only cancelled void bedspaces for the same bed overlap`() { givenAUser(roles = listOf(UserRole.CAS3_ASSESSOR)) { userEntity, jwt -> givenAnOffender { offenderDetails, inmateDetails -> val premises = temporaryAccommodationPremisesEntityFactory.produceAndPersist { @@ -1230,35 +1231,35 @@ class LostBedsTest : IntegrationTestBase() { } } - val reason = cas3LostBedReasonEntityFactory.produceAndPersist { + val reason = cas3VoidBedspaceReasonEntityFactory.produceAndPersist { withServiceScope(ServiceName.temporaryAccommodation.value) } - val lostBeds = cas3LostBedsEntityFactory.produceAndPersist { + val voidBedspaces = cas3VoidBedspacesEntityFactory.produceAndPersist { withStartDate(LocalDate.parse("2022-08-16")) withEndDate(LocalDate.parse("2022-08-30")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } withYieldedBed { bed } withPremises(premises) } - val existingLostBed = cas3LostBedsEntityFactory.produceAndPersist { + val existingLostBed = cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2022-07-15")) withEndDate(LocalDate.parse("2022-08-15")) withYieldedReason { - cas3LostBedReasonEntityFactory.produceAndPersist() + cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } - existingLostBed.cancellation = cas3LostBedCancellationEntityFactory.produceAndPersist { - withLostBed(existingLostBed) + existingLostBed.cancellation = cas3VoidBedspaceCancellationEntityFactory.produceAndPersist { + withVoidBedspace(existingLostBed) withCreatedAt(OffsetDateTime.parse("2022-07-01T12:34:56.789Z")) } webTestClient.put() - .uri("/premises/${premises.id}/lost-beds/${lostBeds.id}") + .uri("/premises/${premises.id}/lost-beds/${voidBedspaces.id}") .header("Authorization", "Bearer $jwt") .bodyValue( UpdateLostBed( diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/SeedCas1PremisesFromSiteSurveyXlsxTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/SeedCas1PremisesFromSiteSurveyXlsxTest.kt index 5273a0cabf..9db674fe68 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/SeedCas1PremisesFromSiteSurveyXlsxTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas1/seed/SeedCas1PremisesFromSiteSurveyXlsxTest.kt @@ -85,7 +85,7 @@ class SeedCas1PremisesFromSiteSurveyXlsxTest : SeedTestBase() { assertThat(createdPremise.probationRegion.name).isEqualTo("Yorkshire & The Humber") assertThat(createdPremise.localAuthorityArea?.name).isEqualTo("Bournemouth, Christchurch and Poole") assertThat(createdPremise.bookings).isEmpty() - assertThat(createdPremise.lostBeds).isEmpty() + assertThat(createdPremise.voidBedspaces).isEmpty() assertThat(createdPremise.rooms).isEmpty() assertThat(createdPremise.status).isEqualTo(PropertyStatus.active) assertThat(createdPremise.gender).isEqualTo(ApprovedPremisesGender.MAN) @@ -179,7 +179,7 @@ class SeedCas1PremisesFromSiteSurveyXlsxTest : SeedTestBase() { assertThat(createdPremise.probationRegion.name).isEqualTo("North West") assertThat(createdPremise.localAuthorityArea?.name).isEqualTo("Bristol, City of") assertThat(createdPremise.bookings).isEmpty() - assertThat(createdPremise.lostBeds).isEmpty() + assertThat(createdPremise.voidBedspaces).isEmpty() assertThat(createdPremise.rooms).isEmpty() assertThat(createdPremise.status).isEqualTo(PropertyStatus.active) assertThat(createdPremise.gender).isEqualTo(ApprovedPremisesGender.WOMAN) @@ -290,7 +290,7 @@ class SeedCas1PremisesFromSiteSurveyXlsxTest : SeedTestBase() { assertThat(createdPremise.probationRegion.name).isEqualTo("Yorkshire & The Humber") assertThat(createdPremise.localAuthorityArea?.name).isEqualTo("Windsor and Maidenhead") assertThat(createdPremise.bookings).hasSize(1) - assertThat(createdPremise.lostBeds).isEmpty() + assertThat(createdPremise.voidBedspaces).isEmpty() assertThat(createdPremise.rooms).hasSize(1) assertThat(createdPremise.status).isEqualTo(PropertyStatus.pending) assertThat(createdPremise.gender).isEqualTo(ApprovedPremisesGender.MAN) diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas3/Cas3ReportsTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas3/Cas3ReportsTest.kt index 2af260e9ba..1249823b8b 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas3/Cas3ReportsTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/integration/cas3/Cas3ReportsTest.kt @@ -2280,12 +2280,12 @@ class Cas3ReportsTest : IntegrationTestBase() { bed.apply { createdAt = OffsetDateTime.parse("2023-02-16T14:03:00+00:00") } bedRepository.save(bed) - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2023-04-28")) withEndDate(LocalDate.parse("2023-05-04")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } govUKBankHolidaysAPIMockSuccessfullCallWithEmptyResponse() @@ -2913,20 +2913,20 @@ class Cas3ReportsTest : IntegrationTestBase() { govUKBankHolidaysAPIMockSuccessfullCallWithEmptyResponse() - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2023-03-28")) withEndDate(LocalDate.parse("2023-04-04")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } - cas3LostBedsEntityFactory.produceAndPersist { + cas3VoidBedspacesEntityFactory.produceAndPersist { withBed(bed) withPremises(premises) withStartDate(LocalDate.parse("2023-04-25")) withEndDate(LocalDate.parse("2023-05-03")) - withYieldedReason { cas3LostBedReasonEntityFactory.produceAndPersist() } + withYieldedReason { cas3VoidBedspaceReasonEntityFactory.produceAndPersist() } } val expectedReportRows = listOf( diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedReasonTestRepository.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspaceCancellationTestRepository.kt similarity index 64% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedReasonTestRepository.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspaceCancellationTestRepository.kt index 765b6e4444..72b3a9d2a2 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedReasonTestRepository.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspaceCancellationTestRepository.kt @@ -2,8 +2,8 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.repository import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceCancellationEntity import java.util.UUID @Repository -interface LostBedReasonTestRepository : JpaRepository +interface Cas3VoidBedspaceCancellationTestRepository : JpaRepository diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedCancellationTestRepository.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspaceReasonTestRepository.kt similarity index 67% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedCancellationTestRepository.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspaceReasonTestRepository.kt index ccdd2aed81..8302a9df20 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedCancellationTestRepository.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspaceReasonTestRepository.kt @@ -2,8 +2,8 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.repository import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedCancellationEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonEntity import java.util.UUID @Repository -interface LostBedCancellationTestRepository : JpaRepository +interface Cas3VoidBedspaceReasonTestRepository : JpaRepository diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedsTestRepository.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspacesTestRepository.kt similarity index 69% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedsTestRepository.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspacesTestRepository.kt index 904d6451b4..d196ec36a1 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/LostBedsTestRepository.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/repository/Cas3VoidBedspacesTestRepository.kt @@ -2,8 +2,8 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.repository import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity import java.util.UUID @Repository -interface LostBedsTestRepository : JpaRepository +interface Cas3VoidBedspacesTestRepository : JpaRepository diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/BedUsageReportGeneratorTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/BedUsageReportGeneratorTest.kt index 773975a719..4df464b822 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/BedUsageReportGeneratorTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/BedUsageReportGeneratorTest.kt @@ -18,11 +18,11 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationRegionE import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.RoomEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.TemporaryAccommodationPremisesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.TurnaroundEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedReasonEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedsEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceReasonEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspacesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BedEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.BedUsageReportGenerator import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUsageReportRow import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUsageType @@ -35,7 +35,7 @@ import java.time.LocalDate class BedUsageReportGeneratorTest { private val mockBookingTransformer = mockk() private val mockBookingRepository = mockk() - private val mockLostBedsRepository = mockk() + private val mockLostBedsRepository = mockk() private val mockWorkingDayService = mockk() private val bedUsageReportGenerator = BedUsageReportGenerator( @@ -61,11 +61,11 @@ class BedUsageReportGeneratorTest { .withRoom(temporaryAccommodationRoom) .produce() - val temporaryAccommodationLostBed = Cas3LostBedsEntityFactory() + val temporaryAccommodationLostBed = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises) .produce() @@ -81,11 +81,11 @@ class BedUsageReportGeneratorTest { .withRoom(approvedPremisesRoom) .produce() - val approvedPremisesLostBed = Cas3LostBedsEntityFactory() + val approvedPremisesLostBed = Cas3VoidBedspacesEntityFactory() .withBed(approvedPremisesBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(approvedPremises) .produce() @@ -120,11 +120,11 @@ class BedUsageReportGeneratorTest { .withRoom(temporaryAccommodationRoom) .produce() - val temporaryAccommodationLostBed = Cas3LostBedsEntityFactory() + val temporaryAccommodationLostBed = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises) .produce() @@ -140,11 +140,11 @@ class BedUsageReportGeneratorTest { .withRoom(approvedPremisesRoom) .produce() - val approvedPremisesLostBed = Cas3LostBedsEntityFactory() + val approvedPremisesLostBed = Cas3VoidBedspacesEntityFactory() .withBed(approvedPremisesBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(approvedPremises) .produce() @@ -214,11 +214,11 @@ class BedUsageReportGeneratorTest { .withRoom(temporaryAccommodationRoom) .produce() - val temporaryAccommodationLostBed = Cas3LostBedsEntityFactory() + val temporaryAccommodationLostBed = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises) .produce() @@ -234,11 +234,11 @@ class BedUsageReportGeneratorTest { .withRoom(approvedPremisesRoom) .produce() - val approvedPremisesLostBed = Cas3LostBedsEntityFactory() + val approvedPremisesLostBed = Cas3VoidBedspacesEntityFactory() .withBed(approvedPremisesBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(approvedPremises) .produce() @@ -300,11 +300,11 @@ class BedUsageReportGeneratorTest { .withRoom(temporaryAccommodationRoomInProbationRegion) .produce() - val temporaryAccommodationLostBedInProbationArea = Cas3LostBedsEntityFactory() + val temporaryAccommodationLostBedInProbationArea = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBedInProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesInProbationRegion) .produce() @@ -321,11 +321,11 @@ class BedUsageReportGeneratorTest { .withRoom(temporaryAccommodationRoomOutsideProbationRegion) .produce() - val temporaryAccommodationLostBedOutsideProbationArea = Cas3LostBedsEntityFactory() + val temporaryAccommodationLostBedOutsideProbationArea = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBedOutsideProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesOutsideProbationRegion) .produce() @@ -376,11 +376,11 @@ class BedUsageReportGeneratorTest { .withRoom(temporaryAccommodationRoomInProbationRegion) .produce() - val temporaryAccommodationLostBedInProbationArea = Cas3LostBedsEntityFactory() + val temporaryAccommodationLostBedInProbationArea = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBedInProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesInProbationRegion) .produce() @@ -397,11 +397,11 @@ class BedUsageReportGeneratorTest { .withRoom(temporaryAccommodationRoomOutsideProbationRegion) .produce() - val temporaryAccommodationLostBedOutsideProbationArea = Cas3LostBedsEntityFactory() + val temporaryAccommodationLostBedOutsideProbationArea = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBedOutsideProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesOutsideProbationRegion) .produce() @@ -588,11 +588,11 @@ class BedUsageReportGeneratorTest { .withRoom(temporaryAccommodationRoom) .produce() - val temporaryAccommodationLostBed = Cas3LostBedsEntityFactory() + val temporaryAccommodationLostBed = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises) .produce() diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/BedUtilisationReportGeneratorTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/BedUtilisationReportGeneratorTest.kt index 0ed7eb9041..52ae4f8bf1 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/BedUtilisationReportGeneratorTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/BedUtilisationReportGeneratorTest.kt @@ -20,8 +20,8 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationRegionE import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.RoomEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.TemporaryAccommodationPremisesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.TurnaroundEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedReasonEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedsEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceReasonEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspacesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.BedUtilisationReportGenerator import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUtilisationReportData import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.BedUtilisationReportRow @@ -53,8 +53,8 @@ class BedUtilisationReportGeneratorTest { val temporaryAccommodationBed = BedEntityFactory().withRoom(temporaryAccommodationRoom).produce() val temporaryAccommodationLostBed = - Cas3LostBedsEntityFactory().withBed(temporaryAccommodationBed).withStartDate(LocalDate.parse("2023-04-05")) - .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(temporaryAccommodationBed).withStartDate(LocalDate.parse("2023-04-05")) + .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises).produce() val approvedPremises = @@ -64,8 +64,8 @@ class BedUtilisationReportGeneratorTest { val approvedPremisesBed = BedEntityFactory().withRoom(approvedPremisesRoom).produce() - Cas3LostBedsEntityFactory().withBed(approvedPremisesBed).withStartDate(LocalDate.parse("2023-04-10")) - .withEndDate(LocalDate.parse("2023-04-17")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(approvedPremisesBed).withStartDate(LocalDate.parse("2023-04-10")) + .withEndDate(LocalDate.parse("2023-04-17")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(approvedPremises).produce() val bedUtilisationBedspaceReportData = convertToCas3BedUtilisationBedspaceReportData(temporaryAccommodationBed) @@ -100,8 +100,8 @@ class BedUtilisationReportGeneratorTest { val temporaryAccommodationBed = BedEntityFactory().withRoom(temporaryAccommodationRoom).produce() val temporaryAccommodationLostBed = - Cas3LostBedsEntityFactory().withBed(temporaryAccommodationBed).withStartDate(LocalDate.parse("2023-04-05")) - .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(temporaryAccommodationBed).withStartDate(LocalDate.parse("2023-04-05")) + .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises).produce() val approvedPremises = @@ -111,8 +111,8 @@ class BedUtilisationReportGeneratorTest { val approvedPremisesBed = BedEntityFactory().withRoom(approvedPremisesRoom).produce() - Cas3LostBedsEntityFactory().withBed(approvedPremisesBed).withStartDate(LocalDate.parse("2023-04-05")) - .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(approvedPremisesBed).withStartDate(LocalDate.parse("2023-04-05")) + .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(approvedPremises).produce() val bedUtilisationReportGeneratorForThreeMonths = BedUtilisationReportGenerator(mockWorkingDayService) @@ -146,8 +146,8 @@ class BedUtilisationReportGeneratorTest { val temporaryAccommodationBed = BedEntityFactory().withRoom(temporaryAccommodationRoom).produce() - Cas3LostBedsEntityFactory().withBed(temporaryAccommodationBed).withStartDate(LocalDate.parse("2023-04-05")) - .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(temporaryAccommodationBed).withStartDate(LocalDate.parse("2023-04-05")) + .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises).produce() val approvedPremises = @@ -158,8 +158,8 @@ class BedUtilisationReportGeneratorTest { val approvedPremisesBed = BedEntityFactory().withRoom(approvedPremisesRoom).produce() val approvedPremisesLostBed = - Cas3LostBedsEntityFactory().withBed(approvedPremisesBed).withStartDate(LocalDate.parse("2023-04-05")) - .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(approvedPremisesBed).withStartDate(LocalDate.parse("2023-04-05")) + .withEndDate(LocalDate.parse("2023-04-07")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(approvedPremises).produce() val bedUtilisationReportGeneratorForThreeMonths = BedUtilisationReportGenerator(mockWorkingDayService) @@ -207,9 +207,9 @@ class BedUtilisationReportGeneratorTest { BedEntityFactory().withRoom(temporaryAccommodationRoomInProbationRegion).produce() val temporaryAccommodationLostBedInProbationArea = - Cas3LostBedsEntityFactory().withBed(temporaryAccommodationBedInProbationRegion) + Cas3VoidBedspacesEntityFactory().withBed(temporaryAccommodationBedInProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")).withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesInProbationRegion).produce() val temporaryAccommodationPremisesOutsideProbationRegion = @@ -223,9 +223,9 @@ class BedUtilisationReportGeneratorTest { BedEntityFactory().withRoom(temporaryAccommodationRoomOutsideProbationRegion).produce() val temporaryAccommodationLostBedOutsideProbationArea = - Cas3LostBedsEntityFactory().withBed(temporaryAccommodationBedOutsideProbationRegion) + Cas3VoidBedspacesEntityFactory().withBed(temporaryAccommodationBedOutsideProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")).withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesOutsideProbationRegion).produce() val bedUtilisationBedspaceReportData = @@ -277,9 +277,9 @@ class BedUtilisationReportGeneratorTest { BedEntityFactory().withRoom(temporaryAccommodationRoomInProbationRegion).produce() val temporaryAccommodationLostBedInProbationArea = - Cas3LostBedsEntityFactory().withBed(temporaryAccommodationBedInProbationRegion) + Cas3VoidBedspacesEntityFactory().withBed(temporaryAccommodationBedInProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")).withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesInProbationRegion).produce() val temporaryAccommodationPremisesOutsideProbationRegion = @@ -293,9 +293,9 @@ class BedUtilisationReportGeneratorTest { BedEntityFactory().withRoom(temporaryAccommodationRoomOutsideProbationRegion).produce() val temporaryAccommodationLostBedOutsideProbationArea = - Cas3LostBedsEntityFactory().withBed(temporaryAccommodationBedOutsideProbationRegion) + Cas3VoidBedspacesEntityFactory().withBed(temporaryAccommodationBedOutsideProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")).withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesOutsideProbationRegion).produce() val bedUtilisationBedInProbationRegionReportData = @@ -625,13 +625,13 @@ class BedUtilisationReportGeneratorTest { val bed = BedEntityFactory().withRoom(room).produce() val relevantVoidStraddlingStartOfMonth = - Cas3LostBedsEntityFactory().withBed(bed).withPremises(premises).withStartDate(LocalDate.parse("2023-03-28")) - .withEndDate(LocalDate.parse("2023-04-04")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(bed).withPremises(premises).withStartDate(LocalDate.parse("2023-03-28")) + .withEndDate(LocalDate.parse("2023-04-04")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .produce() val relevantVoidStraddlingEndOfMonth = - Cas3LostBedsEntityFactory().withBed(bed).withPremises(premises).withStartDate(LocalDate.parse("2023-04-25")) - .withEndDate(LocalDate.parse("2023-05-03")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(bed).withPremises(premises).withStartDate(LocalDate.parse("2023-04-25")) + .withEndDate(LocalDate.parse("2023-05-03")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .produce() val bedUtilisationBedspaceReportData = convertToCas3BedUtilisationBedspaceReportData(bed) @@ -724,13 +724,13 @@ class BedUtilisationReportGeneratorTest { } returns 1 val relevantVoidStraddlingStartOfMonth = - Cas3LostBedsEntityFactory().withBed(bed).withPremises(premises).withStartDate(LocalDate.parse("2023-03-28")) - .withEndDate(LocalDate.parse("2023-04-04")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(bed).withPremises(premises).withStartDate(LocalDate.parse("2023-03-28")) + .withEndDate(LocalDate.parse("2023-04-04")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .produce() val relevantVoidStraddlingEndOfMonth = - Cas3LostBedsEntityFactory().withBed(bed).withPremises(premises).withStartDate(LocalDate.parse("2023-04-25")) - .withEndDate(LocalDate.parse("2023-05-03")).withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + Cas3VoidBedspacesEntityFactory().withBed(bed).withPremises(premises).withStartDate(LocalDate.parse("2023-04-25")) + .withEndDate(LocalDate.parse("2023-05-03")).withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .produce() val bedUtilisationBedspaceReportData = convertToCas3BedUtilisationBedspaceReportData(bed) diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/Cas1OutOfServiceBedReportGeneratorTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/Cas1OutOfServiceBedReportGeneratorTest.kt index c00a2af472..d30d3a9d63 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/Cas1OutOfServiceBedReportGeneratorTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/Cas1OutOfServiceBedReportGeneratorTest.kt @@ -15,7 +15,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationRegionE import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.RoomEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.Cas1OutOfServiceBedRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.Cas1OutOfServiceBedsReportGenerator -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.LostBedReportRow +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.VoidBedspaceReportRow import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1.Cas1ReportService import java.time.LocalDate @@ -123,8 +123,8 @@ class Cas1OutOfServiceBedReportGeneratorTest { ) assertThat(result.count()).isEqualTo(2) - assertThat(result[0][LostBedReportRow::ap]).isEqualTo(premisesInProbationRegion.name) - assertThat(result[1][LostBedReportRow::ap]).isEqualTo(premisesOutsideProbationRegion.name) + assertThat(result[0][VoidBedspaceReportRow::ap]).isEqualTo(premisesInProbationRegion.name) + assertThat(result[1][VoidBedspaceReportRow::ap]).isEqualTo(premisesOutsideProbationRegion.name) } @Test @@ -171,16 +171,16 @@ class Cas1OutOfServiceBedReportGeneratorTest { ) assertThat(result.count()).isEqualTo(1) - assertThat(result[0][LostBedReportRow::roomName]).isEqualTo(room.name) - assertThat(result[0][LostBedReportRow::bedName]).isEqualTo(bed.name) - assertThat(result[0][LostBedReportRow::id]).isEqualTo(outOfServiceBed.id.toString()) - assertThat(result[0][LostBedReportRow::workOrderId]).isEqualTo(outOfServiceBed.referenceNumber) - assertThat(result[0][LostBedReportRow::region]).isEqualTo(premises.probationRegion.name) - assertThat(result[0][LostBedReportRow::ap]).isEqualTo(premises.name) - assertThat(result[0][LostBedReportRow::reason]).isEqualTo(outOfServiceBed.reason.name) - assertThat(result[0][LostBedReportRow::startDate]).isEqualTo(outOfServiceBed.startDate) - assertThat(result[0][LostBedReportRow::endDate]).isEqualTo(outOfServiceBed.endDate) - assertThat(result[0][LostBedReportRow::lengthDays]).isEqualTo(3) + assertThat(result[0][VoidBedspaceReportRow::roomName]).isEqualTo(room.name) + assertThat(result[0][VoidBedspaceReportRow::bedName]).isEqualTo(bed.name) + assertThat(result[0][VoidBedspaceReportRow::id]).isEqualTo(outOfServiceBed.id.toString()) + assertThat(result[0][VoidBedspaceReportRow::workOrderId]).isEqualTo(outOfServiceBed.referenceNumber) + assertThat(result[0][VoidBedspaceReportRow::region]).isEqualTo(premises.probationRegion.name) + assertThat(result[0][VoidBedspaceReportRow::ap]).isEqualTo(premises.name) + assertThat(result[0][VoidBedspaceReportRow::reason]).isEqualTo(outOfServiceBed.reason.name) + assertThat(result[0][VoidBedspaceReportRow::startDate]).isEqualTo(outOfServiceBed.startDate) + assertThat(result[0][VoidBedspaceReportRow::endDate]).isEqualTo(outOfServiceBed.endDate) + assertThat(result[0][VoidBedspaceReportRow::lengthDays]).isEqualTo(3) } @Test @@ -227,15 +227,15 @@ class Cas1OutOfServiceBedReportGeneratorTest { ) assertThat(result.count()).isEqualTo(1) - assertThat(result[0][LostBedReportRow::roomName]).isEqualTo(room.name) - assertThat(result[0][LostBedReportRow::bedName]).isEqualTo(bed.name) - assertThat(result[0][LostBedReportRow::id]).isEqualTo(outOfServiceBed.id.toString()) - assertThat(result[0][LostBedReportRow::workOrderId]).isEqualTo(outOfServiceBed.referenceNumber) - assertThat(result[0][LostBedReportRow::region]).isEqualTo(premises.probationRegion.name) - assertThat(result[0][LostBedReportRow::ap]).isEqualTo(premises.name) - assertThat(result[0][LostBedReportRow::reason]).isEqualTo(outOfServiceBed.reason.name) - assertThat(result[0][LostBedReportRow::startDate]).isEqualTo(outOfServiceBed.startDate) - assertThat(result[0][LostBedReportRow::endDate]).isEqualTo(outOfServiceBed.endDate) - assertThat(result[0][LostBedReportRow::lengthDays]).isEqualTo(7) + assertThat(result[0][VoidBedspaceReportRow::roomName]).isEqualTo(room.name) + assertThat(result[0][VoidBedspaceReportRow::bedName]).isEqualTo(bed.name) + assertThat(result[0][VoidBedspaceReportRow::id]).isEqualTo(outOfServiceBed.id.toString()) + assertThat(result[0][VoidBedspaceReportRow::workOrderId]).isEqualTo(outOfServiceBed.referenceNumber) + assertThat(result[0][VoidBedspaceReportRow::region]).isEqualTo(premises.probationRegion.name) + assertThat(result[0][VoidBedspaceReportRow::ap]).isEqualTo(premises.name) + assertThat(result[0][VoidBedspaceReportRow::reason]).isEqualTo(outOfServiceBed.reason.name) + assertThat(result[0][VoidBedspaceReportRow::startDate]).isEqualTo(outOfServiceBed.startDate) + assertThat(result[0][VoidBedspaceReportRow::endDate]).isEqualTo(outOfServiceBed.endDate) + assertThat(result[0][VoidBedspaceReportRow::lengthDays]).isEqualTo(7) } } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/LostBedReportGeneratorTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/VoidBedspaceReportGeneratorTest.kt similarity index 64% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/LostBedReportGeneratorTest.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/VoidBedspaceReportGeneratorTest.kt index 7db75eede7..ef47f3ebe8 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/LostBedReportGeneratorTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/generator/VoidBedspaceReportGeneratorTest.kt @@ -14,19 +14,19 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationDeliver import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationRegionEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.RoomEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.TemporaryAccommodationPremisesEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedReasonEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedsEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.LostBedsReportGenerator -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.LostBedReportRow -import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.LostBedReportProperties +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceReasonEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspacesEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.generator.VoidBedspacesReportGenerator +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.model.VoidBedspaceReportRow +import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.VoidBedspaceReportProperties import java.time.LocalDate -class LostBedReportGeneratorTest { - private val mockCas3LostBedsRepository = mockk() +class VoidBedspaceReportGeneratorTest { + private val mockCas3VoidBedspacesRepository = mockk() - private val lostBedReportGenerator = LostBedsReportGenerator( - mockCas3LostBedsRepository, + private val voidBedspacesReportGenerator = VoidBedspacesReportGenerator( + mockCas3VoidBedspacesRepository, ) @Test @@ -43,11 +43,11 @@ class LostBedReportGeneratorTest { .withRoom(temporaryAccommodationRoom) .produce() - val temporaryAccommodationLostBed = Cas3LostBedsEntityFactory() + val temporaryAccommodationVoidBedspace = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises) .produce() @@ -63,36 +63,36 @@ class LostBedReportGeneratorTest { .withRoom(approvedPremisesRoom) .produce() - val approvedPremisesLostBed = Cas3LostBedsEntityFactory() + val approvedPremisesLostBed = Cas3VoidBedspacesEntityFactory() .withBed(approvedPremisesBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(approvedPremises) .produce() every { - mockCas3LostBedsRepository.findAllByOverlappingDateForBed( + mockCas3VoidBedspacesRepository.findAllByOverlappingDateForBed( LocalDate.parse("2023-04-01"), LocalDate.parse("2023-04-30"), temporaryAccommodationBed, ) - } returns listOf(temporaryAccommodationLostBed) + } returns listOf(temporaryAccommodationVoidBedspace) every { - mockCas3LostBedsRepository.findAllByOverlappingDateForBed( + mockCas3VoidBedspacesRepository.findAllByOverlappingDateForBed( LocalDate.parse("2023-04-01"), LocalDate.parse("2023-04-30"), approvedPremisesBed, ) } returns listOf(approvedPremisesLostBed) - val result = lostBedReportGenerator.createReport( + val result = voidBedspacesReportGenerator.createReport( listOf(approvedPremisesBed, temporaryAccommodationBed), - LostBedReportProperties(ServiceName.temporaryAccommodation, null, 2023, 4), + VoidBedspaceReportProperties(ServiceName.temporaryAccommodation, null, 2023, 4), ) assertThat(result.count()).isEqualTo(1) - assertThat(result[0][LostBedReportRow::ap]).isEqualTo(temporaryAccommodationPremises.name) + assertThat(result[0][VoidBedspaceReportRow::ap]).isEqualTo(temporaryAccommodationPremises.name) } @Test @@ -125,11 +125,11 @@ class LostBedReportGeneratorTest { .withRoom(temporaryAccommodationRoomInProbationRegion) .produce() - val temporaryAccommodationLostBedInProbationArea = Cas3LostBedsEntityFactory() + val temporaryAccommodationVoidBedspaceInProbationArea = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBedInProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesInProbationRegion) .produce() @@ -146,36 +146,36 @@ class LostBedReportGeneratorTest { .withRoom(temporaryAccommodationRoomOutsideProbationRegion) .produce() - val temporaryAccommodationLostBedOutsideProbationArea = Cas3LostBedsEntityFactory() + val temporaryAccommodationVoidBedspaceOutsideProbationArea = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBedOutsideProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesOutsideProbationRegion) .produce() every { - mockCas3LostBedsRepository.findAllByOverlappingDateForBed( + mockCas3VoidBedspacesRepository.findAllByOverlappingDateForBed( LocalDate.parse("2023-04-01"), LocalDate.parse("2023-04-30"), temporaryAccommodationBedInProbationRegion, ) - } returns listOf(temporaryAccommodationLostBedInProbationArea) + } returns listOf(temporaryAccommodationVoidBedspaceInProbationArea) every { - mockCas3LostBedsRepository.findAllByOverlappingDateForBed( + mockCas3VoidBedspacesRepository.findAllByOverlappingDateForBed( LocalDate.parse("2023-04-01"), LocalDate.parse("2023-04-30"), temporaryAccommodationBedOutsideProbationRegion, ) - } returns listOf(temporaryAccommodationLostBedOutsideProbationArea) + } returns listOf(temporaryAccommodationVoidBedspaceOutsideProbationArea) - val result = lostBedReportGenerator.createReport( + val result = voidBedspacesReportGenerator.createReport( listOf(temporaryAccommodationBedInProbationRegion, temporaryAccommodationBedOutsideProbationRegion), - LostBedReportProperties(ServiceName.temporaryAccommodation, probationRegion1.id, 2023, 4), + VoidBedspaceReportProperties(ServiceName.temporaryAccommodation, probationRegion1.id, 2023, 4), ) assertThat(result.count()).isEqualTo(1) - assertThat(result[0][LostBedReportRow::ap]).isEqualTo(temporaryAccommodationPremisesInProbationRegion.name) + assertThat(result[0][VoidBedspaceReportRow::ap]).isEqualTo(temporaryAccommodationPremisesInProbationRegion.name) } @Test @@ -208,11 +208,11 @@ class LostBedReportGeneratorTest { .withRoom(temporaryAccommodationRoomInProbationRegion) .produce() - val temporaryAccommodationLostBedInProbationArea = Cas3LostBedsEntityFactory() + val temporaryAccommodationVoidBedspaceInProbationArea = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBedInProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesInProbationRegion) .produce() @@ -229,41 +229,41 @@ class LostBedReportGeneratorTest { .withRoom(temporaryAccommodationRoomOutsideProbationRegion) .produce() - val temporaryAccommodationLostBedOutsideProbationArea = Cas3LostBedsEntityFactory() + val temporaryAccommodationVoidBedspaceOutsideProbationArea = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBedOutsideProbationRegion) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremisesOutsideProbationRegion) .produce() every { - mockCas3LostBedsRepository.findAllByOverlappingDateForBed( + mockCas3VoidBedspacesRepository.findAllByOverlappingDateForBed( LocalDate.parse("2023-04-01"), LocalDate.parse("2023-04-30"), temporaryAccommodationBedInProbationRegion, ) - } returns listOf(temporaryAccommodationLostBedInProbationArea) + } returns listOf(temporaryAccommodationVoidBedspaceInProbationArea) every { - mockCas3LostBedsRepository.findAllByOverlappingDateForBed( + mockCas3VoidBedspacesRepository.findAllByOverlappingDateForBed( LocalDate.parse("2023-04-01"), LocalDate.parse("2023-04-30"), temporaryAccommodationBedOutsideProbationRegion, ) - } returns listOf(temporaryAccommodationLostBedOutsideProbationArea) + } returns listOf(temporaryAccommodationVoidBedspaceOutsideProbationArea) - val result = lostBedReportGenerator.createReport( + val result = voidBedspacesReportGenerator.createReport( listOf(temporaryAccommodationBedInProbationRegion, temporaryAccommodationBedOutsideProbationRegion), - LostBedReportProperties(ServiceName.temporaryAccommodation, null, 2023, 4), + VoidBedspaceReportProperties(ServiceName.temporaryAccommodation, null, 2023, 4), ) assertThat(result.count()).isEqualTo(2) - assertThat(result[0][LostBedReportRow::ap]).isEqualTo(temporaryAccommodationPremisesInProbationRegion.name) - assertThat(result[1][LostBedReportRow::ap]).isEqualTo(temporaryAccommodationPremisesOutsideProbationRegion.name) + assertThat(result[0][VoidBedspaceReportRow::ap]).isEqualTo(temporaryAccommodationPremisesInProbationRegion.name) + assertThat(result[1][VoidBedspaceReportRow::ap]).isEqualTo(temporaryAccommodationPremisesOutsideProbationRegion.name) } @Test - fun `Lost Bed rows are correctly generated`() { + fun `Void Bedspace rows are correctly generated`() { val probationRegion = ProbationRegionEntityFactory() .withApArea(ApAreaEntityFactory().produce()) .produce() @@ -289,38 +289,38 @@ class LostBedReportGeneratorTest { .withRoom(temporaryAccommodationRoom) .produce() - val temporaryAccommodationLostBed = Cas3LostBedsEntityFactory() + val temporaryAccommodationVoidBedspace = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBed) .withStartDate(LocalDate.parse("2023-04-05")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises) .produce() every { - mockCas3LostBedsRepository.findAllByOverlappingDateForBed( + mockCas3VoidBedspacesRepository.findAllByOverlappingDateForBed( LocalDate.parse("2023-04-01"), LocalDate.parse("2023-04-30"), temporaryAccommodationBed, ) - } returns listOf(temporaryAccommodationLostBed) + } returns listOf(temporaryAccommodationVoidBedspace) - val result = lostBedReportGenerator.createReport( + val result = voidBedspacesReportGenerator.createReport( listOf(temporaryAccommodationBed), - LostBedReportProperties(ServiceName.temporaryAccommodation, null, 2023, 4), + VoidBedspaceReportProperties(ServiceName.temporaryAccommodation, null, 2023, 4), ) assertThat(result.count()).isEqualTo(1) - assertThat(result[0][LostBedReportRow::roomName]).isEqualTo(temporaryAccommodationRoom.name) - assertThat(result[0][LostBedReportRow::bedName]).isEqualTo(temporaryAccommodationBed.name) - assertThat(result[0][LostBedReportRow::id]).isEqualTo(temporaryAccommodationLostBed.id.toString()) - assertThat(result[0][LostBedReportRow::workOrderId]).isEqualTo(temporaryAccommodationLostBed.referenceNumber) - assertThat(result[0][LostBedReportRow::region]).isEqualTo(temporaryAccommodationPremises.probationRegion.name) - assertThat(result[0][LostBedReportRow::ap]).isEqualTo(temporaryAccommodationPremises.name) - assertThat(result[0][LostBedReportRow::reason]).isEqualTo(temporaryAccommodationLostBed.reason.name) - assertThat(result[0][LostBedReportRow::startDate]).isEqualTo(temporaryAccommodationLostBed.startDate) - assertThat(result[0][LostBedReportRow::endDate]).isEqualTo(temporaryAccommodationLostBed.endDate) - assertThat(result[0][LostBedReportRow::lengthDays]).isEqualTo(3) + assertThat(result[0][VoidBedspaceReportRow::roomName]).isEqualTo(temporaryAccommodationRoom.name) + assertThat(result[0][VoidBedspaceReportRow::bedName]).isEqualTo(temporaryAccommodationBed.name) + assertThat(result[0][VoidBedspaceReportRow::id]).isEqualTo(temporaryAccommodationVoidBedspace.id.toString()) + assertThat(result[0][VoidBedspaceReportRow::workOrderId]).isEqualTo(temporaryAccommodationVoidBedspace.referenceNumber) + assertThat(result[0][VoidBedspaceReportRow::region]).isEqualTo(temporaryAccommodationPremises.probationRegion.name) + assertThat(result[0][VoidBedspaceReportRow::ap]).isEqualTo(temporaryAccommodationPremises.name) + assertThat(result[0][VoidBedspaceReportRow::reason]).isEqualTo(temporaryAccommodationVoidBedspace.reason.name) + assertThat(result[0][VoidBedspaceReportRow::startDate]).isEqualTo(temporaryAccommodationVoidBedspace.startDate) + assertThat(result[0][VoidBedspaceReportRow::endDate]).isEqualTo(temporaryAccommodationVoidBedspace.endDate) + assertThat(result[0][VoidBedspaceReportRow::lengthDays]).isEqualTo(3) } @Test @@ -350,37 +350,37 @@ class LostBedReportGeneratorTest { .withRoom(temporaryAccommodationRoom) .produce() - val temporaryAccommodationLostBed = Cas3LostBedsEntityFactory() + val temporaryAccommodationVoidBedspace = Cas3VoidBedspacesEntityFactory() .withBed(temporaryAccommodationBed) .withStartDate(LocalDate.parse("2023-03-28")) .withEndDate(LocalDate.parse("2023-04-07")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withPremises(temporaryAccommodationPremises) .produce() every { - mockCas3LostBedsRepository.findAllByOverlappingDateForBed( + mockCas3VoidBedspacesRepository.findAllByOverlappingDateForBed( LocalDate.parse("2023-04-01"), LocalDate.parse("2023-04-30"), temporaryAccommodationBed, ) - } returns listOf(temporaryAccommodationLostBed) + } returns listOf(temporaryAccommodationVoidBedspace) - val result = lostBedReportGenerator.createReport( + val result = voidBedspacesReportGenerator.createReport( listOf(temporaryAccommodationBed), - LostBedReportProperties(ServiceName.temporaryAccommodation, null, 2023, 4), + VoidBedspaceReportProperties(ServiceName.temporaryAccommodation, null, 2023, 4), ) assertThat(result.count()).isEqualTo(1) - assertThat(result[0][LostBedReportRow::roomName]).isEqualTo(temporaryAccommodationRoom.name) - assertThat(result[0][LostBedReportRow::bedName]).isEqualTo(temporaryAccommodationBed.name) - assertThat(result[0][LostBedReportRow::id]).isEqualTo(temporaryAccommodationLostBed.id.toString()) - assertThat(result[0][LostBedReportRow::workOrderId]).isEqualTo(temporaryAccommodationLostBed.referenceNumber) - assertThat(result[0][LostBedReportRow::region]).isEqualTo(temporaryAccommodationPremises.probationRegion.name) - assertThat(result[0][LostBedReportRow::ap]).isEqualTo(temporaryAccommodationPremises.name) - assertThat(result[0][LostBedReportRow::reason]).isEqualTo(temporaryAccommodationLostBed.reason.name) - assertThat(result[0][LostBedReportRow::startDate]).isEqualTo(temporaryAccommodationLostBed.startDate) - assertThat(result[0][LostBedReportRow::endDate]).isEqualTo(temporaryAccommodationLostBed.endDate) - assertThat(result[0][LostBedReportRow::lengthDays]).isEqualTo(7) + assertThat(result[0][VoidBedspaceReportRow::roomName]).isEqualTo(temporaryAccommodationRoom.name) + assertThat(result[0][VoidBedspaceReportRow::bedName]).isEqualTo(temporaryAccommodationBed.name) + assertThat(result[0][VoidBedspaceReportRow::id]).isEqualTo(temporaryAccommodationVoidBedspace.id.toString()) + assertThat(result[0][VoidBedspaceReportRow::workOrderId]).isEqualTo(temporaryAccommodationVoidBedspace.referenceNumber) + assertThat(result[0][VoidBedspaceReportRow::region]).isEqualTo(temporaryAccommodationPremises.probationRegion.name) + assertThat(result[0][VoidBedspaceReportRow::ap]).isEqualTo(temporaryAccommodationPremises.name) + assertThat(result[0][VoidBedspaceReportRow::reason]).isEqualTo(temporaryAccommodationVoidBedspace.reason.name) + assertThat(result[0][VoidBedspaceReportRow::startDate]).isEqualTo(temporaryAccommodationVoidBedspace.startDate) + assertThat(result[0][VoidBedspaceReportRow::endDate]).isEqualTo(temporaryAccommodationVoidBedspace.endDate) + assertThat(result[0][VoidBedspaceReportRow::lengthDays]).isEqualTo(7) } } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/util/Cas3ReportsTestHelper.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/util/Cas3ReportsTestHelper.kt index b4bcf6fb69..54d389de4e 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/util/Cas3ReportsTestHelper.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/reporting/util/Cas3ReportsTestHelper.kt @@ -3,12 +3,12 @@ package uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.reporting.util import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BedEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationPremisesEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationBedspaceReportData import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationBookingCancellationReportData import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationBookingReportData import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationBookingTurnaroundReportData -import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationLostBedReportData +import uk.gov.justice.digital.hmpps.approvedpremisesapi.repository.BedUtilisationVoidBedspaceReportData import java.time.Instant import java.time.LocalDate @@ -69,12 +69,12 @@ fun convertToCas3BedUtilisationBookingTurnaroundReportData(booking: BookingEntit ) } -fun convertToCas3BedUtilisationLostBedReportData(lostBed: Cas3LostBedsEntity): Cas3BedUtilisationLostBedReportData { - return Cas3BedUtilisationLostBedReportData( - bedId = lostBed.bed.id.toString(), - startDate = lostBed.startDate, - endDate = lostBed.endDate, - cancellationId = lostBed.cancellation?.id?.toString(), +fun convertToCas3BedUtilisationLostBedReportData(voidBedspace: Cas3VoidBedspacesEntity): Cas3BedUtilisationVoidBedspaceUtilisationVoidBedspaceReportData { + return Cas3BedUtilisationVoidBedspaceUtilisationVoidBedspaceReportData( + bedId = voidBedspace.bed.id.toString(), + startDate = voidBedspace.startDate, + endDate = voidBedspace.endDate, + cancellationId = voidBedspace.cancellation?.id?.toString(), ) } @@ -121,9 +121,9 @@ class Cas3BedUtilisationBookingTurnaroundReportData( override val workingDayCount: Int, ) : BedUtilisationBookingTurnaroundReportData -class Cas3BedUtilisationLostBedReportData( +class Cas3BedUtilisationVoidBedspaceUtilisationVoidBedspaceReportData( override val bedId: String, override val startDate: LocalDate, override val endDate: LocalDate, override val cancellationId: String?, -) : BedUtilisationLostBedReportData +) : BedUtilisationVoidBedspaceReportData diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/BookingServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/BookingServiceTest.kt index 1423edda02..5f5f70df9f 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/BookingServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/BookingServiceTest.kt @@ -44,8 +44,8 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.RoomEntityFactor import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.TemporaryAccommodationPremisesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.UserEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.UserRoleAssignmentEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedReasonEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedsEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceReasonEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspacesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ApprovedPremisesApplicationEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ApprovedPremisesEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ArrivalEntity @@ -66,7 +66,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.PlacementRequ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.PremisesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserQualification import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserRole -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.PersonInfoResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.AuthorisableActionResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.CasResult @@ -107,7 +107,7 @@ class BookingServiceTest { private val mockCancellationReasonRepository = mockk() private val mockBedRepository = mockk() private val mockPlacementRequestRepository = mockk() - private val mockCas3LostBedsRepository = mockk() + private val mockCas3LostBedsRepository = mockk() private val mockPremisesRepository = mockk() private val mockAssessmentRepository = mockk() private val mockUserService = mockk() @@ -131,7 +131,7 @@ class BookingServiceTest { cancellationReasonRepository = mockCancellationReasonRepository, bedRepository = mockBedRepository, placementRequestRepository = mockPlacementRequestRepository, - lostBedsRepository = mockCas3LostBedsRepository, + cas3VoidBedspacesRepository = mockCas3LostBedsRepository, premisesRepository = mockPremisesRepository, userService = mockUserService, userAccessService = mockUserAccessService, @@ -1469,7 +1469,7 @@ class BookingServiceTest { } @Test - fun `returns ConflictError if Bed has a conflicting Lost Bed`() { + fun `returns ConflictError if Bed has a conflicting Void Bedspace`() { val arrivalDate = LocalDate.parse("2023-03-28") val departureDate = LocalDate.parse("2023-03-30") @@ -1502,12 +1502,12 @@ class BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { mockCas3LostBedsRepository.findByBedIdAndOverlappingDate(bed.id, arrivalDate, departureDate, null) } returns listOf( - Cas3LostBedsEntityFactory() + Cas3VoidBedspacesEntityFactory() .withStartDate(arrivalDate) .withEndDate(departureDate) .withPremises(premises) .withBed(bed) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .produce(), ) @@ -2027,19 +2027,19 @@ class BookingServiceTest { } @Test - fun `for non-AP Bookings, returns conflict error for conflicting Lost Bed`() { + fun `for non-AP Bookings, returns conflict error for conflicting Void Bedspace`() { val booking = BookingEntityFactory() .withPremises(temporaryAccommodationPremises) .withBed(temporaryAccommodationBed) .withServiceName(ServiceName.temporaryAccommodation) .produce() - val conflictingLostBed = Cas3LostBedsEntityFactory() + val conflictingLostBed = Cas3VoidBedspacesEntityFactory() .withPremises(temporaryAccommodationPremises) .withBed(temporaryAccommodationBed) .withStartDate(LocalDate.parse("2023-07-10")) .withEndDate(LocalDate.parse("2023-07-12")) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .produce() every { mockWorkingDayService.addWorkingDays(any(), any()) } answers { it.invocation.args[0] as LocalDate } diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/PremisesServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/PremisesServiceTest.kt index c604b5e8c8..21b96c876e 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/PremisesServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/PremisesServiceTest.kt @@ -11,9 +11,9 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.BookingSummaryFo import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.LocalAuthorityEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationRegionEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.RoomEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedCancellationEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedReasonEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedsEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceCancellationEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceReasonEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspacesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BedRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.LocalAuthorityAreaRepository @@ -21,7 +21,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.PremisesRepos import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationDeliveryUnitRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationRegionRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.RoomRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.Availability import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.CharacteristicService import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.PremisesService @@ -31,7 +31,7 @@ import java.time.LocalDate class PremisesServiceTest { private val premisesRepositoryMock = mockk() - private val lostBedsRepositoryMock = mockk() + private val cs3VoidBedspacesRepositoryMock = mockk() private val bookingRepositoryMock = mockk() private val localAuthorityAreaRepositoryMock = mockk() private val probationRegionRepositoryMock = mockk() @@ -51,7 +51,7 @@ class PremisesServiceTest { private val premisesService = PremisesService( premisesRepositoryMock, - lostBedsRepositoryMock, + cs3VoidBedspacesRepositoryMock, bookingRepositoryMock, localAuthorityAreaRepositoryMock, probationRegionRepositoryMock, @@ -63,14 +63,14 @@ class PremisesServiceTest { ) @Test - fun `getAvailabilityForRange returns correctly when there are no bookings or lost beds`() { + fun `getAvailabilityForRange returns correctly when there are no bookings or void bedspaces`() { val startDate = LocalDate.now() val endDate = LocalDate.now().plusDays(3) val premises = approvedPremisesFactory.produce() every { bookingRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf() - every { lostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf() + every { cs3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf() val result = premisesService.getAvailabilityForRange(premises, startDate, endDate) @@ -88,11 +88,11 @@ class PremisesServiceTest { val premises = approvedPremisesFactory.produce() - val lostBedEntityOne = Cas3LostBedsEntityFactory() + val voidBedspaceEntityOne = Cas3VoidBedspacesEntityFactory() .withPremises(premises) .withStartDate(startDate.plusDays(1)) .withEndDate(startDate.plusDays(2)) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withBed( BedEntityFactory().apply { withYieldedRoom { @@ -104,11 +104,11 @@ class PremisesServiceTest { ) .produce() - val lostBedEntityTwo = Cas3LostBedsEntityFactory() + val voidBedspaceEntityTwo = Cas3VoidBedspacesEntityFactory() .withPremises(premises) .withStartDate(startDate.plusDays(1)) .withEndDate(startDate.plusDays(2)) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withBed( BedEntityFactory().apply { withYieldedRoom { @@ -158,35 +158,35 @@ class PremisesServiceTest { nonArrivedBookingEntity, cancelledBookingEntity, ) - every { lostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( - lostBedEntityOne, - lostBedEntityTwo, + every { cs3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( + voidBedspaceEntityOne, + voidBedspaceEntityTwo, ) val result = premisesService.getAvailabilityForRange(premises, startDate, endDate) assertThat(result).containsValues( - Availability(date = startDate, pendingBookings = 0, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(1), pendingBookings = 1, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 2), - Availability(date = startDate.plusDays(2), pendingBookings = 1, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 1, lostBeds = 0), - Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 1, lostBeds = 0), + Availability(date = startDate, pendingBookings = 0, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(1), pendingBookings = 1, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 2), + Availability(date = startDate.plusDays(2), pendingBookings = 1, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 1, voidBedspaces = 0), + Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 1, voidBedspaces = 0), ) } @Test - fun `getAvailabilityForRange returns correctly when there are cancelled lost beds`() { + fun `getAvailabilityForRange returns correctly when there are cancelled void bedspaces`() { val startDate = LocalDate.now() val endDate = LocalDate.now().plusDays(6) val premises = approvedPremisesFactory.produce() - val lostBedEntity = Cas3LostBedsEntityFactory() + val voidBedspaceEntity = Cas3VoidBedspacesEntityFactory() .withPremises(premises) .withStartDate(startDate.plusDays(1)) .withEndDate(startDate.plusDays(2)) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withBed( BedEntityFactory().apply { withYieldedRoom { @@ -198,26 +198,26 @@ class PremisesServiceTest { ) .produce() - val lostBedCancellation = Cas3LostBedCancellationEntityFactory() - .withYieldedLostBed { lostBedEntity } + val lostBedCancellation = Cas3VoidBedspaceCancellationEntityFactory() + .withYieldedVoidBedspace { voidBedspaceEntity } .produce() - lostBedEntity.cancellation = lostBedCancellation + voidBedspaceEntity.cancellation = lostBedCancellation every { bookingRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf() - every { lostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( - lostBedEntity, + every { cs3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( + voidBedspaceEntity, ) val result = premisesService.getAvailabilityForRange(premises, startDate, endDate) assertThat(result).containsValues( - Availability(date = startDate, pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(1), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(2), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), + Availability(date = startDate, pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(1), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(2), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), ) } @@ -237,7 +237,7 @@ class PremisesServiceTest { every { premisesService.getBedCount(premises) } answers { 30 } every { bookingRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, oneYearFromNow) } answers { emptyList() } - every { lostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, oneYearFromNow) } answers { emptyList() } + every { cs3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, oneYearFromNow) } answers { emptyList() } val result = premisesService.getDateCapacities(premises) @@ -265,7 +265,7 @@ class PremisesServiceTest { every { premisesService.getBedCount(premises) } answers { 30 } every { bookingRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } - every { lostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } + every { cs3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } val result = premisesService.getDateCapacities(premises) @@ -291,7 +291,7 @@ class PremisesServiceTest { every { premisesService.getBedCount(premises) } answers { 30 } every { bookingRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } - every { lostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } + every { cs3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } val result = premisesService.getDateCapacities(premises) @@ -317,7 +317,7 @@ class PremisesServiceTest { every { premisesService.getBedCount(premises) } answers { 30 } every { bookingRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } - every { lostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } + every { cs3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, today, fourMonthsFromNow) } answers { emptyList() } val result = premisesService.getDateCapacities(premises) diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/RoomServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/RoomServiceTest.kt index e380750d04..3bd79717cb 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/RoomServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/RoomServiceTest.kt @@ -21,7 +21,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BedRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.RoomEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.RoomRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.AuthorisableActionResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.ValidatableActionResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.service.CharacteristicService @@ -34,10 +34,10 @@ class RoomServiceTest { private val roomRepository = mockk() private val bedRepository = mockk() private val bookingRepository = mockk() - private val lostBedsRepository = mockk() + private val cas3VoidBedspacesRepository = mockk() private val characteristicService = mockk() - private val roomService = RoomService(roomRepository, bedRepository, bookingRepository, lostBedsRepository, characteristicService) + private val roomService = RoomService(roomRepository, bedRepository, bookingRepository, cas3VoidBedspacesRepository, characteristicService) @Test fun `An empty room name results in a validation error`() { diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/UserAccessServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/UserAccessServiceTest.kt index 8272603925..13d7876aa6 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/UserAccessServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/UserAccessServiceTest.kt @@ -633,7 +633,7 @@ class UserAccessServiceTest { user.addRoleForUnitTest(UserRole.CAS3_ASSESSOR) - assertThat(userAccessService.userCanManagePremisesLostBeds(user, temporaryAccommodationPremisesInUserRegion)).isTrue + assertThat(userAccessService.userCanManagePremisesVoidBedspaces(user, temporaryAccommodationPremisesInUserRegion)).isTrue } @Test @@ -642,22 +642,22 @@ class UserAccessServiceTest { user.addRoleForUnitTest(UserRole.CAS3_ASSESSOR) - assertThat(userAccessService.userCanManagePremisesLostBeds(user, temporaryAccommodationPremisesNotInUserRegion)).isFalse + assertThat(userAccessService.userCanManagePremisesVoidBedspaces(user, temporaryAccommodationPremisesNotInUserRegion)).isFalse } @Test fun `userCanManagePremisesLostBeds returns false if the given premises is a Temporary Accommodation premises and the user does not have a suitable role`() { currentRequestIsFor(ServiceName.temporaryAccommodation) - assertThat(userAccessService.userCanManagePremisesLostBeds(user, temporaryAccommodationPremisesInUserRegion)).isFalse - assertThat(userAccessService.userCanManagePremisesLostBeds(user, temporaryAccommodationPremisesNotInUserRegion)).isFalse + assertThat(userAccessService.userCanManagePremisesVoidBedspaces(user, temporaryAccommodationPremisesInUserRegion)).isFalse + assertThat(userAccessService.userCanManagePremisesVoidBedspaces(user, temporaryAccommodationPremisesNotInUserRegion)).isFalse } @Test fun `currentUserCanManagePremisesLostBeds returns false if the given premises is an Approved Premises and the current user has no suitable role`() { currentRequestIsFor(ServiceName.approvedPremises) - assertThat(userAccessService.currentUserCanManagePremisesLostBeds(approvedPremises)).isFalse + assertThat(userAccessService.currentUserCanManagePremisesVoidBedspaces(approvedPremises)).isFalse } @Test @@ -666,7 +666,7 @@ class UserAccessServiceTest { user.addRoleForUnitTest(UserRole.CAS3_ASSESSOR) - assertThat(userAccessService.currentUserCanManagePremisesLostBeds(temporaryAccommodationPremisesInUserRegion)).isTrue + assertThat(userAccessService.currentUserCanManagePremisesVoidBedspaces(temporaryAccommodationPremisesInUserRegion)).isTrue } @Test @@ -675,15 +675,15 @@ class UserAccessServiceTest { user.addRoleForUnitTest(UserRole.CAS3_ASSESSOR) - assertThat(userAccessService.currentUserCanManagePremisesLostBeds(temporaryAccommodationPremisesNotInUserRegion)).isFalse + assertThat(userAccessService.currentUserCanManagePremisesVoidBedspaces(temporaryAccommodationPremisesNotInUserRegion)).isFalse } @Test fun `currentUserCanManagePremisesLostBeds returns false if the given premises is a Temporary Accommodation premises and the user does not have a suitable role`() { currentRequestIsFor(ServiceName.temporaryAccommodation) - assertThat(userAccessService.currentUserCanManagePremisesLostBeds(temporaryAccommodationPremisesInUserRegion)).isFalse - assertThat(userAccessService.currentUserCanManagePremisesLostBeds(temporaryAccommodationPremisesNotInUserRegion)).isFalse + assertThat(userAccessService.currentUserCanManagePremisesVoidBedspaces(temporaryAccommodationPremisesInUserRegion)).isFalse + assertThat(userAccessService.currentUserCanManagePremisesVoidBedspaces(temporaryAccommodationPremisesNotInUserRegion)).isFalse } @ParameterizedTest diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3BookingServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3BookingServiceTest.kt index cf8fe5d885..7d42d862fd 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3BookingServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3BookingServiceTest.kt @@ -64,7 +64,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TurnaroundEnt import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TurnaroundRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserEntity import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.UserQualification -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.PersonInfoResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.AuthorisableActionResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.CasResult @@ -101,7 +101,7 @@ class Cas3BookingServiceTest { private val mockDestinationProviderRepository = mockk() private val mockCancellationReasonRepository = mockk() private val mockBedRepository = mockk() - private val mockLostBedsRepository = mockk() + private val mockCas3VoidBedspacesRepository = mockk() private val mockTurnaroundRepository = mockk() private val mockAssessmentRepository = mockk() private val mockUserService = mockk() @@ -120,7 +120,7 @@ class Cas3BookingServiceTest { moveOnCategoryRepository = mockMoveOnCategoryRepository, cancellationRepository = mockCancellationRepository, cancellationReasonRepository = mockCancellationReasonRepository, - cas3LostBedsRepository = mockLostBedsRepository, + cas3VoidBedspacesRepository = mockCas3VoidBedspacesRepository, turnaroundRepository = mockTurnaroundRepository, extensionRepository = mockExtensionRepository, cas3PremisesService = mockCas3PremisesService, @@ -1246,7 +1246,7 @@ class Cas3BookingServiceTest { every { mockWorkingDayService.addWorkingDays(any(), any()) } answers { it.invocation.args[0] as LocalDate } every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(any(), any(), any()) } returns listOf() - every { mockLostBedsRepository.findByBedIdAndOverlappingDate(any(), any(), any(), any()) } returns listOf() + every { mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate(any(), any(), any(), any()) } returns listOf() } @Test @@ -1610,7 +1610,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bedId, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bedId, arrivalDate, departureDate, @@ -1661,7 +1661,7 @@ class Cas3BookingServiceTest { every { mockBedRepository.findByIdOrNull(bedId) } returns null every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bedId, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bedId, arrivalDate, departureDate, @@ -1730,7 +1730,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -1800,7 +1800,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -1886,7 +1886,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -1975,7 +1975,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -2068,7 +2068,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -2159,7 +2159,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -2257,7 +2257,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -2352,7 +2352,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -2439,7 +2439,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -2509,7 +2509,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -2604,7 +2604,7 @@ class Cas3BookingServiceTest { every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(bed.id, departureDate, null) } returns listOf() every { - mockLostBedsRepository.findByBedIdAndOverlappingDate( + mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate( bed.id, arrivalDate, departureDate, @@ -2705,7 +2705,7 @@ class Cas3BookingServiceTest { every { mockWorkingDayService.addWorkingDays(any(), any()) } answers { it.invocation.args[0] as LocalDate } every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(any(), any(), any()) } returns listOf() - every { mockLostBedsRepository.findByBedIdAndOverlappingDate(any(), any(), any(), any()) } returns listOf() + every { mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate(any(), any(), any(), any()) } returns listOf() every { mockTurnaroundRepository.save(any()) } answers { it.invocation.args[0] as TurnaroundEntity } val negativeDaysResult = cas3BookingService.createTurnaround(booking, -1) @@ -2748,7 +2748,7 @@ class Cas3BookingServiceTest { every { mockWorkingDayService.addWorkingDays(any(), any()) } answers { it.invocation.args[0] as LocalDate } every { mockBookingRepository.findByBedIdAndArrivingBeforeDate(any(), any(), any()) } returns listOf() - every { mockLostBedsRepository.findByBedIdAndOverlappingDate(any(), any(), any(), any()) } returns listOf() + every { mockCas3VoidBedspacesRepository.findByBedIdAndOverlappingDate(any(), any(), any(), any()) } returns listOf() every { mockTurnaroundRepository.save(any()) } answers { it.invocation.args[0] as TurnaroundEntity } val result = cas3BookingService.createTurnaround(booking, 2) diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3PremisesServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3PremisesServiceTest.kt index 9f46a2043e..2e4bfd91e6 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3PremisesServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3PremisesServiceTest.kt @@ -15,19 +15,19 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.LocalAuthorityEn import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationRegionEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.RoomEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.TemporaryAccommodationPremisesEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedCancellationEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedReasonEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedsEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceCancellationEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceReasonEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspacesEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.LocalAuthorityAreaRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.PremisesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationDeliveryUnitRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ProbationRegionRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.TemporaryAccommodationPremisesEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedCancellationRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedReasonRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsEntity -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceCancellationRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspaceReasonRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesEntity +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.Availability import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.AuthorisableActionResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.ValidatableActionResult @@ -38,9 +38,9 @@ import java.util.UUID class Cas3PremisesServiceTest { private val premisesRepositoryMock = mockk() - private val cas3LostBedsRepositoryMock = mockk() - private val cas3LostBedReasonRepositoryMock = mockk() - private val cas3LostBedCancellationRepositoryMock = mockk() + private val cas3VoidBedspacesRepositoryMock = mockk() + private val cas3VoidBedspaceReasonRepositoryMock = mockk() + private val cas3VoidBedspaceCancellationRepositoryMock = mockk() private val bookingRepositoryMock = mockk() private val localAuthorityAreaRepositoryMock = mockk() private val probationRegionRepositoryMock = mockk() @@ -55,9 +55,9 @@ class Cas3PremisesServiceTest { private val premisesService = Cas3PremisesService( premisesRepositoryMock, - cas3LostBedsRepositoryMock, - cas3LostBedReasonRepositoryMock, - cas3LostBedCancellationRepositoryMock, + cas3VoidBedspacesRepositoryMock, + cas3VoidBedspaceReasonRepositoryMock, + cas3VoidBedspaceCancellationRepositoryMock, bookingRepositoryMock, localAuthorityAreaRepositoryMock, probationRegionRepositoryMock, @@ -80,11 +80,11 @@ class Cas3PremisesServiceTest { .withYieldedRoom { room } .produce() - val voidBedspaceEntity = Cas3LostBedsEntityFactory() + val voidBedspaceEntity = Cas3VoidBedspacesEntityFactory() .withPremises(premises) .withStartDate(startDate.plusDays(1)) .withEndDate(startDate.plusDays(2)) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withYieldedBed { bed } .produce() @@ -126,19 +126,19 @@ class Cas3PremisesServiceTest { nonArrivedBookingEntity, cancelledBookingEntity, ) - every { cas3LostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( + every { cas3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( voidBedspaceEntity, ) val result = premisesService.getAvailabilityForRange(premises, startDate, endDate) assertThat(result).containsValues( - Availability(date = startDate, pendingBookings = 0, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(1), pendingBookings = 1, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 1), - Availability(date = startDate.plusDays(2), pendingBookings = 1, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 1, lostBeds = 0), - Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 1, lostBeds = 0), + Availability(date = startDate, pendingBookings = 0, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(1), pendingBookings = 1, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 1), + Availability(date = startDate.plusDays(2), pendingBookings = 1, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 1, voidBedspaces = 0), + Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 1, voidBedspaces = 0), ) } @@ -150,7 +150,7 @@ class Cas3PremisesServiceTest { val premises = temporaryAccommodationPremisesFactory.produce() every { bookingRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf() - every { cas3LostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf() + every { cas3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf() val result = premisesService.getAvailabilityForRange(premises, startDate, endDate) @@ -168,11 +168,11 @@ class Cas3PremisesServiceTest { val premises = temporaryAccommodationPremisesFactory.produce() - val voidBedspaceEntityOne = Cas3LostBedsEntityFactory() + val voidBedspaceEntityOne = Cas3VoidBedspacesEntityFactory() .withPremises(premises) .withStartDate(startDate.plusDays(1)) .withEndDate(startDate.plusDays(2)) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withBed( BedEntityFactory().apply { withYieldedRoom { @@ -184,11 +184,11 @@ class Cas3PremisesServiceTest { ) .produce() - val voidBedspaceEntityTwo = Cas3LostBedsEntityFactory() + val voidBedspaceEntityTwo = Cas3VoidBedspacesEntityFactory() .withPremises(premises) .withStartDate(startDate.plusDays(1)) .withEndDate(startDate.plusDays(2)) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withBed( BedEntityFactory().apply { withYieldedRoom { @@ -238,7 +238,7 @@ class Cas3PremisesServiceTest { nonArrivedBookingEntity, cancelledBookingEntity, ) - every { cas3LostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( + every { cas3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( voidBedspaceEntityOne, voidBedspaceEntityTwo, ) @@ -246,12 +246,12 @@ class Cas3PremisesServiceTest { val result = premisesService.getAvailabilityForRange(premises, startDate, endDate) assertThat(result).containsValues( - Availability(date = startDate, pendingBookings = 0, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(1), pendingBookings = 1, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 2), - Availability(date = startDate.plusDays(2), pendingBookings = 1, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 1, lostBeds = 0), - Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 1, lostBeds = 0), + Availability(date = startDate, pendingBookings = 0, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(1), pendingBookings = 1, arrivedBookings = 1, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 2), + Availability(date = startDate.plusDays(2), pendingBookings = 1, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 1, cancelledBookings = 1, voidBedspaces = 0), + Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 1, voidBedspaces = 0), ) } @@ -262,11 +262,11 @@ class Cas3PremisesServiceTest { val premises = temporaryAccommodationPremisesFactory.produce() - val voidBedspaceEntity = Cas3LostBedsEntityFactory() + val voidBedspaceEntity = Cas3VoidBedspacesEntityFactory() .withPremises(premises) .withStartDate(startDate.plusDays(1)) .withEndDate(startDate.plusDays(2)) - .withYieldedReason { Cas3LostBedReasonEntityFactory().produce() } + .withYieldedReason { Cas3VoidBedspaceReasonEntityFactory().produce() } .withBed( BedEntityFactory().apply { withYieldedRoom { @@ -278,26 +278,26 @@ class Cas3PremisesServiceTest { ) .produce() - val voidBedspaceCancellation = Cas3LostBedCancellationEntityFactory() - .withYieldedLostBed { voidBedspaceEntity } + val voidBedspaceCancellation = Cas3VoidBedspaceCancellationEntityFactory() + .withYieldedVoidBedspace { voidBedspaceEntity } .produce() voidBedspaceEntity.cancellation = voidBedspaceCancellation every { bookingRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf() - every { cas3LostBedsRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( + every { cas3VoidBedspacesRepositoryMock.findAllByPremisesIdAndOverlappingDate(premises.id, startDate, endDate) } returns mutableListOf( voidBedspaceEntity, ) val result = premisesService.getAvailabilityForRange(premises, startDate, endDate) assertThat(result).containsValues( - Availability(date = startDate, pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(1), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(2), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), - Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, lostBeds = 0), + Availability(date = startDate, pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(1), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(2), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(3), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(4), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), + Availability(date = startDate.plusDays(5), pendingBookings = 0, arrivedBookings = 0, nonArrivedBookings = 0, cancelledBookings = 0, voidBedspaces = 0), ) } @@ -307,7 +307,7 @@ class Cas3PremisesServiceTest { val reasonId = UUID.randomUUID() - every { cas3LostBedReasonRepositoryMock.findByIdOrNull(reasonId) } returns null + every { cas3VoidBedspaceReasonRepositoryMock.findByIdOrNull(reasonId) } returns null val result = premisesService.createVoidBedspaces( premises = premisesEntity, @@ -332,7 +332,7 @@ class Cas3PremisesServiceTest { val reasonId = UUID.randomUUID() - every { cas3LostBedReasonRepositoryMock.findByIdOrNull(reasonId) } returns Cas3LostBedReasonEntityFactory() + every { cas3VoidBedspaceReasonRepositoryMock.findByIdOrNull(reasonId) } returns Cas3VoidBedspaceReasonEntityFactory() .withServiceScope(ServiceName.approvedPremises.value) .produce() @@ -367,13 +367,13 @@ class Cas3PremisesServiceTest { premisesEntity.rooms += room room.beds += bed - val voidBedspaceReason = Cas3LostBedReasonEntityFactory() + val voidBedspaceReason = Cas3VoidBedspaceReasonEntityFactory() .withServiceScope(ServiceName.temporaryAccommodation.value) .produce() - every { cas3LostBedReasonRepositoryMock.findByIdOrNull(voidBedspaceReason.id) } returns voidBedspaceReason + every { cas3VoidBedspaceReasonRepositoryMock.findByIdOrNull(voidBedspaceReason.id) } returns voidBedspaceReason - every { cas3LostBedsRepositoryMock.save(any()) } answers { it.invocation.args[0] as Cas3LostBedsEntity } + every { cas3VoidBedspacesRepositoryMock.save(any()) } answers { it.invocation.args[0] as Cas3VoidBedspacesEntity } val result = premisesService.createVoidBedspaces( premises = premisesEntity, @@ -401,10 +401,10 @@ class Cas3PremisesServiceTest { val reasonId = UUID.randomUUID() - val voidBedspaceEntity = Cas3LostBedsEntityFactory() + val voidBedspaceEntity = Cas3VoidBedspacesEntityFactory() .withYieldedPremises { premisesEntity } .withYieldedReason { - Cas3LostBedReasonEntityFactory() + Cas3VoidBedspaceReasonEntityFactory() .withServiceScope(ServiceName.temporaryAccommodation.value) .produce() } @@ -419,8 +419,8 @@ class Cas3PremisesServiceTest { ) .produce() - every { cas3LostBedsRepositoryMock.findByIdOrNull(voidBedspaceEntity.id) } returns voidBedspaceEntity - every { cas3LostBedReasonRepositoryMock.findByIdOrNull(reasonId) } returns null + every { cas3VoidBedspacesRepositoryMock.findByIdOrNull(voidBedspaceEntity.id) } returns voidBedspaceEntity + every { cas3VoidBedspaceReasonRepositoryMock.findByIdOrNull(reasonId) } returns null val result = premisesService.updateVoidBedspaces( voidBedspaceId = voidBedspaceEntity.id, @@ -446,10 +446,10 @@ class Cas3PremisesServiceTest { val reasonId = UUID.randomUUID() - val voidBedspaceEntity = Cas3LostBedsEntityFactory() + val voidBedspaceEntity = Cas3VoidBedspacesEntityFactory() .withYieldedPremises { premisesEntity } .withYieldedReason { - Cas3LostBedReasonEntityFactory() + Cas3VoidBedspaceReasonEntityFactory() .withServiceScope(ServiceName.temporaryAccommodation.value) .produce() } @@ -464,8 +464,8 @@ class Cas3PremisesServiceTest { ) .produce() - every { cas3LostBedsRepositoryMock.findByIdOrNull(voidBedspaceEntity.id) } returns voidBedspaceEntity - every { cas3LostBedReasonRepositoryMock.findByIdOrNull(reasonId) } returns Cas3LostBedReasonEntityFactory() + every { cas3VoidBedspacesRepositoryMock.findByIdOrNull(voidBedspaceEntity.id) } returns voidBedspaceEntity + every { cas3VoidBedspaceReasonRepositoryMock.findByIdOrNull(reasonId) } returns Cas3VoidBedspaceReasonEntityFactory() .withServiceScope(ServiceName.approvedPremises.value) .produce() @@ -490,14 +490,14 @@ class Cas3PremisesServiceTest { fun `updateVoidBedspaces returns Success with correct result when validation passed`() { val premisesEntity = temporaryAccommodationPremisesFactory.produce() - val voidBedspaceReason = Cas3LostBedReasonEntityFactory() + val voidBedspaceReason = Cas3VoidBedspaceReasonEntityFactory() .withServiceScope(ServiceName.temporaryAccommodation.value) .produce() - val voidBedspacesEntity = Cas3LostBedsEntityFactory() + val voidBedspacesEntity = Cas3VoidBedspacesEntityFactory() .withYieldedPremises { premisesEntity } .withYieldedReason { - Cas3LostBedReasonEntityFactory() + Cas3VoidBedspaceReasonEntityFactory() .withServiceScope(ServiceName.temporaryAccommodation.value) .produce() } @@ -512,10 +512,10 @@ class Cas3PremisesServiceTest { ) .produce() - every { cas3LostBedsRepositoryMock.findByIdOrNull(voidBedspacesEntity.id) } returns voidBedspacesEntity - every { cas3LostBedReasonRepositoryMock.findByIdOrNull(voidBedspaceReason.id) } returns voidBedspaceReason + every { cas3VoidBedspacesRepositoryMock.findByIdOrNull(voidBedspacesEntity.id) } returns voidBedspacesEntity + every { cas3VoidBedspaceReasonRepositoryMock.findByIdOrNull(voidBedspaceReason.id) } returns voidBedspaceReason - every { cas3LostBedsRepositoryMock.save(any()) } answers { it.invocation.args[0] as Cas3LostBedsEntity } + every { cas3VoidBedspacesRepositoryMock.save(any()) } answers { it.invocation.args[0] as Cas3VoidBedspacesEntity } val result = premisesService.updateVoidBedspaces( voidBedspaceId = voidBedspacesEntity.id, diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3ReportServiceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3ReportServiceTest.kt index 6ae42099d6..9ea7957cf7 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3ReportServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/service/cas3/Cas3ReportServiceTest.kt @@ -11,7 +11,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.UserEntityFactor import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.BookingRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3BookingGapReportRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3FutureBookingsReportRepository -import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3LostBedsRepository +import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.cas3.Cas3VoidBedspacesRepository import uk.gov.justice.digital.hmpps.approvedpremisesapi.model.PersonSummaryInfoResult import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.BookingsReportProperties import uk.gov.justice.digital.hmpps.approvedpremisesapi.reporting.properties.TransitionalAccommodationReferralReportProperties @@ -37,7 +37,7 @@ class Cas3ReportServiceTest { private val mockTransitionalAccommodationReferralReportRowRepository = mockk() private val mockBookingsReportRepository = mockk() - private val mockLostBedsRepository = mockk() + private val mockLostBedsRepository = mockk() private val mockBookingTransformer = mockk() private val mockWorkingDayService = mockk() private val mockBookingRepository = mockk() diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/Cas3LostBedsTransformerTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/Cas3VoidBedspacesTransformerTest.kt similarity index 53% rename from src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/Cas3LostBedsTransformerTest.kt rename to src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/Cas3VoidBedspacesTransformerTest.kt index 5644ca0856..5acebeb54a 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/Cas3LostBedsTransformerTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/unit/transformer/Cas3VoidBedspacesTransformerTest.kt @@ -13,19 +13,19 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.LocalAuthorityEn import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationRegionEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.RoomEntityFactory import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.TemporaryAccommodationPremisesEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedCancellationEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedReasonEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3LostBedsEntityFactory -import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedCancellationTransformer -import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedReasonTransformer -import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3LostBedsTransformer +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceCancellationEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspaceReasonEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.cas3.Cas3VoidBedspacesEntityFactory +import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspaceCancellationTransformer +import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspaceReasonTransformer +import uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas3.Cas3VoidBedspacesTransformer import java.time.Instant -class Cas3LostBedsTransformerTest { - private val cas3LostBedReasonTransformer = mockk() - private val cas3LostBedCancellationTransformer = mockk() +class Cas3VoidBedspacesTransformerTest { + private val cas3VoidBedspaceReasonTransformer = mockk() + private val cas3VoidBedspaceCancellationTransformer = mockk() - private val cas3LostBedsTransformer = Cas3LostBedsTransformer(cas3LostBedReasonTransformer, cas3LostBedCancellationTransformer) + private val cas3VoidBedspacesTransformer = Cas3VoidBedspacesTransformer(cas3VoidBedspaceReasonTransformer, cas3VoidBedspaceCancellationTransformer) val premises = TemporaryAccommodationPremisesEntityFactory() .withYieldedProbationRegion { @@ -50,9 +50,9 @@ class Cas3LostBedsTransformerTest { .withYieldedRoom { room } .produce() - private val lostBed = Cas3LostBedsEntityFactory() + private val voidBedspace = Cas3VoidBedspacesEntityFactory() .withYieldedReason { - Cas3LostBedReasonEntityFactory() + Cas3VoidBedspaceReasonEntityFactory() .produce() } .withYieldedPremises { premises } @@ -60,22 +60,22 @@ class Cas3LostBedsTransformerTest { .produce() @Test - fun `Lost Bed entity is correctly transformed`() { - every { cas3LostBedReasonTransformer.transformJpaToApi(lostBed.reason) } returns LostBedReason( - id = lostBed.reason.id, - name = lostBed.reason.name, + fun `Void Bedspace entity is correctly transformed`() { + every { cas3VoidBedspaceReasonTransformer.transformJpaToApi(voidBedspace.reason) } returns LostBedReason( + id = voidBedspace.reason.id, + name = voidBedspace.reason.name, isActive = true, serviceScope = "approved-premises", ) - val result = cas3LostBedsTransformer.transformJpaToApi(lostBed) + val result = cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspace) - assertThat(result.id).isEqualTo(lostBed.id) - assertThat(result.startDate).isEqualTo(lostBed.startDate) - assertThat(result.endDate).isEqualTo(lostBed.endDate) - assertThat(result.reason.id).isEqualTo(lostBed.reason.id) - assertThat(result.notes).isEqualTo(lostBed.notes) - assertThat(result.referenceNumber).isEqualTo(lostBed.referenceNumber) + assertThat(result.id).isEqualTo(voidBedspace.id) + assertThat(result.startDate).isEqualTo(voidBedspace.startDate) + assertThat(result.endDate).isEqualTo(voidBedspace.endDate) + assertThat(result.reason.id).isEqualTo(voidBedspace.reason.id) + assertThat(result.notes).isEqualTo(voidBedspace.notes) + assertThat(result.referenceNumber).isEqualTo(voidBedspace.referenceNumber) assertThat(result.status).isEqualTo(LostBedStatus.active) assertThat(result.cancellation).isNull() assertThat(result.bedId).isEqualTo(bed.id) @@ -84,38 +84,38 @@ class Cas3LostBedsTransformerTest { } @Test - fun `A cancelled lost bed entity is correctly transformed`() { - val lostBedCancellation = Cas3LostBedCancellationEntityFactory() - .withYieldedLostBed { lostBed } + fun `A cancelled void bedspace entity is correctly transformed`() { + val lostBedCancellation = Cas3VoidBedspaceCancellationEntityFactory() + .withYieldedVoidBedspace { voidBedspace } .produce() - lostBed.cancellation = lostBedCancellation + voidBedspace.cancellation = lostBedCancellation - every { cas3LostBedReasonTransformer.transformJpaToApi(lostBed.reason) } returns LostBedReason( - id = lostBed.reason.id, - name = lostBed.reason.name, + every { cas3VoidBedspaceReasonTransformer.transformJpaToApi(voidBedspace.reason) } returns LostBedReason( + id = voidBedspace.reason.id, + name = voidBedspace.reason.name, isActive = true, serviceScope = "approved-premises", ) val now = Instant.now() - every { cas3LostBedCancellationTransformer.transformJpaToApi(lostBed.cancellation!!) } returns LostBedCancellation( - id = lostBed.cancellation!!.id, + every { cas3VoidBedspaceCancellationTransformer.transformJpaToApi(voidBedspace.cancellation!!) } returns LostBedCancellation( + id = voidBedspace.cancellation!!.id, createdAt = now, notes = "Some notes", ) - val result = cas3LostBedsTransformer.transformJpaToApi(lostBed) + val result = cas3VoidBedspacesTransformer.transformJpaToApi(voidBedspace) - assertThat(result.id).isEqualTo(lostBed.id) - assertThat(result.startDate).isEqualTo(lostBed.startDate) - assertThat(result.endDate).isEqualTo(lostBed.endDate) - assertThat(result.reason.id).isEqualTo(lostBed.reason.id) - assertThat(result.notes).isEqualTo(lostBed.notes) - assertThat(result.referenceNumber).isEqualTo(lostBed.referenceNumber) + assertThat(result.id).isEqualTo(voidBedspace.id) + assertThat(result.startDate).isEqualTo(voidBedspace.startDate) + assertThat(result.endDate).isEqualTo(voidBedspace.endDate) + assertThat(result.reason.id).isEqualTo(voidBedspace.reason.id) + assertThat(result.notes).isEqualTo(voidBedspace.notes) + assertThat(result.referenceNumber).isEqualTo(voidBedspace.referenceNumber) assertThat(result.status).isEqualTo(LostBedStatus.cancelled) assertThat(result.cancellation).isNotNull - assertThat(result.cancellation!!.id).isEqualTo(lostBed.cancellation!!.id) + assertThat(result.cancellation!!.id).isEqualTo(voidBedspace.cancellation!!.id) assertThat(result.cancellation!!.createdAt).isEqualTo(now) assertThat(result.cancellation!!.notes).isEqualTo("Some notes") assertThat(result.bedId).isEqualTo(bed.id)