package server import ( "context" "net/http/httptest" "testing" ) func TestPeriodicalShareDomain(t *testing.T) { s, _, source, actor := periodicalFixture(t) r := httptest.NewRequest("GET", "http://localhost/v/blog/-/new", nil) d, err := s.store.GetDomainByUUID(source) if err != nil { t.Fatal(err) } if err = s.store.CreateDomain(d.CampusUUID, "share-blog", "Share Blog", "blog.example.test", "local", "", "", true); err != nil { t.Fatal(err) } var target string var id int64 if err = s.store.DB.QueryRow(`SELECT uuid,id FROM domains WHERE name='share-blog'`).Scan(&target, &id); err != nil { t.Fatal(err) } if err = s.store.SetConfigInDomain(target, "home_layout", "blog"); err != nil { t.Fatal(err) } if _, err = s.store.DB.Exec(`INSERT INTO periodical_settings(domain_uuid,kind,enabled) VALUES(?,'blog',1)`, target); err != nil { t.Fatal(err) } if err = s.store.SetPeriodicalProjection(context.Background(), id, actor, "blog", source, "/blog"); err != nil { t.Fatal(err) } targets := s.periodicalShareTargets(r, "blog", "/blog/2026/09/19/keyword") if len(targets) != 1 || targets[0].URL != "https://blog.example.test/2026/09/19/keyword" || targets[0].Title != "Share Blog" { t.Fatal(targets) } if targets := s.periodicalShareTargets(r, "blog", "/2026/09/19"); len(targets) != 0 { t.Fatal("outside prefix", targets) } if _, err = s.store.DB.Exec(`UPDATE domains SET enabled=0 WHERE uuid=?`, target); err != nil { t.Fatal(err) } if targets := s.periodicalShareTargets(r, "blog", "/blog/2026/09/19"); len(targets) != 0 { t.Fatal("disabled", targets) } }