Files
member-console/internal/server/format_currency_test.go
T
cgalo5758 88db730fcc Add dual licensing and SPDX headers
Introduce a commercial license option alongside AGPL-3.0-only, require a
CLA for contributors, and document the terms in COMMERCIAL.md and
NOTICE. Add a script to stamp SPDX headers on Go files and apply it
across the tree.
2026-09-06 02:29:42 -05:00

39 lines
1.3 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
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)
}
})
}
}