Fix Wiki Deploy Post Titles
This commit is contained in:
@@ -140,3 +140,57 @@ func TestDeployWikiCreatesNodeBBTopicAndWritesManifest(t *testing.T) {
|
||||
t.Fatalf("unexpected manifest entry: %#v", entry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeployWikiCreatesNodeBBTopicWithFallbackForShortTitle(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
sourceDir := filepath.Join(root, "pages")
|
||||
if err := os.MkdirAll(filepath.Join(sourceDir, "spells"), 0755); err != nil {
|
||||
t.Fatalf("create source dir: %v", err)
|
||||
}
|
||||
generated := "<!-- sow-topdata-wiki:managed:start -->\n<h1>Aid</h1>\n<p>Generated spell page</p>\n<!-- sow-topdata-wiki:managed:end -->\n"
|
||||
if err := os.WriteFile(filepath.Join(sourceDir, "spells", "aid.html"), []byte(generated), 0644); err != nil {
|
||||
t.Fatalf("write source page: %v", err)
|
||||
}
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost || r.URL.Path != "/api/v3/topics" {
|
||||
t.Fatalf("unexpected request %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
var req struct {
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
t.Fatalf("decode create request: %v", err)
|
||||
}
|
||||
if req.Title != "Spells: Aid" {
|
||||
t.Fatalf("expected fallback title, got %q", req.Title)
|
||||
}
|
||||
if req.Content != generated {
|
||||
t.Fatalf("expected page body to keep short h1 unchanged:\n%s", req.Content)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"response": map[string]any{
|
||||
"tid": 11,
|
||||
"mainPost": map[string]any{
|
||||
"pid": 42,
|
||||
"tid": 11,
|
||||
},
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
_, err := DeployWikiWithOptions(&project.Project{}, DeployWikiOptions{
|
||||
SourceDir: sourceDir,
|
||||
Endpoint: server.URL,
|
||||
Token: "nodebb-token",
|
||||
ManifestPath: filepath.Join(root, "deploy-manifest.json"),
|
||||
CategoryIDs: map[string]int{"spells": 5},
|
||||
AllowCreates: true,
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("DeployWikiWithOptions create failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user