Files
Docwell/Server/internal/directory/reminders_test.go
T
tajniak81andClaude Opus 5.5 84043ba05b Add date mentions with reminders
- "@today", "@friday", "@2026-12-01" insert a date; "@remind friday"
  or the date's popover adds a reminder for the person who set it.
- docwell-server keeps a reminders row per person, date and time zone
  in step with each page and sends a "reminder" notification at 9:00
  on the day in that time zone (job notify.reminders). Dates already
  past when added do not notify.
- Exports write dates out; the web and phone inboxes show reminders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 14:55:46 +01:00

56 lines
2.2 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package directory
import (
"testing"
"time"
)
func TestDocReminders(t *testing.T) {
date := func(attrs string) string { return `{"type":"dateMention","attrs":{` + attrs + `}}` }
doc := `{"type":"doc","content":[
{"type":"paragraph","content":[
{"type":"text","text":"Ship v1 by "},` + date(`"date":"2026-11-20","remind":"aaaaaaaaaaaaaaa","tz":"Europe/Warsaw"`) + `,
{"type":"text","text":" with "},{"type":"mention","attrs":{"id":"bbbbbbbbbbbbbbb","label":"Bob"}}]},
{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[
` + date(`"date":"2026-11-20","remind":"aaaaaaaaaaaaaaa","tz":"Europe/Warsaw"`) + `,
` + date(`"date":"2026-12-01","remind":"aaaaaaaaaaaaaaa","tz":"Not/AZone"`) + `,
` + date(`"date":"2026-12-02","remind":""`) + `,
` + date(`"date":"tomorrow","remind":"aaaaaaaaaaaaaaa"`) + `,
` + date(`"date":"2026-12-03","remind":"bad id!"`) + `]}]}]}]}`
got := docReminders([]byte(doc))
if len(got) != 2 {
t.Fatalf("docReminders = %+v", got)
}
if r := got[0]; r.Date != "2026-11-20" || r.TZ != "Europe/Warsaw" || r.Excerpt != "Ship v1 by 2026-11-20 with @Bob" {
t.Errorf("first = %+v", r)
}
if r := got[1]; r.Date != "2026-12-01" || r.TZ != "" {
t.Errorf("an unknown time zone should become UTC: %+v", r)
}
if docReminders([]byte("null")) != nil || docReminders([]byte("{")) != nil {
t.Error("empty documents should have no reminders")
}
}
func TestDueAt(t *testing.T) {
got, ok := dueAt("2026-11-20", "Europe/Warsaw")
if want := time.Date(2026, 11, 20, 8, 0, 0, 0, time.UTC); !ok || !got.Equal(want) {
t.Errorf("Warsaw = %v, want %v", got, want)
}
// Daylight saving time: 9:00 in New York in July is 13:00 UTC.
got, ok = dueAt("2026-07-01", "America/New_York")
if want := time.Date(2026, 7, 1, 13, 0, 0, 0, time.UTC); !ok || !got.Equal(want) {
t.Errorf("New York = %v, want %v", got, want)
}
if got, ok = dueAt("2026-11-20", ""); !ok || got.UTC().Hour() != 9 {
t.Errorf("UTC = %v", got)
}
for _, bad := range []string{"", "2026-13-01", "20.11.2026", "2026-11-20T10:00:00Z"} {
if _, ok := dueAt(bad, ""); ok {
t.Errorf("%q should be refused", bad)
}
}
}