Files
zeekay 7d727874d5 chore: rebrand Formance Payments -> Hanzo Payments (hanzo-fi)
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments
  (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins).
  External dep kept: formancehq/go-libs.
- plugins: each ce/plugins/* consumed a *published* pkg/domain; added local
  'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every
  standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too.
- branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added),
  goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage),
  proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl.
- CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml +
  cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet).
- kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type
  client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image.
- verified: go build ./... (default + -tags ee) + all 20 nested modules green.
2026-07-05 13:08:55 -07:00

65 lines
1.7 KiB
Go

package mappers
import (
"encoding/json"
"math/big"
"testing"
"time"
"github.com/hanzo-fi/payments/ee/plugins/bitstamp/client"
"github.com/hanzo-fi/payments/pkg/domain/models"
)
func TestAccountBalanceToPSPBalance(t *testing.T) {
t.Parallel()
bal := client.AccountBalance{Currency: "btc", Total: "1.5", Available: "1.25000000", Reserved: "0.25"}
raw, _ := json.Marshal(bal)
asset := "BTC/8"
parent := models.PSPAccount{
Reference: "BTC",
DefaultAsset: &asset,
Raw: raw,
}
observedAt := time.Date(2025, 9, 25, 14, 42, 59, 0, time.UTC)
got, err := AccountBalanceToPSPBalance(testCurrencies, parent, observedAt)
if err != nil {
t.Fatalf("err: %v", err)
}
if got.AccountReference != "BTC" {
t.Errorf("reference=%q, want BTC", got.AccountReference)
}
if got.Asset != "BTC/8" {
t.Errorf("asset=%q, want BTC/8", got.Asset)
}
want := big.NewInt(125000000)
if got.Amount.Cmp(want) != 0 {
t.Errorf("amount=%s, want %s", got.Amount, want)
}
if !got.CreatedAt.Equal(observedAt) {
t.Errorf("createdAt=%v, want %v", got.CreatedAt, observedAt)
}
}
func TestAccountBalanceToPSPBalanceMissingRaw(t *testing.T) {
t.Parallel()
_, err := AccountBalanceToPSPBalance(testCurrencies, models.PSPAccount{Reference: "BTC"}, time.Now())
if err == nil {
t.Fatal("expected error on missing Raw")
}
}
func TestAccountBalanceToPSPBalanceUnknownCurrency(t *testing.T) {
t.Parallel()
bal := client.AccountBalance{Currency: "xyz", Available: "1.0"}
raw, _ := json.Marshal(bal)
parent := models.PSPAccount{Reference: "XYZ", Raw: raw}
got, err := AccountBalanceToPSPBalance(testCurrencies, parent, time.Now())
if err != nil {
t.Fatalf("err: %v", err)
}
if got != nil {
t.Errorf("unknown currency should map to nil, got %#v", got)
}
}