修复提现拒绝审核参数校验

This commit is contained in:
yml2213
2026-07-05 20:33:47 +08:00
parent 1984e07e91
commit 7937b0df8a
6 changed files with 53 additions and 4 deletions
@@ -0,0 +1,41 @@
package withdrawal
import (
"net/http/httptest"
"strings"
"testing"
"github.com/gin-gonic/gin"
)
func TestReviewWithdrawalRequestBindApprovedFalse(t *testing.T) {
gin.SetMode(gin.TestMode)
c, _ := gin.CreateTestContext(httptest.NewRecorder())
c.Request = httptest.NewRequest("POST", "/admin/withdrawals/1/review", strings.NewReader(`{"approved":false,"remark":"资料不符"}`))
c.Request.Header.Set("Content-Type", "application/json")
var req ReviewWithdrawalRequest
if err := c.ShouldBindJSON(&req); err != nil {
t.Fatalf("approved=false 应该通过参数绑定: %v", err)
}
if req.Approved == nil {
t.Fatal("approved 字段应该被识别为已传入")
}
if *req.Approved {
t.Fatal("approved=false 不应该被绑定成 true")
}
}
func TestReviewWithdrawalRequestBindMissingApproved(t *testing.T) {
gin.SetMode(gin.TestMode)
c, _ := gin.CreateTestContext(httptest.NewRecorder())
c.Request = httptest.NewRequest("POST", "/admin/withdrawals/1/review", strings.NewReader(`{"remark":"资料不符"}`))
c.Request.Header.Set("Content-Type", "application/json")
var req ReviewWithdrawalRequest
if err := c.ShouldBindJSON(&req); err == nil {
t.Fatal("缺少 approved 字段时应该参数绑定失败")
}
}