Calendar: in-app reminders — tests for the claim, the occurrence link, tense and the lease edge; fix the notice read's rrule column
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+121
−7
internal/calendar/inapp_reminders_test.go+59 −0internal/calendar/store_reminder_notice.go+8 −7internal/calendar/team_inapp_test.go+54 −0
Intent
diff --git a/internal/calendar/inapp_reminders_test.go b/internal/calendar/inapp_reminders_test.go| index 9dafced..aebd7d0 100644 |
| --- a/internal/calendar/inapp_reminders_test.go |
| +++ b/internal/calendar/inapp_reminders_test.go |
| @@ -142,3 +142,62 @@ func TestTwoRulesOnOneOccurrenceAreBothDeliveredInOnePass(t *testing.T) { |
| t.Fatalf("drain = %d %v, want both rules delivered", sent, err) |
| } |
| } |
| + |
| +// The mark is conditional on the claim, as every completion is: a |
| +// reschedule that overtook the claim announces nothing. |
| +func TestAnOvertakenClaimMarksNothing(t *testing.T) { |
| + w := newPlainWorld(t) |
| + choose := ChannelInApp |
| + w.app.db.G.Model(&Person{}).Where("id = ?", w.person.ID).Update("reminder_channel", choose) |
| + e := w.event("Overtaken") |
| + due, ok, err := w.app.store.ClaimDueReminder(context.Background(), time.Now().Unix()) |
| + if err != nil || !ok || due.EventID != e.ID || due.Channel != ChannelInApp { |
| + t.Fatalf("claim = %+v %v %v", due, ok, err) |
| + } |
| + if err := w.app.store.RescheduleReminder(context.Background(), due.Queue.ReminderID); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := w.app.store.MarkReminderNotice(context.Background(), due, time.Now().Unix()); err != nil || w.notices() != 0 { |
| + t.Fatalf("an overtaken claim marked %d notices (%v)", w.notices(), err) |
| + } |
| +} |
| + |
| +// A notice links to its occurrence, and goes when its event does. |
| +func TestANoticeLinksItsOccurrenceAndGoesWithItsEvent(t *testing.T) { |
| + w := newPlainWorld(t) |
| + w.app.db.G.Model(&Person{}).Where("id = ?", w.person.ID).Update("reminder_channel", ChannelInApp) |
| + start, end := soon(5) |
| + if rec := w.do("POST", "/events", url.Values{"calendar_id": {itoa(w.calendar)}, "title": {"Daily thing"}, "start": {start}, "end": {end}, "tz": {"UTC"}, "kind": {"meeting"}, "status": {"confirmed"}, "repeat": {"daily"}}); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("create = %d", rec.Code) |
| + } |
| + var e Event |
| + w.app.db.G.Last(&e) |
| + page := w.do("GET", "/reminders", nil).Body.String() |
| + if !strings.Contains(page, `href="/events/`+itoa(e.ID)+"/"+compactLocal(e.StartLocal)+`"`) { |
| + t.Fatalf("the notice does not link its occurrence:\n%s", page) |
| + } |
| + if rec := w.do("POST", "/events/"+itoa(e.ID)+"/delete", url.Values{}); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("delete = %d", rec.Code) |
| + } |
| + if page := w.do("GET", "/reminders", nil).Body.String(); strings.Contains(page, "Daily thing") || strings.Contains(page, "Reminders (") { |
| + t.Fatal("a deleted event's notice is still shown or counted") |
| + } |
| +} |
| + |
| +func TestNoticeWhenIsPastTenseAndAllDayIsADate(t *testing.T) { |
| + now := time.Date(2026, 11, 2, 12, 0, 0, 0, time.UTC).Unix() |
| + timed := NoticeView{StartUTC: now - 3600, Local: "2026-11-02T11:00"} |
| + if got := noticeWhen(timed, "Europe/Dublin", now); got != "Started Monday 2 November at 11:00" { |
| + t.Fatalf("a started occurrence = %q", got) |
| + } |
| + timed.StartUTC = now + 3600 |
| + if got := noticeWhen(timed, "UTC", now); got != "Starts Monday 2 November at 13:00" { |
| + t.Fatalf("a coming occurrence = %q", got) |
| + } |
| + // An all-day occurrence is its date, wherever the reader is: its UTC |
| + // instant west of Greenwich is the evening before. |
| + allDay := NoticeView{AllDay: true, StartUTC: now + 86400, Local: "2026-11-03"} |
| + if got := noticeWhen(allDay, "America/Los_Angeles", now); got != "Starts Tuesday 3 November" { |
| + t.Fatalf("an all-day occurrence = %q", got) |
| + } |
| +} |
diff --git a/internal/calendar/store_reminder_notice.go b/internal/calendar/store_reminder_notice.go| index 6c64836..c31cf94 100644 |
| --- a/internal/calendar/store_reminder_notice.go |
| +++ b/internal/calendar/store_reminder_notice.go |
| @@ -135,14 +135,15 @@ func (s *Store) UnreadNoticeCount(ctx context.Context, personID int64) (int64, e |
| // UnreadNotices lists up to limit unread in-app reminders, newest |
| // occurrence first. |
| func (s *Store) UnreadNotices(ctx context.Context, personID int64, limit int) ([]NoticeView, error) { |
| + // Every column named: gorm's default for RRule is r_rule. |
| type row struct { |
| - ID int64 |
| - EventID int64 |
| - OccurrenceKey string |
| - StartUTC int64 |
| - TitleSealed []byte |
| - RRule string |
| - AllDay bool |
| + ID int64 `gorm:"column:id"` |
| + EventID int64 `gorm:"column:event_id"` |
| + OccurrenceKey string `gorm:"column:occurrence_key"` |
| + StartUTC int64 `gorm:"column:start_utc"` |
| + TitleSealed []byte `gorm:"column:title_sealed"` |
| + RRule string `gorm:"column:rrule"` |
| + AllDay bool `gorm:"column:all_day"` |
| } |
| var rows []row |
| err := s.noticeRows(ctx, personID). |
diff --git a/internal/calendar/team_inapp_test.go b/internal/calendar/team_inapp_test.go| index 2279084..97bd524 100644 |
| --- a/internal/calendar/team_inapp_test.go |
| +++ b/internal/calendar/team_inapp_test.go |
| @@ -11,6 +11,7 @@ import ( |
| "time" |
| "amadan.net/oficina/home/dashboard" |
| + "amadan.net/oficina/home/roster" |
| ) |
| // In-app reminders in team mode (spec §7 "In-app reminders", Paul |
| @@ -240,3 +241,56 @@ func TestTeamInAppRulesAreFeedAlarms(t *testing.T) { |
| t.Fatal("a feed without alarms=1 carried one") |
| } |
| } |
| + |
| +// At the lease's edge the native list and Home's pull are whole or |
| +// unavailable, never an answer whose list is shorter than its count. A |
| +// fresh fixture per step, its lease lapsing k ms into the read. |
| +func TestTeamInAppListAtTheLeaseEdgeIsWholeOrUnavailable(t *testing.T) { |
| + subject := teamSubject('g') |
| + seen := map[string]bool{} |
| + for k := 1; k <= 40; k++ { |
| + for _, surface := range []string{"native", "seam"} { |
| + f := newTeamFixture(t) |
| + p := f.member(subject, "member") |
| + team, _ := f.calendarsOf(p) |
| + homeOnlyEvent(t, f, team, "Edge one") |
| + homeOnlyEvent(t, f, team, "Edge two") |
| + if _, _, err := f.app.h.drain(context.Background(), time.Now()); err != nil || len(noticesOf(f, p)) != 2 { |
| + t.Fatalf("drain: %v", err) |
| + } |
| + f.dir.SetDown(true) |
| + f.clock.Step(roster.MaximumAge - time.Duration(k)*time.Millisecond) |
| + f.clock.SetTick(time.Millisecond) |
| + if surface == "native" { |
| + var native struct { |
| + Unread int `json:"unread"` |
| + Reminders []any `json:"reminders"` |
| + } |
| + switch w := f.get("/api/native/reminders"); { |
| + case w.Code == http.StatusServiceUnavailable: |
| + retryable(t, "native reminders at the lease's edge", w) |
| + seen["native unavailable"] = true |
| + case w.Code == http.StatusOK && json.Unmarshal(w.Body.Bytes(), &native) == nil && native.Unread == 2 && len(native.Reminders) == 2: |
| + seen["native whole"] = true |
| + default: |
| + t.Fatalf("k=%d: native reminders at the lease's edge = %d %s", k, w.Code, w.Body.String()) |
| + } |
| + continue |
| + } |
| + sum, err := f.app.reminderNotices(context.Background(), p.ID, subject, time.Now()) |
| + switch { |
| + case errors.Is(err, dashboard.ErrUnavailable): |
| + seen["seam unavailable"] = true |
| + case err == nil && sum.Unread == 2 && len(sum.Items) == 2: |
| + seen["seam whole"] = true |
| + default: |
| + t.Fatalf("k=%d: the seam at the lease's edge = %+v %v", k, sum, err) |
| + } |
| + } |
| + } |
| + for _, want := range []string{"native whole", "native unavailable", "seam whole", "seam unavailable"} { |
| + if !seen[want] { |
| + t.Fatalf("the sweep saw %v, want %q too", seen, want) |
| + } |
| + } |
| +} |