eeafe2a625
continuous-integration/drone/push Build is passing
- Introduced InvalidStatusTransitionError to handle invalid status transitions for inquiries, providing clearer error messages. - Updated UpdateInquiryStatusForm to make the Reason field optional and added logic to set a default reason if not provided. - Enhanced form validation tests to cover new status transition error scenarios and validation messages. - Refactored handler methods to utilize new error handling functions for improved response management. This update improves the robustness of inquiry status management by ensuring proper error handling and validation, enhancing user experience during status updates.
36 lines
934 B
Go
36 lines
934 B
Go
package inquiry
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"tm/pkg/security"
|
|
)
|
|
|
|
func TestUpdateInquiryStatusFormValidation(t *testing.T) {
|
|
xssPolicy := security.NewXSSPolicy()
|
|
|
|
cases := []struct {
|
|
name string
|
|
body string
|
|
wantErr bool
|
|
}{
|
|
{"status only", `{"status":"reviewed"}`, false},
|
|
{"capitalized status", `{"status":"Reviewed"}`, false},
|
|
{"valid with reason", `{"status":"reviewed","reason":"Initial review completed"}`, false},
|
|
{"user payload", `{"status":"reviewed","reason":"test","description":"test"}`, false},
|
|
{"invalid status", `{"status":"done"}`, true},
|
|
}
|
|
for _, tc := range cases {
|
|
var form UpdateInquiryStatusForm
|
|
if err := json.Unmarshal([]byte(tc.body), &form); err != nil {
|
|
t.Fatalf("%s: unmarshal failed: %v", tc.name, err)
|
|
}
|
|
|
|
err := form.ValidateAndSanitize(xssPolicy)
|
|
if (err != nil) != tc.wantErr {
|
|
t.Errorf("%s: got err=%v wantErr=%v", tc.name, err, tc.wantErr)
|
|
}
|
|
}
|
|
}
|