| 123456789101112131415161718192021222324252627282930313233 |
- 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"
- )
- // TC-0508: 缺少必填字段(adminLogin)
- func TestAdminLoginHandler_MissingFields(t *testing.T) {
- svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
- handler := AdminLoginHandler(svcCtx)
- req := httptest.NewRequest(http.MethodPost, "/api/auth/adminLogin", 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.Equal(t, 400, body.Code)
- assert.Contains(t, body.Msg, "username")
- }
|