adminLoginHandler_test.go 870 B

123456789101112131415161718192021222324252627282930313233
  1. package pub
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "net/http/httptest"
  6. "strings"
  7. "testing"
  8. "perms-system-server/internal/response"
  9. "perms-system-server/internal/svc"
  10. "perms-system-server/internal/testutil"
  11. "github.com/stretchr/testify/assert"
  12. "github.com/stretchr/testify/require"
  13. )
  14. // TC-0023: 缺少必填字段(adminLogin)
  15. func TestAdminLoginHandler_MissingFields(t *testing.T) {
  16. svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
  17. handler := AdminLoginHandler(svcCtx)
  18. req := httptest.NewRequest(http.MethodPost, "/api/auth/adminLogin", strings.NewReader("{}"))
  19. req.Header.Set("Content-Type", "application/json")
  20. rr := httptest.NewRecorder()
  21. handler.ServeHTTP(rr, req)
  22. var body response.Body
  23. err := json.Unmarshal(rr.Body.Bytes(), &body)
  24. require.NoError(t, err)
  25. assert.Equal(t, 400, body.Code)
  26. assert.Contains(t, body.Msg, "username")
  27. }