Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"pageswiki/internal/calendar"
|
|
)
|
|
|
|
func TestCalendarUpcomingDefaultsAndBounds(t *testing.T) {
|
|
s, token, domain := configFixture(t)
|
|
s.registerCalendarRoutes()
|
|
repo, e := s.calendars()
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
owner, e := s.store.PrincipalForSession(domain, token)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
c, e := repo.Create(context.Background(), domain, owner.UUID, "Default", "default")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
other, e := repo.Create(context.Background(), domain, owner.UUID, "Other", "other")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if e = repo.SaveDefaults(context.Background(), domain, owner.UUID, []string{c.ID}); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
for i := 0; i < 25; i++ {
|
|
start := time.Now().UTC().Add(time.Duration(i+1) * time.Hour).Truncate(time.Second)
|
|
b, _ := json.Marshal(map[string]any{"summary": fmt.Sprintf("Event %02d", i), "start": start, "end": start.Add(time.Hour)})
|
|
if w := calendarRequest(s, token, "POST", calendarAPI+"calendars/"+c.ID+"/events", string(b), ""); w.Code != 201 {
|
|
t.Fatal(w.Code, w.Body.String())
|
|
}
|
|
}
|
|
start := time.Now().UTC().Add(time.Hour).Truncate(time.Second)
|
|
b, _ := json.Marshal(map[string]any{"summary": "Not selected", "start": start, "end": start.Add(time.Hour)})
|
|
if w := calendarRequest(s, token, "POST", calendarAPI+"calendars/"+other.ID+"/events", string(b), ""); w.Code != 201 {
|
|
t.Fatal(w.Code, w.Body.String())
|
|
}
|
|
w := calendarRequest(s, token, "GET", calendarAPI+"upcoming", "", "")
|
|
var result struct {
|
|
Events []struct {
|
|
calendar.Event
|
|
Href string
|
|
}
|
|
}
|
|
if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &result) != nil || len(result.Events) != 20 {
|
|
t.Fatal(w.Code, w.Body.String())
|
|
}
|
|
if !strings.Contains(result.Events[0].Href, "calendar=default") || result.Events[0].Summary != "Event 00" || result.Events[19].Summary != "Event 19" {
|
|
t.Fatal(result.Events)
|
|
}
|
|
if !strings.Contains(w.Header().Get("Cache-Control"), "no-store") {
|
|
t.Fatal("private response cached")
|
|
}
|
|
if w = calendarRequest(s, "", "GET", calendarAPI+"upcoming", "", ""); w.Code != 403 {
|
|
t.Fatal("anonymous access", w.Code)
|
|
}
|
|
if w = calendarRequest(s, token, "GET", calendarAPI+"upcoming?date=1900-01-01", "", ""); w.Code != 422 {
|
|
t.Fatal("unbounded dates", w.Code)
|
|
}
|
|
}
|