4.8 KiB
4.8 KiB
QA procedure: article_body_format
Package: test (black-box). New files: test/article_body_format_test.go, test/markdown_converter_test.go, test/json_blocks_converter_test.go. No live server, no real SQLite file, no real SMTP.
Setup
- Call
validator.InitValidator()once. - Reuse
mockArticleRepoandmockUserRepo. Add a fakefakeBodyRendererwith a unique type name. It records each call's format and the html it received. For markdown it returns "MD:"+html. For html it returns the html unchanged. For json it returns[{"type":"paragraph","children":[{"type":"text","text":"FAKE","marks":[]}]}]. It has a failure switch. - Wire the real use cases over the fakes, passing the renderer. Update every existing test that builds these use cases for the new constructor signatures. Build
article.NewHandler(...). - Mount a fresh
chi.NewRouter()mirroringapi/router.gofor/v1/article:jwtauth.Verifieron the group, GET/and/{id}public, andAuthenticator+RequireCurrentToken+RequireVerifiedUserfor POST, DELETE and PATCH. - Mint a jwt cookie for user_id 1 with
token.Encode(map[string]any{"user_id": uint32(1)}). Seed a verified user. Seed articles 1 (online) and 2 (offline).
HTTP checks (fake renderer)
- Single read matrix: for each of none,
?format=, markdown, MarkDown, html, HTML, json, JSON, assert status 200,body_format, the renderer's recorded format and the stored HTML passed in. For json, decodebodyand assert it is a JSON array (not a string). - List with none,
?format=htmland?format=json: every element has the matchingbody_format. format=pdf,xmlandmdon single, list and unknown-id paths return 400 withapperr.ArticleBodyFormatErrorMessage + "\n". The renderer and the repo are not called.GET /v1/article/abc?format=pdfreturns 400 withapperr.IdUint32ErrorMessage + "\n".?format=html&format=jsonreturns html.GET /v1/article/2?format=jsonanonymous returns 404"Article not found\n".- Write-route matrix with a cookie (POST, PATCH, publish, unpublish, each with none, html and json where listed): assert status,
body_format, and that the repo holds the HTML that was sent. PATCH /v1/article/1?format=pdfandPOST /v1/article/?format=pdfwith a cookie return 400. The repo is unchanged and no article is created.- Authenticated
GET /v1/article/?format=jsonincludes articles 1 and 2. - Renderer failure switch, then
GET /v1/article/1returns 500"Internal server error\n".
Domain
ParseBodyFormat: "", markdown, MARKDOWN, html, Html, json, JSON are accepted (empty returns markdown). pdf, md and " html" returnerrors.Is(err, ErrUnsupportedBodyFormat).
Converter tests (real library, real Tiptap HTML samples)
test/markdown_converter_test.go: every row of the markdown fidelity table, plus a combined document (heading, paragraph with marks, list, image, code block, quote, hr). Assert exact output. For format html, assert the input comes back byte-identical. 17b. Alignment and escaping: every row of the alignment and plain-text tables, for markdown and json, intest/markdown_converter_test.goandtest/json_blocks_converter_test.go.test/body_converter_documents_test.gocovers the combined hostile document (no raw script, style, iframe or span leaks in markdown or json), its block types, and code block text extraction.test/json_blocks_converter_test.go: every row of the json shapes table. Assert by unmarshalling both sides and comparing with deep equality. This also assertsmarksis[]rather than null or absent,orderedis a bool, and codelanguageis "" when absent. Also include a combined document with nested list, blockquote and an image inside a paragraph. Assert that script and style content never appears, and that no raw HTML survives in any output for any format except html.test/json_blocks_converter_test.goalso asserts that html "" produces[], and that the output is a non-null JSON array.
SPA (Vitest, task test:web)
- Mock
/v1/article/12?format=htmland assertEditorViewrequests that URL and loads the HTML body into the draft. - Assert
useArticles.listArticlesrequests/v1/article/?format=html. - Assert the
ArticleViewimage count is computed from the HTML. - Assert
useArticleDraft.savesends PATCH/v1/article/{id}?format=htmlwith the JSON body. - Reported as NOT RUN if there is no runner. No visual check applies, because no visual change is expected.
Docs
- Check that a docs/api article read page, the IntegrationView snippets and a docs/releases note exist as described.
Manual verification
- In the embedded SPA, edit and save an article against a real SQLite file and confirm the stored body is still HTML.
curlthe public list and a single article with no format,?format=htmland?format=jsonagainst a built binary.- No SMTP involvement.