Compare commits

...

2 Commits

Author SHA1 Message Date
1c004dd838 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.
2026-06-05 23:45:44 +02:00
1ce63fbdb9 fix(products): update pricing on products 2026-06-05 23:38:54 +02:00
2 changed files with 18 additions and 9 deletions

View File

@@ -709,6 +709,14 @@ func TestConvertCartLimit(t *testing.T) {
t.Fatalf("seed card: %v", err) 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) handler := NewCartHandler("", "", tc.capCents)
body, _ := json.Marshal(map[string]interface{}{"coffee_id": 4, "quantity": tc.quantity}) 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 { 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"]) 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 { 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*500, resp.Error.Details["total_cents"]) t.Errorf("total_cents in details: want %d, got %v", tc.quantity*pinnedPrice, resp.Error.Details["total_cents"])
} }
} }
}) })

View File

@@ -4,8 +4,9 @@ import (
"fmt" "fmt"
"log" "log"
"gorm.io/gorm"
"terminalShop/pkg/models" "terminalShop/pkg/models"
"gorm.io/gorm"
) )
// Seed populates the database with initial data // Seed populates the database with initial data
@@ -27,7 +28,7 @@ func Seed(db *gorm.DB) error {
RoastType: "Dark Roast", RoastType: "Dark Roast",
Ounces: 2, Ounces: 2,
BeanType: "Arabica", BeanType: "Arabica",
Price: 350, // $3.50 Price: 1800, // $18.00
Color: "#8B4513", Color: "#8B4513",
Description: "Bold and intense coffee with a rich crema", Description: "Bold and intense coffee with a rich crema",
}, },
@@ -36,7 +37,7 @@ func Seed(db *gorm.DB) error {
RoastType: "Medium Roast", RoastType: "Medium Roast",
Ounces: 8, Ounces: 8,
BeanType: "Arabica", BeanType: "Arabica",
Price: 400, // $4.00 Price: 2200, // $22.00
Color: "#A0522D", Color: "#A0522D",
Description: "Smooth and balanced espresso diluted with hot water", Description: "Smooth and balanced espresso diluted with hot water",
}, },
@@ -45,7 +46,7 @@ func Seed(db *gorm.DB) error {
RoastType: "Medium Roast", RoastType: "Medium Roast",
Ounces: 6, Ounces: 6,
BeanType: "Arabica", BeanType: "Arabica",
Price: 450, // $4.50 Price: 2200, // $22.00
Color: "#C4A574", Color: "#C4A574",
Description: "Espresso with steamed milk and a thick layer of foam", Description: "Espresso with steamed milk and a thick layer of foam",
}, },
@@ -54,7 +55,7 @@ func Seed(db *gorm.DB) error {
RoastType: "Medium Roast", RoastType: "Medium Roast",
Ounces: 12, Ounces: 12,
BeanType: "Arabica", BeanType: "Arabica",
Price: 500, // $5.00 Price: 2500, // $25.00
Color: "#D2B48C", Color: "#D2B48C",
Description: "Creamy espresso with plenty of steamed milk and a touch of foam", 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", RoastType: "Dark Roast",
Ounces: 12, Ounces: 12,
BeanType: "Arabica", BeanType: "Arabica",
Price: 550, // $5.50 Price: 3000, // $30.00
Color: "#8B4513", Color: "#8B4513",
Description: "Chocolate and espresso combined with steamed milk. Sweet and indulgent.", Description: "Chocolate and espresso combined with steamed milk. Sweet and indulgent.",
}, },
@@ -72,7 +73,7 @@ func Seed(db *gorm.DB) error {
RoastType: "Dark Roast", RoastType: "Dark Roast",
Ounces: 3, Ounces: 3,
BeanType: "Robusta Blend", BeanType: "Robusta Blend",
Price: 425, // $4.25 Price: 1800, // $18.00
Color: "#DAA520", Color: "#DAA520",
Description: "Espresso 'marked' with a dollop of foamed milk. Small but mighty, like a tiny caffeinated warrior.", Description: "Espresso 'marked' with a dollop of foamed milk. Small but mighty, like a tiny caffeinated warrior.",
}, },