2.9 KiB
2.9 KiB
QA procedure: remove_article_image
Package: test (black-box, extending article_test.go / image_test.go).
Setup shared by every case
- Call
validator.InitValidator()once. - Reuse
mockArticleRepoandmockImageRepoas-is. - Wire
useCases.NewDeleteImageUseCase(imageRepo)(already used bydelete_article_cascades_images.qa.md's suite) alongside the existing use cases. - Build
image.NewHandler(...)with its grown constructor including the delete use case, matching whatever parameter order the coder settles on. - Build a test
jwtauth.New("HS256", []byte("test-secret"), nil). - Mount
DELETE /{id}/image/{imageId}alongside the existing article routes under the authenticated group, mirroringapi/router.goafter this slice. - Mint a valid jwt cookie for user id 1 as in
upload_article_image.qa.md.
HTTP checks
- Seed
articleRepo.articles[1]withImages: []*image.Image{{ID: 10}}andimageRepo.images[10] = image.Image{ID: 10}. SendDELETE /v1/article/1/image/10with the valid cookie. Assert status 204, empty body; assertimageRepo.imagesno longer has key 10. - Empty
articleRepo; seedimageRepo.images[10]. SendDELETE /v1/article/9999/image/10. Assert 404, body"Article not found\n"; assertimageRepo.imagesstill has key 10 (Delete never called — track via a call-count field on the fake, the same way the existing fakes already trackCreate). - Seed
articleRepo.articles[1]; emptyimageRepo. SendDELETE /v1/article/1/image/9999. Assert 404, body"Image not found\n". - Seed
articleRepo.articles[1](empty Images) andarticleRepo.articles[2]withImages: []*image.Image{{ID: 10}}; seedimageRepo.images[10]. SendDELETE /v1/article/1/image/10. Assert 204; assertimageRepo.imagesno longer has key 10 — asserts the shallow-check contract from the feature's fourth scenario. - Seed as in step 8. Send
DELETE /v1/article/1/image/10with no cookie. Assert 401; assertimageRepo.imagesstill has key 10. - Examples-driven: send
DELETE /v1/article/abc/image/10andDELETE /v1/article/1/image/abcwith the valid cookie. Assert 400, body"The server expects the ID to be in the format of an unsigned 32-bit integer (uint32).\n"for each.
Also touched by this slice: upload_article_image's 201 body
- Extend
upload_article_image.qa.md's existing 201-body assertion to also decode and check theidfield equals the newly created image'sIDinimageRepo.images.
Manual verification (not exercised by the Go test)
- Real DELETE against a real SQLite file and real UPLOAD_DIR: confirm the
file is actually removed from disk and the
article_imagesjoin row is gone, the same wayupload_article_image.qa.md's manual item covers the POST side. - SPA-visible behaviour: covered separately by
features/editor_image_removal.qa.md. - No SMTP involvement.