From 1c004dd838a0dfa51ff28dcbfed9670e39d977bd Mon Sep 17 00:00:00 2001 From: marcusDenslow Date: Fri, 5 Jun 2026 23:45:44 +0200 Subject: [PATCH] fix(test): pin coffee price in cart-limit fixture TestConvertCartLimit's quantities and expected totals were keyed to the original 500-cent latte price. After the product price bump in 1ce63fb, coffee_id=4 became 2500 cents, so under_cap/at_cap subtests overshot the $200 cap and over_cap's expected total magnitude was wrong by 5x. Override coffee_id=4's price to 500 in test setup so the cap math stays stable regardless of seed changes. --- api/handlers/cart_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/api/handlers/cart_test.go b/api/handlers/cart_test.go index c520c02..c80a5e7 100644 --- a/api/handlers/cart_test.go +++ b/api/handlers/cart_test.go @@ -709,6 +709,14 @@ func TestConvertCartLimit(t *testing.T) { t.Fatalf("seed card: %v", err) } + // Pin coffee_id=4's price so cart-cap math stays stable across + // seed-price changes. The cap test is about (price * quantity) + // vs cap, not which coffee or what the menu currently charges. + const pinnedPrice = 500 + if err := db.Model(&models.Coffee{}).Where("id = ?", 4).Update("price", pinnedPrice).Error; err != nil { + t.Fatalf("pin coffee price: %v", err) + } + handler := NewCartHandler("", "", tc.capCents) body, _ := json.Marshal(map[string]interface{}{"coffee_id": 4, "quantity": tc.quantity}) @@ -760,8 +768,8 @@ func TestConvertCartLimit(t *testing.T) { if got, _ := resp.Error.Details["limit_cents"].(float64); int(got) != tc.capCents { t.Errorf("limit_cents in details: want %d, got %v", tc.capCents, resp.Error.Details["limit_cents"]) } - if got, _ := resp.Error.Details["total_cents"].(float64); int(got) != tc.quantity*500 { - t.Errorf("total_cents in details: want %d, got %v", tc.quantity*500, resp.Error.Details["total_cents"]) + if got, _ := resp.Error.Details["total_cents"].(float64); int(got) != tc.quantity*pinnedPrice { + t.Errorf("total_cents in details: want %d, got %v", tc.quantity*pinnedPrice, resp.Error.Details["total_cents"]) } } })