mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
- 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.
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestInitiateTransfer_404DoesNotPanic(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Moneycorp answers 404 when the source account is unknown. The error
|
|
// checker maps it to a nil error, so the body is empty and Transfer is
|
|
// nil. The client must surface a non-retryable error, not panic.
|
|
c, server := newTestClient(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
_, _ = w.Write([]byte(`{"errors":[{"detail":"account not found"}]}`))
|
|
})
|
|
defer server.Close()
|
|
|
|
resp, err := c.InitiateTransfer(context.Background(), &TransferRequest{SourceAccountID: "123"})
|
|
require.Error(t, err)
|
|
require.Nil(t, resp)
|
|
require.ErrorIs(t, err, models.ErrInvalidRequest)
|
|
}
|
|
|
|
func TestInitiateTransfer_EmptyBody(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
c, server := newTestClient(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write([]byte(`{}`))
|
|
})
|
|
defer server.Close()
|
|
|
|
resp, err := c.InitiateTransfer(context.Background(), &TransferRequest{SourceAccountID: "123"})
|
|
require.Error(t, err)
|
|
require.Nil(t, resp)
|
|
require.ErrorIs(t, err, models.ErrInvalidRequest)
|
|
require.Contains(t, err.Error(), "empty response")
|
|
}
|
|
|
|
func TestInitiateTransfer_Success(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
c, server := newTestClient(func(w http.ResponseWriter, r *http.Request) {
|
|
require.Equal(t, http.MethodPost, r.Method)
|
|
w.WriteHeader(http.StatusOK)
|
|
_ = json.NewEncoder(w).Encode(transferResponse{Transfer: &TransferResponse{ID: "tr_1"}})
|
|
})
|
|
defer server.Close()
|
|
|
|
resp, err := c.InitiateTransfer(context.Background(), &TransferRequest{SourceAccountID: "123"})
|
|
require.NoError(t, err)
|
|
require.NotNil(t, resp)
|
|
require.Equal(t, "tr_1", resp.ID)
|
|
}
|
|
|
|
func TestGetTransfer_404DoesNotPanic(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
c, server := newTestClient(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
_, _ = w.Write([]byte(`{}`))
|
|
})
|
|
defer server.Close()
|
|
|
|
resp, err := c.GetTransfer(context.Background(), "123", "tr_1")
|
|
require.Error(t, err)
|
|
require.Nil(t, resp)
|
|
require.ErrorIs(t, err, models.ErrInvalidRequest)
|
|
}
|