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.
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
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(`<h1>Guide</h1><p>{{children:/guide exclude=/guide/private}}</p>`), "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())
|
|
}
|
|
}
|