package server import "testing" // TestFormatCurrency covers finding #12: formatCurrency used to hardcode a // "$" prefix regardless of currency and always divided by 100, which is // wrong for zero-decimal currencies (e.g. JPY). The fixed formatter must // prefix the uppercase ISO-4217 code (no symbol) and only divide by 100 for // currencies with a minor unit. func TestFormatCurrency(t *testing.T) { cases := []struct { name string amount int32 currency string want string }{ {"usd lowercase code uppercases", 1000, "usd", "USD 10.00"}, {"usd already uppercase", 1000, "USD", "USD 10.00"}, {"eur no dollar sign", 1000, "eur", "EUR 10.00"}, {"sub-dollar amount", 99, "usd", "USD 0.99"}, {"zero amount", 0, "usd", "USD 0.00"}, {"jpy zero-decimal not divided by 100", 1000, "jpy", "JPY 1000"}, {"jpy uppercase input", 500, "JPY", "JPY 500"}, {"krw zero-decimal", 15000, "krw", "KRW 15000"}, {"negative amount preserved", -500, "usd", "USD -5.00"}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { got := formatCurrency(tc.amount, tc.currency) if got != tc.want { t.Errorf("formatCurrency(%d, %q) = %q, want %q", tc.amount, tc.currency, got, tc.want) } }) } }