package server import ( "bytes" "encoding/json" "net/http" "net/http/httptest" "strings" "testing" "pageswiki/internal/db" "pageswiki/internal/store" ) func TestChildrenMacroAuthoringRoundTripAndProjectionAreSeparated(t *testing.T) { database, err := db.Open(t.TempDir() + "/macros.db") if err != nil { t.Fatal(err) } defer database.Close() if err := db.Migrate(database); err != nil { t.Fatal(err) } st := store.New(database) domain, _ := st.GetDefaultDomain() objectUUID, err := st.CreatePageAtPathInDomain(domain.UUID, "/guide") if err != nil { t.Fatal(err) } if _, err = st.SaveRevisionContent(objectUUID, []byte(`
{{children:/guide exclude=/guide/private}}
`), "test", "und", "text/html", ""); err != nil { t.Fatal(err) } server := &Server{store: st} request := httptest.NewRequest(http.MethodGet, "http://localhost/guide", nil) authoring, err := server.transpileMarkdownFromPath(request, "/guide", markdownAuthoring) if err != nil { t.Fatal(err) } if !strings.Contains(authoring, `{{children:/guide exclude=/guide/private}}`) || strings.Contains(authoring, "children-async") { t.Fatalf("authoring markdown=%q", authoring) } payload, _ := json.Marshal(map[string]any{"markdown": authoring, "path": "/guide", "projection": true}) previewRequest := httptest.NewRequest(http.MethodPost, "http://localhost/_/api/v1/render/markdown", bytes.NewReader(payload)) preview := httptest.NewRecorder() server.handleMarkdownRenderAPI(preview, previewRequest) if preview.Code != http.StatusOK || !strings.Contains(preview.Body.String(), "children-async") || strings.Contains(preview.Body.String(), `{{children`) { t.Fatalf("projection status=%d body=%s", preview.Code, preview.Body.String()) } }