oficina / calendar Public

Clone
git clone https://amadan.net/oficina/calendar

Plain git — no account needed to clone.

Download

Download this file

1package calendartest
2
3import (
4 "context"
5 "net/http"
6 "net/url"
7 "strconv"
8 "strings"
9 "testing"
10 "time"
11)
12
13// TestTheSharePageSaysFeedTimesInTheViewersZone: the database hands every
14// stored time back in UTC (rastrillo's _timezone=UTC, from fb806a2), and
15// the share page used to print a feed's created and last-polled times
16// straight off the row — UTC, without saying so. They are the viewer's
17// zone now, like every other time on every other page.
18func TestTheSharePageSaysFeedTimesInTheViewersZone(t *testing.T) {
19 app, session := signedIn(t, "someone@example.com")
20 h := app.Handler()
21 if rec := postAs(t, h, session, "/settings", url.Values{"zone": {"Pacific/Auckland"}, "week_start": {"1"},
22 "default_reminder_min": {"10"}, "default_all_day_min": {"0"}}); rec.Code != http.StatusSeeOther {
23 t.Fatalf("POST /settings = %d", rec.Code)
24 }
25 person := app.PersonByAddressForTest(t, "someone@example.com")
26 cal, err := app.StoreForTest().DefaultCalendarID(context.Background(), person.ID)
27 if err != nil {
28 t.Fatal(err)
29 }
30 share := "/calendars/" + strconv.FormatInt(cal, 10) + "/share"
31 if rec := postAs(t, h, session, "/calendars/"+strconv.FormatInt(cal, 10)+"/feeds", nil); rec.Code != http.StatusSeeOther {
32 t.Fatalf("mint feed = %d", rec.Code)
33 }
34 // 20:00 UTC on 2 March is 09:00 on 3 March in Auckland (NZDT, +13).
35 at := time.Date(2026, 3, 2, 20, 0, 0, 0, time.UTC)
36 if _, err := app.DBForTest().Exec(`UPDATE feeds SET created_at = ?, last_polled_at = ?, poll_count = 1`, at, at); err != nil {
37 t.Fatal(err)
38 }
39 page := getAs(t, h, session, share).Body.String()
40 for _, want := range []string{"Created 3 March 2026", "last 3 Mar 09:00"} {
41 if !strings.Contains(page, want) {
42 t.Errorf("share page lacks %q (the viewer's zone):\n%s", want, page)
43 }
44 }
45}
46