Supertest · Todo CRUD E2E
Read by ID และ Not Found
ทดสอบการอ่านรายการเดียวและ missing resource
Read by id มีสามเส้นทางหลัก
GET /todos/:id ควรมี test สำหรับ id ที่มีอยู่, id ที่รูปแบบผิด และ id ที่รูปแบบถูกแต่ไม่มี resource การแยกสามกรณีนี้ทำให้เห็นความต่างระหว่าง validation กับ not found
read existing resourceTS
not found เป็น behavior ที่ตั้งใจ
missing resourceTS
กฎสำคัญ
mapping
อย่าคาดหวัง 500 จาก missing data
การไม่มี row เป็น outcome ที่ application ควร map เป็น 404 อย่างตั้งใจ
fixture
ใช้ id จาก create เมื่อทดสอบ success
ช่วยหลีกเลี่ยงการผูก test กับ sequence ของ database