package pub import ( "encoding/json" "net/http" "net/http/httptest" "strings" "testing" "perms-system-server/internal/response" "perms-system-server/internal/svc" "perms-system-server/internal/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func init() { response.Setup() } // TC-0012: 缺少必填字段 func TestLoginHandler_MissingFields(t *testing.T) { svcCtx := svc.NewServiceContext(testutil.GetTestConfig()) handler := LoginHandler(svcCtx) req := httptest.NewRequest(http.MethodPost, "/api/auth/login", strings.NewReader("{}")) req.Header.Set("Content-Type", "application/json") rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) var body response.Body err := json.Unmarshal(rr.Body.Bytes(), &body) require.NoError(t, err) assert.False(t, body.Success) assert.Equal(t, 400, body.ErrorCode) assert.Contains(t, body.ErrorMessage, "username") }