feat(bookstack-api-jt9): implement pages export (Markdown, PDF)
Add doRaw() for non-JSON responses. Implement ExportMarkdown() and ExportPDF() on PagesService returning raw bytes. Add tests.
This commit is contained in:
parent
6944d50512
commit
f2747adcaf
5 changed files with 99 additions and 5 deletions
|
|
@ -75,3 +75,54 @@ func TestPagesService_Get_NotFound(t *testing.T) {
|
|||
t.Error("expected ErrNotFound")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPagesService_ExportMarkdown(t *testing.T) {
|
||||
c := testClient(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/pages/5/export/markdown" {
|
||||
t.Errorf("path = %s, want /api/pages/5/export/markdown", r.URL.Path)
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write([]byte("# Hello\n\nThis is markdown."))
|
||||
})
|
||||
|
||||
data, err := c.Pages.ExportMarkdown(context.Background(), 5)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if string(data) != "# Hello\n\nThis is markdown." {
|
||||
t.Errorf("got %q", string(data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPagesService_ExportPDF(t *testing.T) {
|
||||
pdfContent := []byte("%PDF-1.4 fake content")
|
||||
c := testClient(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/pages/5/export/pdf" {
|
||||
t.Errorf("path = %s, want /api/pages/5/export/pdf", r.URL.Path)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/pdf")
|
||||
w.Write(pdfContent)
|
||||
})
|
||||
|
||||
data, err := c.Pages.ExportPDF(context.Background(), 5)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if string(data) != string(pdfContent) {
|
||||
t.Errorf("got %d bytes, want %d", len(data), len(pdfContent))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPagesService_ExportMarkdown_NotFound(t *testing.T) {
|
||||
c := testClient(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
})
|
||||
|
||||
_, err := c.Pages.ExportMarkdown(context.Background(), 999)
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
if !errors.Is(err, ErrNotFound) {
|
||||
t.Error("expected ErrNotFound")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue