Files
online-backend/internal/payment/visamasterpay/db/helpers_test.go
T
guwandyk e47e8c24d0
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled
added log
2026-09-28 16:53:34 +05:00

62 lines
2.1 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")
}
}