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

241 lines
7.0 KiB
Go

package tink
import (
"encoding/json"
"errors"
"time"
"github.com/hanzo-fi/payments/ce/plugins/tink/client"
"github.com/hanzo-fi/payments/pkg/domain/models"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
gomock "go.uber.org/mock/gomock"
)
var _ = Describe("Tink *Plugin Accounts", func() {
Context("fetchNextAccounts", func() {
var (
ctrl *gomock.Controller
plg models.Plugin
m *client.MockClient
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
m = client.NewMockClient(ctrl)
plg = &Plugin{
client: m,
}
})
AfterEach(func() {
ctrl.Finish()
})
It("should fetch accounts successfully", func(ctx SpecContext) {
userID := uuid.New()
accountID := "test_account_id"
// Create the webhook payload with proper time values
webhookPayload := fetchNextDataRequest{
UserID: userID.String(),
ExternalUserID: userID.String(),
AccountID: accountID,
TransactionEarliestModifiedBookedDate: time.Now().Add(-24 * time.Hour),
TransactionLatestModifiedBookedDate: time.Now(),
}
webhookPayloadBytes, err := json.Marshal(webhookPayload)
Expect(err).To(BeNil())
// Create the from payload using only FromPayload to avoid issues
fromPayload := models.OpenBankingForwardedUserFromPayload{
FromPayload: webhookPayloadBytes,
}
fromPayloadBytes, err := json.Marshal(fromPayload)
Expect(err).To(BeNil())
// Mock the client response
expectedAccount := client.Account{
ID: accountID,
Name: "Test Account",
Type: "CHECKING",
}
m.EXPECT().GetAccount(gomock.Any(), userID.String(), accountID).Return(expectedAccount, nil)
req := models.FetchNextAccountsRequest{
FromPayload: fromPayloadBytes,
}
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Accounts).To(HaveLen(1))
account := resp.Accounts[0]
Expect(account.Reference).To(Equal(accountID))
Expect(*account.Name).To(Equal("Test Account"))
Expect(account.Metadata).To(HaveLen(0)) // No OB Provider psu metadata
Expect(account.Raw).ToNot(BeNil())
})
It("should handle client error", func(ctx SpecContext) {
userID := uuid.New()
accountID := "test_account_id"
// Create the webhook payload
webhookPayload := fetchNextDataRequest{
UserID: userID.String(),
ExternalUserID: userID.String(),
AccountID: accountID,
}
webhookPayloadBytes, err := json.Marshal(webhookPayload)
Expect(err).To(BeNil())
// Create the open banking forwarded user from payload
fromPayload := models.OpenBankingForwardedUserFromPayload{
FromPayload: webhookPayloadBytes,
}
fromPayloadBytes, err := json.Marshal(fromPayload)
Expect(err).To(BeNil())
// Mock the client error
m.EXPECT().GetAccount(gomock.Any(), userID.String(), accountID).Return(client.Account{}, errors.New("client error"))
req := models.FetchNextAccountsRequest{
FromPayload: fromPayloadBytes,
}
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).ToNot(BeNil())
Expect(resp).To(Equal(models.FetchNextAccountsResponse{}))
})
It("should handle invalid from payload", func(ctx SpecContext) {
req := models.FetchNextAccountsRequest{
FromPayload: []byte("invalid json"),
}
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).ToNot(BeNil())
Expect(resp).To(Equal(models.FetchNextAccountsResponse{}))
})
It("should handle invalid webhook payload", func(ctx SpecContext) {
// Create invalid from payload by directly using invalid JSON bytes
fromPayloadBytes := []byte(`{"fromPayload": "invalid json"}`)
req := models.FetchNextAccountsRequest{
FromPayload: fromPayloadBytes,
}
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).ToNot(BeNil())
Expect(resp).To(Equal(models.FetchNextAccountsResponse{}))
})
It("should handle missing ob provider psu metadata", func(ctx SpecContext) {
userID := uuid.New()
accountID := "test_account_id"
// Create the webhook payload
webhookPayload := fetchNextDataRequest{
UserID: userID.String(),
ExternalUserID: userID.String(),
AccountID: accountID,
}
webhookPayloadBytes, err := json.Marshal(webhookPayload)
Expect(err).To(BeNil())
// Create the from payload without open banking forwarded user
fromPayload := models.OpenBankingForwardedUserFromPayload{
FromPayload: webhookPayloadBytes,
}
fromPayloadBytes, err := json.Marshal(fromPayload)
Expect(err).To(BeNil())
// Mock the client response
expectedAccount := client.Account{
ID: accountID,
Name: "Test Account",
Type: "CHECKING",
}
m.EXPECT().GetAccount(gomock.Any(), userID.String(), accountID).Return(expectedAccount, nil)
req := models.FetchNextAccountsRequest{
FromPayload: fromPayloadBytes,
}
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Accounts).To(HaveLen(1))
account := resp.Accounts[0]
Expect(account.Reference).To(Equal(accountID))
Expect(*account.Name).To(Equal("Test Account"))
Expect(account.Metadata).To(HaveLen(0))
})
})
Context("toPSPAccounts", func() {
It("should convert client accounts to PSP accounts", func() {
psuID := uuid.New()
connectionID := "test_connection_id"
clientAccounts := []client.Account{
{
ID: "account1",
Name: "Account 1",
Type: "CHECKING",
},
{
ID: "account2",
Name: "Account 2",
Type: "SAVINGS",
},
}
fromPayload := models.OpenBankingForwardedUserFromPayload{
PSUID: psuID,
OpenBankingForwardedUser: &models.OpenBankingForwardedUser{
PsuID: psuID,
},
OpenBankingConnection: &models.OpenBankingConnection{
ConnectionID: connectionID,
},
}
accounts := make([]models.PSPAccount, 0)
result, err := toPSPAccounts(accounts, clientAccounts, fromPayload)
Expect(err).To(BeNil())
Expect(result).To(HaveLen(2))
// Check first account
Expect(result[0].Reference).To(Equal("account1"))
Expect(*result[0].Name).To(Equal("Account 1"))
Expect(result[0].PsuID).To(Not(BeNil()))
Expect(*result[0].PsuID).To(Equal(psuID))
Expect(result[0].OpenBankingConnectionID).To(Not(BeNil()))
Expect(*result[0].OpenBankingConnectionID).To(Equal(connectionID))
Expect(result[0].Raw).ToNot(BeNil())
// Check second account
Expect(result[1].Reference).To(Equal("account2"))
Expect(*result[1].Name).To(Equal("Account 2"))
Expect(result[1].PsuID).To(Not(BeNil()))
Expect(*result[1].PsuID).To(Equal(psuID))
Expect(result[1].OpenBankingConnectionID).To(Not(BeNil()))
Expect(*result[1].OpenBankingConnectionID).To(Equal(connectionID))
Expect(result[1].Raw).ToNot(BeNil())
})
It("should handle JSON marshaling error", func() {
// This test would require mocking json.Marshal which is not easily done
// The function should handle this gracefully, but we can't easily test it
// without more complex mocking
})
})
})