Skip to content

Commit db378bc

Browse files
test(slots): make the empty-dates notice assertion clock-safe
Review catch on #23. The test asked for a window starting tomorrow with a one-minute minimum notice and asserted that nothing was withheld. But seedNoticeEventType opens availability at 00:00, so tomorrow's first slot is midnight, and in the last minute of a UTC day the cutoff lands past it (now 23:59:01 → cutoff 00:00:01). That slot is then correctly withheld, dates is non-empty, and the test fails — roughly 59 seconds a day, for a reason unrelated to what it is asserting. Starts the window at +2 days instead. Every candidate slot is then at least 24 hours beyond any cutoff a one-minute policy can produce, whatever the clock says, which is the property the file header promises for all of these. Verified: TestGetSlots_minNoticeDatesEmptyWhenThePolicyCostThisRangeNothing and TestGetSlots_minNoticeDatesUseTheRequestedTimezone both pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 8228988 commit db378bc

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

internal/handler/slots_notice_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,23 @@ func TestGetSlots_omitsMinNoticeWhenThereIsNoPolicy(t *testing.T) {
103103
}
104104

105105
func TestGetSlots_minNoticeDatesEmptyWhenThePolicyCostThisRangeNothing(t *testing.T) {
106-
// A one-minute notice, asked about days that start tomorrow: the policy exists and is
107-
// reported, but it took nothing away in this window, so nothing should be explained.
106+
// A one-minute notice, asked about days that start the day after tomorrow: the policy
107+
// exists and is reported, but it took nothing away in this window, so nothing should
108+
// be explained.
109+
//
110+
// ⚠️ The window deliberately starts at +2 days, not +1. seedNoticeEventType opens
111+
// availability at 00:00, so tomorrow's first slot is midnight — and in the last minute
112+
// of a UTC day a one-minute notice pushes the cutoff past it (now 23:59:01 → cutoff
113+
// 00:00:01), withholding that slot and making dates non-empty. That is a real ~59
114+
// seconds a day where this test would fail for a reason unrelated to what it asserts.
115+
// Starting a full day later puts every candidate slot at least 24 hours beyond any
116+
// cutoff a one-minute policy can produce, whatever the clock says.
108117
h, database, _, ownerID := setupWorkspaceWithDB(t)
109118
seedNoticeEventType(t, database, ownerID, "tiny-notice", 1)
110119

111120
now := time.Now().UTC()
112-
from := now.AddDate(0, 0, 1).Format("2006-01-02")
113-
to := now.AddDate(0, 0, 3).Format("2006-01-02")
121+
from := now.AddDate(0, 0, 2).Format("2006-01-02")
122+
to := now.AddDate(0, 0, 4).Format("2006-01-02")
114123
got := getSlots(t, h, "tiny-notice", "?from="+from+"&to="+to+"&tz=UTC")
115124

116125
if got.MinNotice == nil {

0 commit comments

Comments
 (0)