Skip to content

Commit

Permalink
Allow rooms to have multiple beds.
Browse files Browse the repository at this point in the history
  • Loading branch information
danhumphreys-moj committed Dec 20, 2024
1 parent 633728b commit 5dc6481
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class ApprovedPremisesRoomsSeedFromXLSXJob(
val roomAnswers = dataFrame.getColumn(i)
val room = buildRoom(premisesId, roomCode = "$qCode - ${roomAnswers[0]}", roomName = roomAnswers[0].toString())

rooms.add(room)
if (rooms.none { it.code == room.code }) rooms.add(room)
}
return rooms
}

private fun buildCharacteristics(dataFrame: DataFrame<*>): MutableMap<String, MutableList<CharacteristicEntity>> {
var premisesCharacteristics = mutableMapOf<String, MutableList<CharacteristicEntity>>()
private fun buildCharacteristics(dataFrame: DataFrame<*>): MutableMap<String, MutableSet<CharacteristicEntity>> {
var premisesCharacteristics = mutableMapOf<String, MutableSet<CharacteristicEntity>>()

questionCriteriaMapping.questionToCharacterEntityMapping.forEach { (question, characteristic) ->
val rowId = dataFrame.getColumn(0).values().indexOf(question)
Expand All @@ -74,7 +74,7 @@ class ApprovedPremisesRoomsSeedFromXLSXJob(
val answer = dataFrame[rowId][colId].toString().trim()

if (answer.equals("yes", ignoreCase = true)) {
premisesCharacteristics.computeIfAbsent(roomCode) { mutableListOf() }.add(characteristic!!)
premisesCharacteristics.computeIfAbsent(roomCode) { mutableSetOf() }.add(characteristic!!)
} else if (!answer.equals("no", ignoreCase = true) && !answer.equals("N/A", ignoreCase = true)) {
throw SiteSurveyImportException("Expecting 'yes' or 'no' for question '$question' but is '$answer' on sheet Sheet3 (row = ${rowId + 1}, col = $colId).")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SeedFromXLSXApprovedPremisesRoomsTest : SeedTestBase() {
}

@Test
fun `Creating three new rooms and new beds with a characteristic succeeds`() {
fun `Creating three new rooms and three new beds with a characteristic succeeds`() {
val localAuthorityArea = localAuthorityEntityFactory.produceAndPersist()
val probationRegion = probationRegionEntityFactory.produceAndPersist()
val qCode = "Q999"
Expand Down Expand Up @@ -146,6 +146,72 @@ class SeedFromXLSXApprovedPremisesRoomsTest : SeedTestBase() {
)
}

@Test
fun `Creating two new rooms and three new beds with a characteristic succeeds`() {
val localAuthorityArea = localAuthorityEntityFactory.produceAndPersist()
val probationRegion = probationRegionEntityFactory.produceAndPersist()
val qCode = "Q999"
val premises = approvedPremisesEntityFactory.produceAndPersist {
withLocalAuthorityArea(localAuthorityArea)
withProbationRegion(probationRegion)
withQCode(qCode)
}
val premisesId = premises.id

val header = listOf("Unique Reference Number for Bed", "SWABI01NEW", "SWABI02NEW", "SWABI03NEW")
val rows = mutableListOf(
"Room Number / Name",
"1",
"2",
"2",
"Bed Number (in this room i.e if this is a single room insert 1. If this is a shared room separate entries will need to be made for bed 1 and bed 2)",
"1",
"1",
"2",
)
rows.addCharacteristics(3, mapOf("Is this room located on the ground floor?" to listOf(1, 2)))

val dataFrame = dataFrameOf(header, rows)

withXlsx("example", "Sheet3", dataFrame)

seedService.seedExcelData(
SeedFromExcelFileType.approvedPremisesRoom,
premisesId,
"example.xlsx",
)

val room1 = roomRepository.findByCode("Q999 - 1")
assertThat(room1!!.characteristics).isEmpty()

val bed1 = bedRepository.findByCodeAndRoomId("SWABI01NEW", room1.id)
assertThat(bed1!!.name).isEqualTo("1")
assertThat(
bed1.room.id == room1.id &&
bed1.room.code == "Q999 - 1",
)

val room2 = roomRepository.findByCode("Q999 - 2")
assertThat(room2!!.characteristics).anyMatch {
it.name == "Is this room located on the ground floor?" &&
it.propertyName == "isGroundFloor"
}

val bed2 = bedRepository.findByCodeAndRoomId("SWABI02NEW", room2.id)
assertThat(bed2!!.name).isEqualTo("1")
assertThat(
bed2.room.id == room2.id &&
bed2.room.code == "Q999 - 2",
)

val bed3 = bedRepository.findByCodeAndRoomId("SWABI03NEW", room2.id)
assertThat(bed3!!.name).isEqualTo("2")
assertThat(
bed3.room.id == room2.id &&
bed3.room.code == "Q999 - 2",
)
}

@Test
fun `Creating a new room and a new bed without a characteristic succeeds`() {
val localAuthorityArea = localAuthorityEntityFactory.produceAndPersist()
Expand Down

0 comments on commit 5dc6481

Please sign in to comment.