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

83 lines
2.8 KiB
Go

package bankingbridge
import (
"context"
"encoding/json"
"errors"
"time"
"github.com/hanzo-fi/payments/ee/plugins/bankingbridge/client"
"github.com/hanzo-fi/payments/pkg/domain/plugins"
"github.com/hanzo-fi/payments/pkg/domain/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
func (suite *PluginTestSuite) TestFetchNextBalances_Success() {
ctx := context.Background()
req := models.FetchNextBalancesRequest{
PageSize: 2,
State: nil,
}
reportedAt := time.Now().Add(-time.Hour).Truncate(time.Millisecond).UTC()
importedAt1 := time.Now().Add(-time.Minute).Truncate(time.Millisecond).UTC()
importedAt2 := time.Now().Truncate(time.Millisecond).UTC()
bals := []client.Balance{
{AccountReference: "acc1", AmountInMinors: int64(1234), Asset: "EUR", ReportedAt: reportedAt, ImportedAt: importedAt1},
{AccountReference: "acc2", AmountInMinors: int64(999), Asset: "USD", ReportedAt: reportedAt, ImportedAt: importedAt2},
}
newCursor := "newCursor"
suite.client.EXPECT().GetAccountBalances(gomock.Any(), "", "", req.PageSize).Return(bals, true, newCursor, nil)
resp, err := suite.plugin.FetchNextBalances(ctx, req)
require.NoError(suite.T(), err)
assert.Len(suite.T(), resp.Balances, len(bals))
assert.Equal(suite.T(), bals[0].AccountReference, resp.Balances[0].AccountReference)
assert.Equal(suite.T(), bals[0].Asset, resp.Balances[0].Asset)
assert.Equal(suite.T(), bals[0].ReportedAt, resp.Balances[0].CreatedAt)
require.NotNil(suite.T(), resp.Balances[0].Amount)
assert.Equal(suite.T(), bals[0].AmountInMinors, resp.Balances[0].Amount.Int64())
assert.True(suite.T(), resp.HasMore)
var state workflowState
err = json.Unmarshal(resp.NewState, &state)
require.NoError(suite.T(), err)
assert.Equal(suite.T(), newCursor, state.Cursor)
lastSeenImportedAt, err := time.Parse(ImportedAtLayout, state.LastSeenImportedAt)
require.NoError(suite.T(), err)
assert.Equal(suite.T(), importedAt2, lastSeenImportedAt)
}
func (suite *PluginTestSuite) TestFetchNextBalances_ClientError() {
ctx := context.Background()
req := models.FetchNextBalancesRequest{
PageSize: 2,
State: nil,
}
expectedErr := errors.New("expected")
suite.client.EXPECT().GetAccountBalances(gomock.Any(), "", "", req.PageSize).Return(nil, false, "", expectedErr)
_, err := suite.plugin.FetchNextBalances(ctx, req)
require.Error(suite.T(), err)
assert.Equal(suite.T(), expectedErr, err)
}
func (suite *PluginTestSuite) TestFetchNextBalances_NotYetInstalled() {
ctx := context.Background()
req := models.FetchNextBalancesRequest{
PageSize: 2,
State: nil,
}
suite.plugin.client = nil
_, err := suite.plugin.FetchNextBalances(ctx, req)
assert.Error(suite.T(), err)
assert.Equal(suite.T(), plugins.ErrNotYetInstalled, err)
}