Supertest · NestJS Validation และ Error
Internal Error Boundary
ตรวจการ map persistence หรือ infrastructure failure เป็น HTTP response
ทดสอบ failure ที่ไม่คาดคิดอย่างปลอดภัย
ระบบอาจเจอ database outage หรือ external dependency ล้มเหลว E2E test ควรยืนยันว่า server ตอบ 500 อย่างปลอดภัย ไม่ค้าง และไม่ส่ง stack trace, secret หรือรายละเอียด infrastructure ให้ client
safe internal error responseTS
คุม failure ที่จะทำให้ test deterministic
อย่ารอให้ database จริงพังเพื่อทดสอบ 500 เพราะจะทำให้ suite ไม่แน่นอน ใช้ provider override หรือ fault fixture เฉพาะจุดเพื่อจำลอง dependency error แล้วตรวจ HTTP mapping จากภายนอก
กฎสำคัญ
boundary
จำลองสาเหตุ ไม่จำลอง response
ให้ dependency โยน error แล้วปล่อย application map error เป็น 500 เพื่อพิสูจน์ boundary จริง
security
ห้าม leak implementation
message สำหรับ client ควรปลอดภัยและ predictable ไม่ใช่ข้อความจาก driver หรือ stack เต็ม