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.
81 lines
2.6 KiB
Go
81 lines
2.6 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http/httptest"
|
|
"pageswiki/internal/store"
|
|
"testing"
|
|
)
|
|
|
|
func TestTaskHierarchyAndDaySchedule(t *testing.T) {
|
|
s, token, domain, owner := taskFixture(t)
|
|
ctx := context.Background()
|
|
save := func(i store.TaskRecord) store.TaskRecord {
|
|
t.Helper()
|
|
v, e := s.store.SaveTask(ctx, domain, owner, i, i.Version)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
return v
|
|
}
|
|
parent := save(newTaskRecord("task", "Parent"))
|
|
child := newTaskRecord("task", "Child")
|
|
child.ParentUUID = parent.UUID
|
|
child.StartOn = "2026-09-29"
|
|
child.EndOn = "2026-10-02"
|
|
child = save(child)
|
|
bad := newTaskRecord("task", "Grandchild")
|
|
bad.ParentUUID = child.UUID
|
|
if _, e := s.store.SaveTask(ctx, domain, owner, bad, 0); !errors.Is(e, store.ErrTaskInvalid) {
|
|
t.Fatal("grandchild accepted", e)
|
|
}
|
|
bad = parent
|
|
bad.ParentUUID = child.UUID
|
|
if _, e := s.store.SaveTask(ctx, domain, owner, bad, parent.Version); !errors.Is(e, store.ErrTaskInvalid) {
|
|
t.Fatal("cycle accepted", e)
|
|
}
|
|
parent.Status = "done"
|
|
parent.Archived = true
|
|
save(parent)
|
|
child.Title = "Independent child"
|
|
child = save(child)
|
|
if child.Status != "todo" {
|
|
t.Fatal("parent completion cascaded")
|
|
}
|
|
for _, month := range []string{"2026-09", "2026-10"} {
|
|
items, partial, e := s.store.TaskSchedule(ctx, domain, owner, month, "")
|
|
if e != nil || partial || len(items) != 1 || items[0].UUID != child.UUID || items[0].Notes != "" {
|
|
t.Fatalf("schedule %s: %+v %v", month, items, e)
|
|
}
|
|
}
|
|
if items, _, e := s.store.TaskSchedule(ctx, domain, owner, "2026-11", ""); e != nil || len(items) != 0 {
|
|
t.Fatal("out of range", e)
|
|
}
|
|
bad = child
|
|
bad.EndOn = "2026-09-01"
|
|
if _, e := s.store.SaveTask(ctx, domain, owner, bad, child.Version); !errors.Is(e, store.ErrTaskInvalid) {
|
|
t.Fatal("reverse span", e)
|
|
}
|
|
bad = child
|
|
bad.EndOn = "2028-09-01"
|
|
if _, e := s.store.SaveTask(ctx, domain, owner, bad, child.Version); !errors.Is(e, store.ErrTaskInvalid) {
|
|
t.Fatal("unbounded span", e)
|
|
}
|
|
family, _, e := s.store.ListTasks(ctx, domain, owner, store.TaskQuery{Kind: "task", View: "family", Parent: parent.UUID, Today: "2026-09-25"})
|
|
if e != nil || len(family) != 1 {
|
|
t.Fatal("family", e)
|
|
}
|
|
w := taskRequest(s, token, "GET", "schedule?month=2026-10", nil, "")
|
|
if w.Code != 200 {
|
|
t.Fatalf("schedule API %d %s", w.Code, w.Body)
|
|
}
|
|
r := httptest.NewRequest("GET", "http://localhost/v/plan/tasks/schedule/2026/10", nil)
|
|
r.Header.Set("Authorization", "Bearer "+token)
|
|
w = httptest.NewRecorder()
|
|
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
|
if w.Code != 200 {
|
|
t.Fatalf("schedule page %d %s", w.Code, w.Body)
|
|
}
|
|
}
|