Skip to content

Commit

Permalink
fix: [ANDROAPP-5803/5630] ignore deleted events on schedule creation (#…
Browse files Browse the repository at this point in the history
…3458)

* fix: [ANDROAPP-5803] ignore deleted events on schedule creation

* lint

* unit test
  • Loading branch information
mmmateos authored Jan 15, 2024
1 parent fad8dc2 commit 87cd3d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ class EventDetailsRepository(
val activeEvents =
d2.eventModule().events().byEnrollmentUid().eq(enrollmentUid).byProgramStageUid()
.eq(programStageUid)
.byDeleted().isFalse
.orderByEventDate(RepositoryScope.OrderByDirection.DESC).blockingGet()
val scheduleEvents =
d2.eventModule().events().byEnrollmentUid().eq(enrollmentUid).byProgramStageUid()
.eq(programStageUid)
.byDeleted().isFalse
.orderByDueDate(RepositoryScope.OrderByDirection.DESC).blockingGet()

var activeDate: Date? = null
Expand All @@ -88,7 +90,12 @@ class EventDetailsRepository(
}
if (scheduleEvents.isNotEmpty()) scheduleDate = scheduleEvents[0].dueDate()

return activeDate ?: scheduleDate
return when {
scheduleDate == null -> activeDate
activeDate == null -> scheduleDate
activeDate.before(scheduleDate) -> scheduleDate
else -> activeDate
}
}

fun hasAccessDataWrite(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,27 @@ class EventDetailsRepositoryTest {
d2.eventModule().events()
.byEnrollmentUid().eq(ENROLLMENT_UID)
.byProgramStageUid().eq(PROGRAM_STAGE_UID)
.byDeleted(),
) doReturn mock()
whenever(
d2.eventModule().events()
.byEnrollmentUid().eq(ENROLLMENT_UID)
.byProgramStageUid().eq(PROGRAM_STAGE_UID)
.byDeleted().isFalse,
) doReturn mock()
whenever(
d2.eventModule().events()
.byEnrollmentUid().eq(ENROLLMENT_UID)
.byProgramStageUid().eq(PROGRAM_STAGE_UID)
.byDeleted().isFalse
.orderByEventDate(DESC),
) doReturn mock()

whenever(
d2.eventModule().events()
.byEnrollmentUid().eq(ENROLLMENT_UID)
.byProgramStageUid().eq(PROGRAM_STAGE_UID)
.byDeleted().isFalse
.orderByDueDate(DESC),
) doReturn mock()
}
Expand Down Expand Up @@ -97,13 +111,15 @@ class EventDetailsRepositoryTest {
d2.eventModule().events()
.byEnrollmentUid().eq(ENROLLMENT_UID)
.byProgramStageUid().eq(PROGRAM_STAGE_UID)
.byDeleted().isFalse
.orderByEventDate(DESC)
.blockingGet(),
) doReturn listOf(event)
whenever(
d2.eventModule().events()
.byEnrollmentUid().eq(ENROLLMENT_UID)
.byProgramStageUid().eq(PROGRAM_STAGE_UID)
.byDeleted().isFalse
.orderByDueDate(DESC)
.blockingGet(),
) doReturn emptyList()
Expand All @@ -120,13 +136,15 @@ class EventDetailsRepositoryTest {
d2.eventModule().events()
.byEnrollmentUid().eq(ENROLLMENT_UID)
.byProgramStageUid().eq(PROGRAM_STAGE_UID)
.byDeleted().isFalse
.orderByEventDate(DESC)
.blockingGet(),
) doReturn emptyList()
whenever(
d2.eventModule().events()
.byEnrollmentUid().eq(ENROLLMENT_UID)
.byProgramStageUid().eq(PROGRAM_STAGE_UID)
.byDeleted().isFalse
.orderByDueDate(DESC)
.blockingGet(),
) doReturn listOf(event)
Expand Down

0 comments on commit 87cd3d8

Please sign in to comment.