fix logger and redeem admin review findings
Some checks failed
CI / test (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
Security Scan / backend-security (push) Has been cancelled
Security Scan / frontend-security (push) Has been cancelled

This commit is contained in:
2026-04-20 11:24:36 +08:00
parent 3a0ca7f57f
commit ed642e8769
22 changed files with 563 additions and 63 deletions

View File

@@ -7,6 +7,7 @@ import (
"net/http/httptest"
"testing"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
)
@@ -226,7 +227,13 @@ func TestProxyHandlerEndpoints(t *testing.T) {
}
func TestRedeemHandlerEndpoints(t *testing.T) {
router, _ := setupAdminRouter()
router, adminSvc := setupAdminRouter()
adminSvc.batchDeleteRedeemResult = &service.RedeemBatchDeleteResult{
DeletedIDs: []int64{1},
Skipped: []service.RedeemBatchDeleteSkipped{
{ID: 2, Reason: "db error"},
},
}
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/v1/admin/redeem-codes", nil)
@@ -255,6 +262,20 @@ func TestRedeemHandlerEndpoints(t *testing.T) {
req.Header.Set("Content-Type", "application/json")
router.ServeHTTP(rec, req)
require.Equal(t, http.StatusOK, rec.Code)
var resp struct {
Code int `json:"code"`
Data struct {
DeletedIDs []int64 `json:"deleted_ids"`
Skipped []struct {
ID int64 `json:"id"`
Reason string `json:"reason"`
} `json:"skipped"`
} `json:"data"`
}
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp))
require.Equal(t, []int64{1}, resp.Data.DeletedIDs)
require.Len(t, resp.Data.Skipped, 1)
require.Equal(t, int64(2), resp.Data.Skipped[0].ID)
rec = httptest.NewRecorder()
req = httptest.NewRequest(http.MethodPost, "/api/v1/admin/redeem-codes/5/expire", nil)