From e908a4130bd48a25d43cb4577e96c8907bd34177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20T=C3=B6rnberg?= Date: Tue, 14 Oct 2025 19:38:38 +0200 Subject: [PATCH] more tests --- cmd/cart/price.go | 2 +- cmd/cart/price_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/cart/price.go b/cmd/cart/price.go index efe13e8..4d66ee4 100644 --- a/cmd/cart/price.go +++ b/cmd/cart/price.go @@ -25,7 +25,7 @@ func NewPrice() *Price { func NewPriceFromIncVat(incVat int64, taxRate float32) *Price { tax := GetTaxAmount(incVat, int(taxRate*100)) return &Price{ - IncVat: incVat - tax, + IncVat: incVat, VatRates: map[float32]int64{ taxRate: tax, }, diff --git a/cmd/cart/price_test.go b/cmd/cart/price_test.go index 6f847c6..b7d697a 100644 --- a/cmd/cart/price_test.go +++ b/cmd/cart/price_test.go @@ -32,6 +32,19 @@ func TestPriceMarshalJSON(t *testing.T) { } } +func TestNewPriceFromIncVat(t *testing.T) { + p := NewPriceFromIncVat(1000, 0.25) + if p.IncVat != 1000 { + t.Fatalf("expected IncVat %d got %d", 1000, p.IncVat) + } + if p.VatRates[25] != 250 { + t.Fatalf("expected VAT 25 rate %d got %d", 250, p.VatRates[25]) + } + if p.ValueExVat() != 750 { + t.Fatalf("expected exVat %d got %d", 750, p.ValueExVat()) + } +} + func TestSumPrices(t *testing.T) { // We'll construct prices via raw struct since constructor expects tax math. // IncVat already includes vat portions.