Files
pages/internal/store/city_operations_test.go
T
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
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.
2026-09-27 14:44:43 +09:00

64 lines
1.8 KiB
Go

package store
import (
"context"
"database/sql"
"errors"
"testing"
_ "modernc.org/sqlite"
)
func TestCityHealthAndTopologyEventsAreDomainScoped(t *testing.T) {
db, err := sql.Open("sqlite", "file:city-operations-test?mode=memory&cache=shared")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = db.Close() })
st := &Store{DB: db}
ctx, cancel := context.WithCancel(context.Background())
cancel()
if _, err := st.ResolveCityPathContextWithContext(ctx, "d1", "/life"); !errors.Is(err, context.Canceled) {
t.Fatalf("cancelled locality read: %v", err)
}
if err := st.EnsureCitySchema(); err != nil {
t.Fatal(err)
}
if _, err := db.Exec(`CREATE TABLE paths(domain_uuid TEXT,path TEXT,object_uuid TEXT,is_primary INTEGER DEFAULT 0)`); err != nil {
t.Fatal(err)
}
q, err := st.CreateZoneAtPath("d1", "actor", "quartier", "", "life", "Life", "", "/life")
if err != nil {
t.Fatal(err)
}
street, err := st.CreateZoneAtPath("d1", "actor", "street", q, "home", "Home", "", "/life/home")
if err != nil {
t.Fatal(err)
}
if _, err := st.CreateSpotAtPath("d1", "actor", street, "kitchen", "Kitchen", "", "/life/home/kitchen"); err != nil {
t.Fatal(err)
}
if _, err := st.CreateZoneAtPath("d2", "actor2", "quartier", "", "work", "Work", "", "/work"); err != nil {
t.Fatal(err)
}
health, err := st.GetCityHealth("d1")
if err != nil {
t.Fatal(err)
}
if health.Quartiers != 1 || health.Streets != 1 || health.Spots != 1 || health.EmptySpots != 1 {
t.Fatalf("unexpected health: %+v", health)
}
events, err := st.ListTopologyEvents("d1", 0, 20)
if err != nil {
t.Fatal(err)
}
if len(events) != 3 {
t.Fatalf("events=%d, want 3", len(events))
}
for _, event := range events {
if event.DomainUUID != "d1" {
t.Fatalf("cross-domain event leaked: %+v", event)
}
}
}