package store import ( "context" "testing" ) func TestCitySpotDisplayTitlePreservesIdentity(t *testing.T) { for _, test := range []struct{ name, title, boundary, parent, want string }{ {"home-undefined", "Undefined", "/life/home/_undefined", "Home & Garden", "Home & Garden"}, {"home-undefined", "home-undefined", "/life/home/_undefined", "Home", "Home"}, {"home-undefined", "My notes", "/life/home/_undefined", "Home", "My notes"}, {"manual", "Undefined", "/life/home/manual", "Home", "Undefined"}, {"home-undefined", "", "/life/home/_undefined", "", "home"}, } { if got := CitySpotDisplayTitle(test.name, test.title, test.boundary, test.parent); got != test.want { t.Fatalf("%+v: %q", test, got) } } } func TestCitySearchContentPathMetadata(t *testing.T) { st := cityReadFixture(t) citySearchInsertZone(t, st, "q", "d", "quartier", "", "campus", "Campus", "needle", "/life") citySearchInsertZone(t, st, "s", "d", "street", "q", "home", "Home", "needle", "/life/home") citySearchInsertSpot(t, st, "p", "d", "s", "home-undefined", "Undefined", "needle", "/life/home/_undefined") // Same Path in another Domain must not be mistaken for a local portal. cityTestExec(t, st, `INSERT INTO paths(domain_uuid,path,object_uuid) VALUES('other','/life','other-page'),('d','/life/home','home-page')`) results, err := st.SearchCityInDomain(context.Background(), "d", "/", "needle", 30, citySearchAllowAll, SearchOptions{}) if err != nil || len(results) != 3 { t.Fatalf("results: %+v %v", results, err) } if results[0].HasPage || !results[1].HasPage || !results[2].HasPage || results[2].ContentPath() != "/life/home" || results[2].DisplayTitle() != "Home" { t.Fatalf("projection: %+v", results) } node, err := st.CityNode("d", "spot", "home-undefined") if err != nil || node.DisplayTitle() != "Home" || node.Title != "Undefined" || node.Name != "home-undefined" || node.PathPrefix != "/life/home/_undefined" { t.Fatalf("raw identity mutated: %+v %v", node, err) } cityTestExec(t, st, `INSERT INTO spot_pages(spot_uuid,page_uuid,edge_type,label,source,created_at_ms) VALUES('p','home-page','primary','','local',1)`) appearances, err := st.ListPageSpotAppearances("d", "home-page") if err != nil || len(appearances) != 1 || appearances[0].DisplayTitle != "Home" || appearances[0].SpotTitle != "Undefined" || appearances[0].StreetPath != "/life/home" || appearances[0].QuartierPath != "/life" { t.Fatalf("appearance projection: %+v %v", appearances, err) } // Both parent and boundary ACLs still gate the result. results, err = st.SearchCityInDomain(context.Background(), "d", "/", "needle", 30, func(p string) bool { return p != "/life/home" }, SearchOptions{}) if err != nil || len(results) != 1 { t.Fatalf("parent ACL: %+v %v", results, err) } }