From 135f1361e4e924cf5577ddc93f979452ebdac167 Mon Sep 17 00:00:00 2001 From: marcus06 Date: Fri, 5 Jun 2026 23:49:03 +0200 Subject: [PATCH] fix(products): update pricing on products (#34) * fix(products): update pricing on products * 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 ++++++++++-- pkg/database/seed.go | 15 ++++++++------- 2 files changed, 18 insertions(+), 9 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"]) } } }) diff --git a/pkg/database/seed.go b/pkg/database/seed.go index 812e3d0..4d21fef 100644 --- a/pkg/database/seed.go +++ b/pkg/database/seed.go @@ -4,8 +4,9 @@ import ( "fmt" "log" - "gorm.io/gorm" "terminalShop/pkg/models" + + "gorm.io/gorm" ) // Seed populates the database with initial data @@ -27,7 +28,7 @@ func Seed(db *gorm.DB) error { RoastType: "Dark Roast", Ounces: 2, BeanType: "Arabica", - Price: 350, // $3.50 + Price: 1800, // $18.00 Color: "#8B4513", Description: "Bold and intense coffee with a rich crema", }, @@ -36,7 +37,7 @@ func Seed(db *gorm.DB) error { RoastType: "Medium Roast", Ounces: 8, BeanType: "Arabica", - Price: 400, // $4.00 + Price: 2200, // $22.00 Color: "#A0522D", Description: "Smooth and balanced espresso diluted with hot water", }, @@ -45,7 +46,7 @@ func Seed(db *gorm.DB) error { RoastType: "Medium Roast", Ounces: 6, BeanType: "Arabica", - Price: 450, // $4.50 + Price: 2200, // $22.00 Color: "#C4A574", Description: "Espresso with steamed milk and a thick layer of foam", }, @@ -54,7 +55,7 @@ func Seed(db *gorm.DB) error { RoastType: "Medium Roast", Ounces: 12, BeanType: "Arabica", - Price: 500, // $5.00 + Price: 2500, // $25.00 Color: "#D2B48C", Description: "Creamy espresso with plenty of steamed milk and a touch of foam", }, @@ -63,7 +64,7 @@ func Seed(db *gorm.DB) error { RoastType: "Dark Roast", Ounces: 12, BeanType: "Arabica", - Price: 550, // $5.50 + Price: 3000, // $30.00 Color: "#8B4513", Description: "Chocolate and espresso combined with steamed milk. Sweet and indulgent.", }, @@ -72,7 +73,7 @@ func Seed(db *gorm.DB) error { RoastType: "Dark Roast", Ounces: 3, BeanType: "Robusta Blend", - Price: 425, // $4.25 + Price: 1800, // $18.00 Color: "#DAA520", Description: "Espresso 'marked' with a dollop of foamed milk. Small but mighty, like a tiny caffeinated warrior.", },