fix(chores): only block a bonus claim on bonus chores due today - #158
Merged
Conversation
Claiming a bonus chore was refused with "User already has an uncompleted bonus chore" whenever the user had bonus chores assigned for other days of the week, even with every bonus chore actually due today complete. assignBonusChore built its blocking set from every visible schedule with clam_value > 0, with no due-today filter, while `schedules` comes from /api/chore-schedules?usage=chart — every visible schedule regardless of crontab. A Monday-only chore therefore counted as outstanding on a Sunday. This is not intermittent: a user whose bonus chores span the week always has some that are not due, so the gate fires every day and the claim path is unreachable. Extract the rule to hasOutstandingBonusChore() in choreHelpers, which filters through shouldShowChoreToday — the same predicate the widget renders with, so the gate and the visible list cannot disagree — and cover it with unit tests. The one-bonus-at-a-time rule itself is unchanged; only the set it is evaluated against.
Collaborator
|
Preserves the intent of only doing 1 bonus chore at a time. Approved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claiming a bonus chore is refused with "User already has an uncompleted bonus chore. Complete it first!" when the user has bonus chores assigned for other days of the week, even though every bonus chore actually due today is complete.
Cause
assignBonusChore()builds its blocking set with no due-today filter:schedulescomes from/api/chore-schedules?usage=chart— every visible schedule regardless ofcrontab— so a Monday-only chore counts as outstanding on a Sunday.The filter is right about which chores are bonus chores (
clam_value > 0, matching the server's own test that a regular chore isclam_value === 0) and wrong about when they are outstanding.This is not intermittent. A user whose bonus chores span the week always has some that are not due, so the gate fires every day and the claim path becomes unreachable. On the install where this was found, one child had bonus chores on Mon/Tue/Wed/Thu/Fri and could not claim on any day.
The inverse also holds: regular chores that are outstanding are invisible to the gate, since they are
clam_value 0. It blocks on chores that are not due and ignores chores that are.Fix
shouldShowChoreToday()already implements the due-today predicate — cron replay in the server timezone, plus snooze handling — andChoreWidgetalready imports it and renders with it.This extracts the rule into
hasOutstandingBonusChore()inchoreHelpers.js, filtering through that same predicate, so the gate and the visible list cannot disagree. The component's inline block collapses to one call.The one-bonus-at-a-time rule itself is unchanged — only the set it is evaluated against.
Tests
Seven unit cases on the new helper: not-due chore does not block, due-and-uncompleted does, the reported case (due-today complete + other weekdays outstanding) does not, plus regular chores, other users, hidden schedules, and a one-off with no crontab.
Client suite: 167 passing (160 + 7). i18n parity unchanged; no new strings.
One test carries a comment worth noting for reviewers: cases are chosen to avoid the day immediately after "today", because
shouldShowChoreTodaycompares a cron occurrence resolved in the server zone against local midnight. When the two differ, tomorrow-00:00 can land on today's local date. That is a pre-existing timezone issue, unrelated to this change, and not addressed here.