4.0 KiB
4.0 KiB
QA procedure: article_publishing
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; itsUpdateIsOnlineandFindByFiltersalready support 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(...)extended to also take the update use case (matching whateverNewHandlersignature the coder lands on), exposing the newPublishArticleandUnpublishArticlemethods. - Build a test
jwtauth.New("HS256", []byte("test-secret"), nil). - Mount the routes on a fresh
chi.NewRouter()mirroringapi/router.go's current shape (perpublic_article_listing.qa.md):GET /underjwtauth.Verifieronly;GET /{id},POST /,DELETE /{id}underjwtauth.Verifier+jwtauth.Authenticator. AddPATCH /{id}/publishandPATCH /{id}/unpublishto 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", IsOnline: true}andrepo.articles[2] = article.Article{ID: 2, Title: "Draft: Kitchen Remodel", IsOnline: false}.
HTTP checks
PATCH /v1/article/2/publishwith the valid cookie, repo seeded per step 7 -> status200; decode the JSON body and assertid == 2andis_online == true; assertrepo.articles[2].IsOnlineis nowtrue.PATCH /v1/article/1/unpublishwith the valid cookie, repo seeded per step 7 -> status200; decode the JSON body and assertid == 1andis_online == false; assertrepo.articles[1].IsOnlineis nowfalse.PATCH /v1/article/1/publishwith the valid cookie against an article already seededIsOnline: true-> status200, bodyis_online == true, no error (idempotency).PATCH /v1/article/2/unpublishwith the valid cookie against an article already seededIsOnline: false-> status200, bodyis_online == false, no error (idempotency).PATCH /v1/article/9999/publishwith the valid cookie, empty repo id9999-> status404, body"Article not found\n". Repeat forPATCH /v1/article/9999/unpublish-> same assertions.PATCH /v1/article/not-a-number/publishwith the valid cookie -> status400, body matchingapperr.IdUint32ErrorMessage + "\n". Repeat for.../unpublish.PATCH /v1/article/1/publishwith no cookie, repo seeded with article id 1 -> status401. Repeat forPATCH /v1/article/1/unpublishwith no cookie -> status401.- Integration with the public listing: seed repo with an offline article id 2, call
PATCH /v1/article/2/publishwith the valid cookie (assert200), then callGET /v1/article/with no cookie and assert the decoded JSON array contains an element with id2. - Mirror check: seed repo with an online article id 1, call
PATCH /v1/article/1/unpublishwith the valid cookie (assert200), then callGET /v1/article/with no cookie and assert the decoded JSON array does not contain an element with id1.
Manual verification (not exercised by the Go test)
- SPA-visible behaviour: confirm the back-office article editor exposes a publish/unpublish
control that calls the new endpoints and updates the visible online/offline state, against the
real embedded frontend and a real SQLite file. Not exercised by
task test; requirestask devor a builttask buildbinary. (No such UI exists yet as of this slice — this note applies once the SPA is wired to the new endpoints.) - No SMTP involvement.