feat: 优化批量匹配和分页默认值 (#244)
This commit is contained in:
@@ -2,9 +2,15 @@ package web
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"cmautobuy/admin/service"
|
||||
)
|
||||
|
||||
@@ -15,6 +21,45 @@ func TestParseInnerCodeIDs_过滤无效并保持首次选择顺序(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInnerCodeRedirect_区分错误反馈并使用默认100条(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
recorder := httptest.NewRecorder()
|
||||
context, _ := gin.CreateTestContext(recorder)
|
||||
form := url.Values{"page_size": {""}}
|
||||
context.Request = httptest.NewRequest(http.MethodPost, "/inner-codes/match", strings.NewReader(form.Encode()))
|
||||
context.Request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
(&Handler{}).innerCodeRedirect(context, "2026-08-15", "pending", "ORDER-1", 2,
|
||||
innerCodeFeedbackError, "匹配失败:测试错误")
|
||||
if context.Writer.Status() != http.StatusSeeOther {
|
||||
t.Fatalf("状态码=%d,期望 303", context.Writer.Status())
|
||||
}
|
||||
location, err := url.Parse(recorder.Header().Get("Location"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
query := location.Query()
|
||||
if location.Path != "/inner-codes" || query.Get("feedback") != "error" ||
|
||||
query.Get("message") != "匹配失败:测试错误" || query.Get("page_size") != "100" ||
|
||||
query.Get("date") != "2026-08-15" || query.Get("status") != "pending" ||
|
||||
query.Get("q") != "ORDER-1" || query.Get("page") != "2" {
|
||||
t.Fatalf("反馈跳转参数不完整: %s", recorder.Header().Get("Location"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInnerCodeMatch_不再按20条提前拒绝只读匹配(t *testing.T) {
|
||||
raw, err := os.ReadFile("inner_code.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := string(raw)
|
||||
for _, forbidden := range []string{"InnerCodeRemoteBatchLimit", "一次最多匹配 20 条"} {
|
||||
if strings.Contains(source, forbidden) {
|
||||
t.Errorf("只读匹配仍包含旧限制 %q", forbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureInnerCodeMatchSession_有效会话不自动登录(t *testing.T) {
|
||||
loginCalls := 0
|
||||
autoLoggedIn, message := ensureInnerCodeMatchSession(
|
||||
|
||||
Reference in New Issue
Block a user