Supertest · คำขอ HTTP แรก
GET Request
ทดสอบการอ่าน resource ด้วย HTTP GET
GET ใช้เมื่ออ่าน resource
เริ่มจาก request ที่ไม่มี body และไม่มี state ใหม่ GET เหมาะกับการอ่าน collection หรือ resource เดียว แล้วเราตรวจ status และ body ตาม contract ของ endpoint
GET /todosTS
assert collection shape หลังจากยืนยัน status
GET collection กับ GET by id
| request | คำถามที่ test ควรตอบ | หลักฐาน |
|---|---|---|
| GET /todos | collection ถูกคืนใน shape ที่กำหนดหรือไม่ | items และ total |
| GET /todos/7 | resource id 7 ถูกคืนหรือไม่ | id และ public fields |
| GET /todos/404 | missing resource ถูก map ถูกหรือไม่ | status 404 และ error shape |
i
หนึ่ง test หนึ่งคำถามหลัก
อย่าให้ test list, get-by-id และ not-found กลายเป็น assertion ก้อนเดียวจนอ่าน failure ไม่ออก แยก intent ตาม behavior แล้วค่อยรวมเป็น flow ใน phase CRUD