Skip to content

Commit

Permalink
e2e test fixes and integration tests for category matching and non-re…
Browse files Browse the repository at this point in the history
…servation units
  • Loading branch information
tmkrepo committed Sep 30, 2024
1 parent cd92441 commit 88ea4ec
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ beforeEach(async () => {

await Fixture.absence({
absenceType: 'OTHER_ABSENCE',
absenceCategory: 'NONBILLABLE',
absenceCategory: 'BILLABLE',
date: mockedToday,
childId: child.id
}).save()
Expand All @@ -90,7 +90,7 @@ beforeEach(async () => {
}).save()
await Fixture.absence({
absenceType: 'OTHER_ABSENCE',
absenceCategory: 'NONBILLABLE',
absenceCategory: 'BILLABLE',
date: mockedToday.addDays(4),
childId: child.id
}).save()
Expand All @@ -113,7 +113,7 @@ describe('Holiday period attendance report', () => {
date: 'Ma 09.09.2024',
presentChildren: [],
assistanceChildren: [],
coefficientSum: '0',
coefficientSum: '0,00',
staffCount: '0',
absenceCount: '1',
noResponseChildren: []
Expand All @@ -122,7 +122,7 @@ describe('Holiday period attendance report', () => {
date: 'Ti 10.09.2024',
presentChildren: [childName],
assistanceChildren: [childName],
coefficientSum: '4.38',
coefficientSum: '4,38',
staffCount: '1',
absenceCount: '0',
noResponseChildren: []
Expand All @@ -131,7 +131,7 @@ describe('Holiday period attendance report', () => {
date: 'Ke 11.09.2024',
presentChildren: [],
assistanceChildren: [],
coefficientSum: '0',
coefficientSum: '0,00',
staffCount: '0',
absenceCount: '0',
noResponseChildren: [childName]
Expand All @@ -140,7 +140,7 @@ describe('Holiday period attendance report', () => {
date: 'To 12.09.2024',
presentChildren: [childName],
assistanceChildren: [childName],
coefficientSum: '4.38',
coefficientSum: '4,38',
staffCount: '1',
absenceCount: '0',
noResponseChildren: []
Expand All @@ -149,7 +149,7 @@ describe('Holiday period attendance report', () => {
date: 'Pe 13.09.2024',
presentChildren: [],
assistanceChildren: [],
coefficientSum: '0',
coefficientSum: '0,00',
staffCount: '0',
absenceCount: '1',
noResponseChildren: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export default React.memo(function HolidayPeriodAttendanceReport() {
const daycareOptions = useMemo(
() =>
units.map((d) => {
return orderBy(d, (item) => item.name)
return orderBy(
d.filter((u) => u.enabledPilotFeatures.includes('RESERVATIONS')),
(item) => item.name
)
}),
[units]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ import fi.espoo.evaka.shared.domain.MockEvakaClock
import fi.espoo.evaka.shared.domain.TimeRange
import fi.espoo.evaka.shared.security.PilotFeature
import fi.espoo.evaka.snDaycareFullDay35
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalTime
import java.util.UUID
import kotlin.test.assertEquals
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.fail
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.springframework.beans.factory.annotation.Autowired
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalTime
import java.util.UUID
import kotlin.test.assertEquals

class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach = true) {
@Autowired private lateinit var holidayPeriodAttendanceReport: HolidayPeriodAttendanceReport
Expand Down Expand Up @@ -94,6 +94,44 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
assertThat(results.isNotEmpty())
}

@Test
fun `Report for unit without RESERVATIONS feature not available`() {
val daycareId = DaycareId(UUID.randomUUID())
val monday = holidayPeriod.period.start
db.transaction { tx ->
tx.insertServiceNeedOptions()
tx.insert(holidayPeriod)
tx.insert(admin)
tx.insert(unitSupervisorA)

val areaAId = tx.insert(DevCareArea(name = "Area A", shortName = "Area A"))
tx.insert(
DevDaycare(
id = daycareId,
name = "Daycare without RESERVATIONS",
areaId = areaAId,
openingDate = monday.minusDays(7),
type = setOf(CareType.CENTRE),
operationTimes =
List(5) { TimeRange(LocalTime.of(8, 0), LocalTime.of(18, 0)) } +
List(2) { null },
enabledPilotFeatures = emptySet(),
)
)
tx.insertDaycareAclRow(daycareId, unitSupervisorA.id, UserRole.UNIT_SUPERVISOR)
}

assertThrows<Forbidden> {
holidayPeriodAttendanceReport.getHolidayPeriodAttendanceReport(
dbInstance(),
mockClock,
unitSupervisorA.user,
daycareId,
holidayPeriod.id,
)
}
}

@Test
fun `Admin can see report results`() {
val testUnitData = initTestUnitData(holidayPeriod.period.start)
Expand Down Expand Up @@ -174,11 +212,14 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach

val expectedMonday =
HolidayPeriodAttendanceReportRow(
absentCount = 3,
absentCount = 2,
requiredStaff = 0,
presentChildren = emptyList(),
assistanceChildren = emptyList(),
noResponseChildren = emptyList(),
noResponseChildren =
listOf(testData[1].first).map {
ChildWithName(it.id, it.firstName, it.lastName)
},
date = holidayPeriod.period.start,
presentOccupancyCoefficient = 0.0,
)
Expand Down Expand Up @@ -238,7 +279,10 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
listOf(testData[2].first).map {
ChildWithName(it.id, it.firstName, it.lastName)
},
assistanceChildren = emptyList(),
assistanceChildren =
listOf(testData[2].first).map {
ChildWithName(it.id, it.firstName, it.lastName)
},
noResponseChildren = emptyList(),
date = holidayPeriod.period.start.plusDays(4),
presentOccupancyCoefficient = 5.5,
Expand Down Expand Up @@ -274,11 +318,14 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach

val expectedMonday =
HolidayPeriodAttendanceReportRow(
absentCount = 3,
absentCount = 2,
requiredStaff = 0,
presentChildren = emptyList(),
assistanceChildren = emptyList(),
noResponseChildren = emptyList(),
noResponseChildren =
listOf(testData[1].first).map {
ChildWithName(it.id, it.firstName, it.lastName)
},
date = monday,
presentOccupancyCoefficient = 0.0,
)
Expand Down Expand Up @@ -427,11 +474,14 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach

val expectedMonday =
HolidayPeriodAttendanceReportRow(
absentCount = 4,
absentCount = 3,
requiredStaff = 0,
presentChildren = emptyList(),
assistanceChildren = emptyList(),
noResponseChildren = emptyList(),
noResponseChildren =
listOf(testData[1].first).map {
ChildWithName(it.id, it.firstName, it.lastName)
},
date = monday,
presentOccupancyCoefficient = 0.0,
)
Expand Down Expand Up @@ -488,7 +538,10 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
listOf(testData[2].first).map {
ChildWithName(it.id, it.firstName, it.lastName)
},
assistanceChildren = emptyList(),
assistanceChildren =
listOf(testData[2].first).map {
ChildWithName(it.id, it.firstName, it.lastName)
},
noResponseChildren = emptyList(),
date = monday.plusDays(4),
presentOccupancyCoefficient = 5.5,
Expand Down Expand Up @@ -640,7 +693,7 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
val placementB =
DevPlacement(
id = PlacementId(UUID.randomUUID()),
type = PlacementType.DAYCARE,
type = PlacementType.PRESCHOOL_DAYCARE,
childId = testChildBertil.id,
unitId = daycareId,
startDate = defaultPlacementDuration.start,
Expand Down Expand Up @@ -680,10 +733,10 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
)
)

// Monday - everyone is absent
// Monday - everyone is absent, but Bertil has a missing absence category -> no response

listOf(testChildAapo, testChildBertil, testChildCecil, testChildVille).forEach {
createOtherAbsence(monday, it.id, tx)
createOtherAbsence(monday, it.id, AbsenceCategory.BILLABLE, tx)
}

// Tuesday - everyone is present
Expand All @@ -692,21 +745,23 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
createNullReservation(tuesday, it.id, tx)
}

// Wednesday - only Aapo has answered
// Wednesday - only Aapo present, 3 no responses

createNullReservation(wednesday, testChildAapo.id, tx)

// Thursday - 2 present, 1 absent
// Thursday - 2 no response, 1 absent

listOf(testChildAapo, testChildBertil).forEach {
createNullReservation(thursday, it.id, tx)
}
createOtherAbsence(thursday, testChildCecil.id, tx)
createOtherAbsence(thursday, testChildCecil.id, AbsenceCategory.BILLABLE, tx)

// Friday - 1 present, 2 (+ bc Ville) absent
// Friday - Cecil present, 2 (+ bc Ville) absent
listOf(testChildAapo, testChildBertil, testChildVille).forEach {
createOtherAbsence(friday, it.id, tx)
createOtherAbsence(friday, it.id, AbsenceCategory.BILLABLE, tx)
}
createOtherAbsence(friday, testChildBertil.id, AbsenceCategory.NONBILLABLE, tx)

createNullReservation(friday, testChildCecil.id, tx)

// Saturday - 1 present
Expand Down Expand Up @@ -774,7 +829,12 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
)
)

private fun createOtherAbsence(date: LocalDate, childId: PersonId, tx: Database.Transaction) =
private fun createOtherAbsence(
date: LocalDate,
childId: PersonId,
category: AbsenceCategory,
tx: Database.Transaction,
) =
tx.insert(
DevAbsence(
id = AbsenceId(UUID.randomUUID()),
Expand All @@ -783,7 +843,7 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
AbsenceType.OTHER_ABSENCE,
HelsinkiDateTime.atStartOfDay(date),
EvakaUserId(admin.id.raw),
AbsenceCategory.BILLABLE,
category,
)
)

Expand All @@ -794,11 +854,13 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
assertEquals(expected.date, actual.date)
assertEquals(expected.absentCount, actual.absentCount, "${actual.date}: absentCount")
assertThat(actual.presentChildren)
.describedAs("${actual.date}: presentChildren")
.containsExactlyInAnyOrderElementsOf(expected.presentChildren)
.withFailMessage("${actual.date}: presentChildren")

assertThat(actual.assistanceChildren)
.describedAs("${actual.date}: assistanceChildren")
.containsExactlyInAnyOrderElementsOf(expected.assistanceChildren)
.withFailMessage("${actual.date}: assistanceChildren")

assertEquals(
expected.presentOccupancyCoefficient,
actual.presentOccupancyCoefficient,
Expand All @@ -810,7 +872,7 @@ class HolidayPeriodAttendanceReportTest : FullApplicationTest(resetDbBeforeEach
"${actual.date}: staffRequirement",
)
assertThat(actual.noResponseChildren)
.withFailMessage("${actual.date}: noResponseChildren")
.describedAs("${actual.date}: noResponseChildren")
.containsExactlyInAnyOrderElementsOf(expected.noResponseChildren)
}
}

0 comments on commit 88ea4ec

Please sign in to comment.