fix: remove nonDepositPaymentType dead code, wire dead handlers to routes
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
//lint:ignore U1000 referenced from tests
|
||||
//lint:ignore U1000 referenced from tests; route DELETE /api/bookings/{id} conflicts with bookings.DeleteBookingHandler at main.go:360
|
||||
func UserCancelBookingHandler(w http.ResponseWriter, r *http.Request) {
|
||||
bookingID := chi.URLParam(r, "id")
|
||||
if bookingID == "" || !validators.IsValidID(bookingID) {
|
||||
@@ -305,7 +305,7 @@ type AdminCreateBookingForUserRequest struct {
|
||||
OutOfHours bool `json:"out_of_hours"`
|
||||
}
|
||||
|
||||
//lint:ignore U1000 referenced from tests
|
||||
//lint:ignore U1000 referenced from tests; route GET /api/admin/today/current-next conflicts with today.GetCurrentAndNextHandler at main.go:452
|
||||
func AdminGetInProgressBookingHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var b Booking
|
||||
var userID, fullName string
|
||||
|
||||
@@ -1433,25 +1433,6 @@ func buildSplitRecords(primary PaymentRecord, reqPaymentType string, info *Booki
|
||||
return records
|
||||
}
|
||||
|
||||
// nonDepositPaymentType picks the right label for the non-deposit portion of a
|
||||
// split payment, following the same rules as the frontend's handlePayFull:
|
||||
// 'balance' when some payment already exists, 'full' when covering everything,
|
||||
// 'partial' when leaving a remainder.
|
||||
//
|
||||
//lint:ignore U1000 reserved for future use
|
||||
func nonDepositPaymentType(reqType string, totalPaidAfterThis float64, thisPortion float64, bookingTotal float64) string {
|
||||
if totalPaidAfterThis >= bookingTotal {
|
||||
if totalPaidAfterThis-thisPortion > 0 {
|
||||
return "balance"
|
||||
}
|
||||
return "full"
|
||||
}
|
||||
if reqType == "full" || reqType == "deposit" {
|
||||
return "partial"
|
||||
}
|
||||
return "partial"
|
||||
}
|
||||
|
||||
func GetUserPaymentMethods(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := r.Context().Value(mw.UserIDKey).(string)
|
||||
if !ok || userID == "" {
|
||||
|
||||
@@ -1431,56 +1431,6 @@ func TestBookingPayment_TransactionAtomicity_SplitRollsBackOnError(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// nonDepositPaymentType unit tests — pure function, no DB needed.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
func TestNonDepositPaymentType_FirstPaymentFull(t *testing.T) {
|
||||
// First-ever payment, paying full amount → "full"
|
||||
result := nonDepositPaymentType("full", 100, 100, 100)
|
||||
if result != "full" {
|
||||
t.Errorf("expected 'full', got %q", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonDepositPaymentType_BalanceWhenPriorExists(t *testing.T) {
|
||||
// Total paid after this = 100, portion = 50, prior = 50 → "balance"
|
||||
result := nonDepositPaymentType("balance", 100, 50, 100)
|
||||
if result != "balance" {
|
||||
t.Errorf("expected 'balance', got %q", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonDepositPaymentType_PartialWhenUnderTotal(t *testing.T) {
|
||||
// Paying 30 on a 100 total → "partial"
|
||||
result := nonDepositPaymentType("partial", 30, 30, 100)
|
||||
if result != "partial" {
|
||||
t.Errorf("expected 'partial', got %q", result)
|
||||
}
|
||||
|
||||
// Same result when request type is "full" but amount doesn't cover total
|
||||
result = nonDepositPaymentType("full", 80, 80, 100)
|
||||
if result != "partial" {
|
||||
t.Errorf("expected 'partial' when full doesn't cover total, got %q", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonDepositPaymentType_FullWhenFirstPaymentFullyCovers(t *testing.T) {
|
||||
// First payment ever, exactly covers total → "full"
|
||||
result := nonDepositPaymentType("full", 100, 100, 100)
|
||||
if result != "full" {
|
||||
t.Errorf("expected 'full', got %q", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonDepositPaymentType_DepositReqTypeBecomesPartial(t *testing.T) {
|
||||
// Request type is "deposit" but amount doesn't fully cover → "partial"
|
||||
result := nonDepositPaymentType("deposit", 30, 30, 100)
|
||||
if result != "partial" {
|
||||
t.Errorf("expected 'partial' for deposit type under total, got %q", result)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// buildSplitRecords unit tests — pure function, no DB needed.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user