fix: remove 10 unused test functions flagged by staticcheck U1000
This commit is contained in:
@@ -20,10 +20,6 @@ import (
|
||||
"crussell/testutils/jwt"
|
||||
)
|
||||
|
||||
func boolPtr(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// populateDepositFields - DepositProtectedAmount
|
||||
// =============================================================================
|
||||
|
||||
@@ -250,14 +250,6 @@ func getTotalPaymentCount(t *testing.T, bookingID string, ctx context.Context) i
|
||||
return count
|
||||
}
|
||||
|
||||
func getAmountPaid(t *testing.T, bookingID string, ctx context.Context) float64 {
|
||||
t.Helper()
|
||||
var amount float64
|
||||
err := db.Conn.QueryRow(ctx, `SELECT COALESCE(SUM(amount), 0) FROM payments WHERE booking_id = $1 AND status = 'completed'`, bookingID).Scan(&amount)
|
||||
require.NoError(t, err)
|
||||
return amount
|
||||
}
|
||||
|
||||
func applyLoyaltyRedemption(t *testing.T, bookingID, userID string, ctx context.Context) {
|
||||
t.Helper()
|
||||
handler := http.HandlerFunc(payments.ApplyLoyaltyRedemption)
|
||||
|
||||
@@ -156,56 +156,6 @@ func getEditRequestIDFromDB(t *testing.T, ctx context.Context, tx db.Querier, bo
|
||||
return editRequestID
|
||||
}
|
||||
|
||||
// createAdminNotification creates an admin notification for an edit request.
|
||||
func createAdminNotification(t *testing.T, ctx context.Context, tx db.Querier, bookingID, userID string) {
|
||||
t.Helper()
|
||||
_, err := tx.Exec(ctx,
|
||||
`INSERT INTO admin_notifications (reason, booking_id, user_id)
|
||||
VALUES ('edit_requested', $1, $2)`, bookingID, userID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create admin notification: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// makeAdminEditRequest creates an admin request with chi routing context for
|
||||
// admin edit request endpoints (approve/deny). This is the most robust pattern.
|
||||
func makeAdminEditRequest(method, path, routePattern string, body interface{}) *httptest.ResponseRecorder {
|
||||
var req *http.Request
|
||||
if body != nil {
|
||||
bodyBytes, _ := json.Marshal(body)
|
||||
req = httptest.NewRequest(method, path, bytes.NewReader(bodyBytes))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
} else {
|
||||
req = httptest.NewRequest(method, path, nil)
|
||||
}
|
||||
|
||||
adminToken := jwt.GenerateAdminToken()
|
||||
req.Header.Set("Authorization", "Bearer "+adminToken)
|
||||
|
||||
rctx := chi.NewRouteContext()
|
||||
// Parse route pattern like "/api/admin/bookings/{id}/edit-requests/{request_id}/approve"
|
||||
patternParts := strings.Split(strings.Trim(routePattern, "/"), "/")
|
||||
pathParts := strings.Split(strings.Trim(path, "/"), "/")
|
||||
for i, pp := range patternParts {
|
||||
if strings.HasPrefix(pp, "{") && strings.HasSuffix(pp, "}") {
|
||||
paramName := pp[1 : len(pp)-1]
|
||||
if i < len(pathParts) {
|
||||
rctx.URLParams.Add(paramName, pathParts[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx := context.WithValue(req.Context(), chi.RouteCtxKey, rctx)
|
||||
ctx = context.WithValue(ctx, mw.UserRoleKey, "admin")
|
||||
if info := extractUserFromTestJWT(adminToken); info != nil {
|
||||
ctx = context.WithValue(ctx, mw.UserIDKey, info.userID)
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
return w
|
||||
}
|
||||
|
||||
// serveChiHandler sets up a chi router with the given route and serves a request.
|
||||
// Supports an optional JSON body (pass nil for no body). An optional base context
|
||||
// can be provided as the last argument to carry a per-test transaction.
|
||||
@@ -262,15 +212,6 @@ func setupAdminContext(ctx context.Context) context.Context {
|
||||
return ctx
|
||||
}
|
||||
|
||||
// setupUserContext adds user JWT to context.
|
||||
func setupUserContext(ctx context.Context, token string) context.Context {
|
||||
if info := extractUserFromTestJWT(token); info != nil {
|
||||
ctx = context.WithValue(ctx, mw.UserIDKey, info.userID)
|
||||
ctx = context.WithValue(ctx, mw.UserRoleKey, info.role)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 1. User Creates Edit Request (RequestEditHandler)
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user