Skip to content

Commit b93a0a3

Browse files
committed
fix(sync): use relative dates in calendar delta tests so they don't drift past lookback
TestSyncCalendarUpsertsAndDeletesEvents and TestSyncCalendar410ResetsAndReFetches hardcoded `2026-05-01` for the seeded / upserted event start times. The default [sync].calendar_lookback_days is 7, so once `time.Now()` advances past 2026-05-08 the prune step (DeleteEventsBefore(start)) deletes the events immediately after upsert and the assertions fall over. Switch both tests to compute the event start from `time.Now().UTC().Add(time.Hour)` — the same shape TestSyncCalendarPrunesOldEvents already uses for relative fixtures. The Graph delta payload's `dateTime` strings are formatted from the same value so the upsert path lands inside the window. Pre-existing failure on origin/main; surfaced while preparing v0.56.1 release.
1 parent 70f8d86 commit b93a0a3

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

internal/sync/calendar_sync_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ import (
1919
func TestSyncCalendarUpsertsAndDeletesEvents(t *testing.T) {
2020
eng, srv, st, acc := newSyncTest(t)
2121

22-
// Pre-seed an event that the delta response will @remove.
23-
now := time.Date(2026, 5, 1, 10, 0, 0, 0, time.UTC)
22+
// Pre-seed an event that the delta response will @remove. Use a
23+
// time inside the default lookback window (now is the conservative
24+
// choice — the prune step deletes events strictly older than
25+
// truncateToDay(now) - lookbackDays).
26+
inWindow := time.Now().UTC().Add(time.Hour)
2427
require.NoError(t, st.PutEvent(context.Background(), store.Event{
25-
ID: "ev-stale", AccountID: acc, Start: now, End: now.Add(time.Hour),
28+
ID: "ev-stale", AccountID: acc, Start: inWindow, End: inWindow.Add(time.Hour),
2629
}))
2730

31+
freshStart := inWindow.Format("2006-01-02T15:04:05.0000000")
32+
freshEnd := inWindow.Add(time.Hour).Format("2006-01-02T15:04:05.0000000")
2833
srv.Handle("/me/calendarView/delta", func(w http.ResponseWriter, _ *http.Request) {
2934
resp := map[string]any{
3035
"value": []map[string]any{
3136
{
3237
"id": "ev-new", "subject": "Fresh event",
33-
"start": map[string]any{"dateTime": "2026-05-01T10:00:00.0000000"},
34-
"end": map[string]any{"dateTime": "2026-05-01T11:00:00.0000000"},
38+
"start": map[string]any{"dateTime": freshStart},
39+
"end": map[string]any{"dateTime": freshEnd},
3540
"isAllDay": false,
3641
"organizer": map[string]any{
3742
"emailAddress": map[string]any{"name": "Bob", "address": "bob@example.invalid"},
@@ -68,6 +73,12 @@ func TestSyncCalendarUpsertsAndDeletesEvents(t *testing.T) {
6873
func TestSyncCalendar410ResetsAndReFetches(t *testing.T) {
6974
eng, srv, st, acc := newSyncTest(t)
7075

76+
// Use a time inside the default lookback window so the event is not
77+
// pruned right after upsert when the test runs on a date past the
78+
// hardcoded fixture date.
79+
inWindow := time.Now().UTC().Add(time.Hour)
80+
freshStart := inWindow.Format("2006-01-02T15:04:05.0000000")
81+
freshEnd := inWindow.Add(time.Hour).Format("2006-01-02T15:04:05.0000000")
7182
callCount := 0
7283
srv.Handle("/me/calendarView/delta", func(w http.ResponseWriter, _ *http.Request) {
7384
callCount++
@@ -80,8 +91,8 @@ func TestSyncCalendar410ResetsAndReFetches(t *testing.T) {
8091
resp := map[string]any{
8192
"value": []map[string]any{{
8293
"id": "ev-fresh", "subject": "Refetched",
83-
"start": map[string]any{"dateTime": "2026-05-01T10:00:00.0000000"},
84-
"end": map[string]any{"dateTime": "2026-05-01T11:00:00.0000000"},
94+
"start": map[string]any{"dateTime": freshStart},
95+
"end": map[string]any{"dateTime": freshEnd},
8596
"isAllDay": false,
8697
"organizer": map[string]any{
8798
"emailAddress": map[string]any{"name": "", "address": ""},

0 commit comments

Comments
 (0)