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 calendar "amadan.net/oficina/calendar/internal/calendar"
5 "context"
6 "errors"
7 "net/url"
8 "testing"
9 "time"
10)
11
12func TestGapSeriesRefusesFreeSlotsWithoutBreakingOrdinaryDates(t *testing.T) {
13 app, session := signedIn(t, "gap@example.test")
14 createEvent(t, app.Handler(), session, url.Values{"title": {"Gap fixture"}, "start": {"2026-03-01T01:30"}, "end": {"2026-03-01T02:00"}, "tz": {"Europe/Dublin"}, "kind": {"meeting"}, "status": {"confirmed"}, "repeat": {"daily"}})
15 host := app.PersonByAddressForTest(t, "gap@example.test")
16 st := app.StoreForTest()
17 ctx := context.Background()
18 ws, problems := calendar.ParseAvailability("every day 0-4")
19 if len(problems) != 0 {
20 t.Fatal(problems)
21 }
22 stored, err := st.CreateBookingPage(ctx, host.ID, calendar.BookingPageInput{Title: "Gap check", Availability: "every day 0-4", DurationMin: 30, HorizonDays: 30}, ws)
23 if err != nil {
24 t.Fatal(err)
25 }
26 page, err := st.BookingPage(ctx, host.ID, stored.ID)
27 if err != nil {
28 t.Fatal(err)
29 }
30 for _, c := range []struct {
31 day int
32 month time.Month
33 incomplete bool
34 }{{29, time.March, true}, {27, time.March, false}, {1, time.April, false}} {
35 from := time.Date(2026, c.month, c.day, 0, 0, 0, 0, time.UTC)
36 to := from.Add(24 * time.Hour)
37 slots, err := st.FreeSlots(ctx, page, host, from, from, to, 0, 0)
38 if c.incomplete {
39 if !errors.Is(err, calendar.ErrIncompleteExpansion) || len(slots) != 0 {
40 t.Fatalf("gap FreeSlots=%v err=%v", slots, err)
41 }
42 } else if err != nil || len(slots) == 0 {
43 t.Fatalf("ordinary date %v incomplete", from)
44 }
45 views, err := st.EventsInRange(ctx, host.ID, from.Unix(), to.Unix())
46 if err != nil {
47 t.Fatal(err)
48 }
49 if c.incomplete && len(views) != 0 {
50 t.Fatalf("invalid chip: %+v", views)
51 }
52 if !c.incomplete && len(views) != 1 {
53 t.Fatalf("ordinary date %v: %d views", from, len(views))
54 }
55 }
56}
57