Files
member-console/internal/server/format_currency_test.go
T
cgalo5758 8514df5b50 Remediate operator UX audit findings
Fix HTMX expired-session handling, CSP-blocked form behaviors, reorder
recovery, billing currency display, plan/checkout guards, FedWiki quota
edge cases, and operator/member empty/error states.

Add entitlement uniqueness migrations, canonical migration source
wiring,
and regression coverage for the remediated flows. Update status docs
with
the audit triage and model inventory.
2026-07-03 11:58:03 -05:00

36 lines
1.2 KiB
Go

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)
}
})
}
}