fix: remove 10 unused test functions flagged by staticcheck U1000
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
func intPtr(i int) *int { return &i }
|
||||
func float64Ptr(f float64) *float64 { return &f }
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
// ─── Public info ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -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)
|
||||
// =============================================================================
|
||||
|
||||
@@ -36,11 +36,6 @@ func makeAdminRequest(handler http.Handler, method, path string, body interface{
|
||||
return makeRequestWithContext(handler, method, path, body, "admin001", "admin", ctx)
|
||||
}
|
||||
|
||||
// makeUserRequest creates a request with regular user context
|
||||
func makeUserRequest(handler http.Handler, method, path string, body interface{}, ctx context.Context) *httptest.ResponseRecorder {
|
||||
return makeRequestWithContext(handler, method, path, body, "user001", "verified_email", ctx)
|
||||
}
|
||||
|
||||
// makeRequestWithContext creates a request with specific user context
|
||||
func makeRequestWithContext(handler http.Handler, method, path string, body interface{}, userID, role string, ctx context.Context) *httptest.ResponseRecorder {
|
||||
var req *http.Request
|
||||
|
||||
@@ -898,21 +898,6 @@ func jpegBytes(t *testing.T) []byte {
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func webpBytes(t *testing.T) []byte {
|
||||
t.Helper()
|
||||
img := image.NewNRGBA(image.Rect(0, 0, 100, 100))
|
||||
for y := 0; y < 100; y++ {
|
||||
for x := 0; x < 100; x++ {
|
||||
img.Set(x, y, color.RGBA{R: 100, G: 150, B: 200, A: 255})
|
||||
}
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := imaging.Encode(&buf, img, imaging.PNG); err != nil {
|
||||
t.Fatalf("failed to encode test image: %v", err)
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func multipartUploadBody(t *testing.T, fields map[string][]byte, tags string) (*bytes.Buffer, string) {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
|
||||
@@ -329,6 +329,4 @@ func TestContact_ReturnsInfo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func strPtr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
|
||||
@@ -319,13 +319,4 @@ func createPayment(t *testing.T, ctx context.Context, q db.Querier, bookingID, p
|
||||
}
|
||||
}
|
||||
|
||||
func createDiscountPayment(t *testing.T, ctx context.Context, q db.Querier, bookingID string, amount float64) {
|
||||
t.Helper()
|
||||
_, err := q.Exec(ctx, `
|
||||
INSERT INTO payments (booking_id, payment_type, payment_method, amount, status)
|
||||
VALUES ($1, 'partial', 'discount', $2, 'completed')
|
||||
`, bookingID, amount)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create discount payment: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user