Add unit tests for ProcessDueRecurringExpenses #15
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
PR #10 (
feat/3-implement-recurring-interactors) ships the recurring interactors with./gradlew assembleDebugas the only verification.ProcessDueRecurringExpenses.awaithas several non-trivial behaviors that warrant tests:isActive = 1filter ingetDue(today)(app/src/main/java/dev/achmad/ledgerr/data/local/dao/RecurringExpenseDao.kt:34-35)<= todayboundary (templates due today are processed, not just past-due ones)nextDueDatebyinterval.advance(...)docs/03-function-todos.md:138: "if the app has not been opened for multiple intervals, advancenextDueDateby one interval per call" (no back-fill flooding)recurringExpenseIdlink on the createdExpensematches the source template's id0L)These are the kinds of things an in-memory Room test would catch cheaply.
What to do
androidx.room:room-testingtoapp/build.gradle.ktsdependencies (testImplementation).app/src/test/java/dev/achmad/ledgerr/domain/recurring/interactor/ProcessDueRecurringExpensesTest.ktwith cases:await_createsOneExpenseAndAdvancesNextDueDate_whenTemplateDueTodayawait_returnsEmptyList_whenNoTemplatesDueawait_skipsInactiveTemplatesawait_advancesByOneIntervalOnly_evenIfMultiplePeriodsOverdue(the edge case)await_linksCreatedExpenseToTemplateIdawait_processesAllIntervals_dailyWeeklyMonthlyYearly(parameterized)Room.inMemoryDatabaseBuilderto build an in-memoryAppDatabaseper test. Pre-seed one default category so foreign-key constraints onexpensesare satisfied../gradlew testpasses.Notes
withTransactionfix (separate issue). Re-run these tests after that fix lands to confirm the transaction does not change observable behavior.RecurringExpensethrough Room callbacks — directdao.insert(...)is fine.Acceptance
ProcessDueRecurringExpensesTestcovers the cases above./gradlew testpasseswithTransactionfix landsImplementation rule
Per
AGENTS.md— do not start implementation without explicit user sign-off on this issue. When working, check for related issues in the remote repo first.Closing — addressed as a review comment on PR #10 (#10) instead of a separate issue.