3.6 KiB
3.6 KiB
QA procedure: edit_article_body
Package: test (black-box, extending article_test.go).
Setup shared by every case
- Call
validator.InitValidator()once. - Reuse
mockArticleRepo(test/article_test.go) as-is; itsUpdateBodyalready supports everything this slice needs, no fake changes expected. - Wire the real use cases over the fake:
useCases.NewCreateArticleUseCase,useCases.NewGetArticleUseCase,useCases.NewListArticlesUseCase,useCases.NewDeleteArticleUseCase,useCases.NewUpdateArticleUseCase. Buildarticle.NewHandler(...)(existing signature, already takes the update use case), exposing the newUpdateArticleBodymethod. - Build a test
jwtauth.New("HS256", []byte("test-secret"), nil). - Mount the routes on a fresh
chi.NewRouter()mirroringapi/router.go's current shape (perarticle_publishing.qa.md):GET /underjwtauth.Verifieronly;GET /{id},POST /,DELETE /{id},PATCH /{id}/publish,PATCH /{id}/unpublishunderjwtauth.Verifier+jwtauth.Authenticator. AddPATCH /{id}to that same authenticated group. - Mint a valid jwt cookie for user id 1:
token.Encode(map[string]any{"user_id": uint32(1)}), set as thejwtcookie on the relevanthttptest.NewRequest. - Seed the repo directly via the map pattern already used elsewhere, e.g.
repo.articles[1] = article.Article{ID: 1, Title: "Backyard Renovation Update", Body: "Old body text", IsOnline: true}andrepo.articles[2] = article.Article{ID: 2, Title: "Draft: Kitchen Remodel", Body: "Draft notes", IsOnline: false}.
HTTP checks
PATCH /v1/article/1with the valid cookie and JSON body{"body": "New body text"}, repo seeded per step 7 -> status200; decode the JSON response and assertid == 1,body == "New body text",title == "Backyard Renovation Update",is_online == true; assertrepo.articles[1].Bodyis now"New body text"andrepo.articles[1].Title/IsOnlineare unchanged.PATCH /v1/article/2with the valid cookie and JSON body{"body": "Revised draft notes"}, repo seeded per step 7 -> status200; decode the JSON response and assertid == 2,body == "Revised draft notes",is_online == false.PATCH /v1/article/9999with the valid cookie and a valid JSON body, empty repo id9999-> status404, body"Article not found\n".PATCH /v1/article/not-a-numberwith the valid cookie and a valid JSON body -> status400, body matchingapperr.IdUint32ErrorMessage + "\n".PATCH /v1/article/1with the valid cookie and a malformed JSON body (e.g. raw stringnot-json), repo seeded with article id 1 -> status400, body matchingapperr.BodyErrorMessage + "\n".PATCH /v1/article/1with the valid cookie and JSON body{"body": ""}, repo seeded with article id 1 -> status400; assertrepo.articles[1].Bodyis unchanged (nothing stored).PATCH /v1/article/1with the valid cookie and JSON body{"body": "<10001-char string>"}, repo seeded with article id 1 -> status400; assertrepo.articles[1].Bodyis unchanged.PATCH /v1/article/1with no cookie, repo seeded with article id 1 -> status401.
Manual verification (not exercised by the Go test)
- SPA-visible behaviour: confirm the back-office article editor exposes a body-editing
control that calls
PATCH /v1/article/{id}and reflects the updated body, against the real embedded frontend and a real SQLite file. Not exercised bytask test; requirestask devor a builttask buildbinary. (No such UI exists yet as of this slice.) - No SMTP involvement.