70 lines
2.4 KiB
Go
70 lines
2.4 KiB
Go
package db
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRound2(t *testing.T) {
|
|
// Values that round cleanly.
|
|
cases := map[float64]float64{
|
|
2.344: 2.34,
|
|
100.0: 100.0,
|
|
0.1 + 0.2: 0.30,
|
|
}
|
|
for in, want := range cases {
|
|
if got := round2(in); got != want {
|
|
t.Errorf("round2(%v)=%v want %v", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// round2 is built on float64 (math.Round(v*100)/100). Classic .xx5 amounts
|
|
// like 1.005 and 2.345 are NOT representable exactly, so they round DOWN
|
|
// instead of to the nearer cent. This test pins that real behaviour: money
|
|
// math on float64 loses tenths of a cent, which is why totals should be
|
|
// computed in integer minor units (tetri) or a decimal type. If round2 is
|
|
// ever fixed to true half-up cents, update these expectations deliberately.
|
|
func TestRound2_FloatImprecision(t *testing.T) {
|
|
// 1.005 cannot be represented exactly; v*100 lands just under 100.5, so
|
|
// math.Round drops it to 100 -> 1.00 instead of the expected 1.01.
|
|
if got := round2(1.005); got != 1.00 {
|
|
t.Errorf("round2(1.005)=%v; documented float behaviour is 1.00 (loses a cent)", got)
|
|
}
|
|
}
|
|
|
|
func TestIsSber(t *testing.T) {
|
|
sber := "sber"
|
|
upper := " SBER "
|
|
visa := "visa"
|
|
if !isSber(&sber) || !isSber(&upper) {
|
|
t.Error("sber/SBER should be detected (case- and space-insensitive)")
|
|
}
|
|
if isSber(&visa) || isSber(nil) {
|
|
t.Error("non-sber and nil should be false")
|
|
}
|
|
}
|
|
|
|
// isPayableDay currently has skipPayableDayCheck hard-wired to true, so it
|
|
// returns true for EVERY day - including weekends. This test documents that
|
|
// live behaviour so it can't change silently: if the weekend guard is ever
|
|
// re-enabled, this test will flip and force a deliberate update.
|
|
func TestIsPayableDay_GuardIsDisabled(t *testing.T) {
|
|
saturday := time.Date(2026, 9, 26, 12, 0, 0, 0, ashgabatZone) // a Saturday
|
|
sunday := time.Date(2026, 9, 27, 12, 0, 0, 0, ashgabatZone) // a Sunday
|
|
if !skipPayableDayCheck {
|
|
t.Skip("weekend guard re-enabled; update this test intentionally")
|
|
}
|
|
if !isPayableDay(saturday) || !isPayableDay(sunday) {
|
|
t.Error("with skipPayableDayCheck=true, weekends must still report payable")
|
|
}
|
|
}
|
|
|
|
func TestNewOrderNumber(t *testing.T) {
|
|
// 29.09.2026 08:38:08 UTC is 13:38:08 in Ashgabat (+05).
|
|
at := time.Date(2026, 9, 29, 8, 38, 8, 0, time.UTC)
|
|
if got, want := newOrderNumber(at), "290926133808"; got != want {
|
|
t.Errorf("newOrderNumber(%v)=%q want %q", at, got, want)
|
|
}
|
|
}
|