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.
182 lines
5.2 KiB
Go
182 lines
5.2 KiB
Go
package plaid
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/hanzo-fi/payments/ce/plugins/plaid/client"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/google/uuid"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/plaid/plaid-go/v34/plaid"
|
|
gomock "go.uber.org/mock/gomock"
|
|
)
|
|
|
|
var _ = Describe("Plaid *Plugin Accounts", func() {
|
|
Context("fetch next accounts", func() {
|
|
var (
|
|
ctrl *gomock.Controller
|
|
plg models.Plugin
|
|
m *client.MockClient
|
|
|
|
sampleAccounts []plaid.AccountBase
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
ctrl = gomock.NewController(GinkgoT())
|
|
m = client.NewMockClient(ctrl)
|
|
plg = &Plugin{client: m}
|
|
|
|
sampleAccounts = make([]plaid.AccountBase, 0)
|
|
for i := 0; i < 3; i++ {
|
|
account := plaid.NewAccountBaseWithDefaults()
|
|
account.SetAccountId(fmt.Sprintf("account_%d", i))
|
|
account.SetName(fmt.Sprintf("Account %d", i))
|
|
account.SetType(plaid.ACCOUNTTYPE_DEPOSITORY)
|
|
|
|
balance := plaid.NewAccountBalanceWithDefaults()
|
|
balance.SetIsoCurrencyCode("USD")
|
|
account.SetBalances(*balance)
|
|
|
|
sampleAccounts = append(sampleAccounts, *account)
|
|
}
|
|
})
|
|
|
|
AfterEach(func() {
|
|
ctrl.Finish()
|
|
})
|
|
|
|
It("should return an error - list accounts error", func(ctx SpecContext) {
|
|
fromPayload := models.OpenBankingForwardedUserFromPayload{
|
|
OpenBankingConnection: &models.OpenBankingConnection{
|
|
ConnectorID: models.ConnectorID{
|
|
Reference: uuid.New(),
|
|
Provider: "plaid-test",
|
|
},
|
|
AccessToken: &models.Token{Token: "test-token"},
|
|
ConnectionID: "test-connection",
|
|
},
|
|
FromPayload: json.RawMessage(`{}`),
|
|
}
|
|
fromPayloadBytes, _ := json.Marshal(fromPayload)
|
|
|
|
req := models.FetchNextAccountsRequest{
|
|
FromPayload: fromPayloadBytes,
|
|
}
|
|
|
|
m.EXPECT().ListAccounts(gomock.Any(), "test-token").Return(
|
|
plaid.AccountsGetResponse{},
|
|
errors.New("test error"),
|
|
)
|
|
|
|
resp, err := plg.FetchNextAccounts(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(err).To(MatchError("test error"))
|
|
Expect(resp).To(Equal(models.FetchNextAccountsResponse{}))
|
|
})
|
|
|
|
It("should fetch accounts successfully", func(ctx SpecContext) {
|
|
fromPayload := models.OpenBankingForwardedUserFromPayload{
|
|
OpenBankingConnection: &models.OpenBankingConnection{
|
|
ConnectorID: models.ConnectorID{
|
|
Reference: uuid.New(),
|
|
Provider: "plaid-test",
|
|
},
|
|
AccessToken: &models.Token{Token: "test-token"},
|
|
ConnectionID: "test-connection",
|
|
},
|
|
FromPayload: json.RawMessage(`{}`),
|
|
}
|
|
fromPayloadBytes, _ := json.Marshal(fromPayload)
|
|
|
|
req := models.FetchNextAccountsRequest{
|
|
FromPayload: fromPayloadBytes,
|
|
}
|
|
|
|
m.EXPECT().ListAccounts(gomock.Any(), "test-token").Return(
|
|
plaid.AccountsGetResponse{
|
|
Accounts: sampleAccounts,
|
|
},
|
|
nil,
|
|
)
|
|
|
|
resp, err := plg.FetchNextAccounts(ctx, req)
|
|
Expect(err).To(BeNil())
|
|
Expect(resp.Accounts).To(HaveLen(3))
|
|
Expect(resp.Accounts[0].Reference).To(Equal("account_0"))
|
|
Expect(resp.Accounts[0].Name).ToNot(BeNil())
|
|
Expect(*resp.Accounts[0].Name).To(Equal("Account 0"))
|
|
Expect(resp.Accounts[0].Metadata["accountType"]).To(Equal("depository"))
|
|
Expect(resp.Accounts[0].OpenBankingConnectionID).To(Not(BeNil()))
|
|
Expect(*resp.Accounts[0].OpenBankingConnectionID).To(Equal("test-connection"))
|
|
Expect(resp.Accounts[0].PsuID).To(Not(BeNil()))
|
|
Expect(*resp.Accounts[0].PsuID).To(Equal(fromPayload.PSUID))
|
|
})
|
|
|
|
It("should handle empty accounts response", func(ctx SpecContext) {
|
|
fromPayload := models.OpenBankingForwardedUserFromPayload{
|
|
OpenBankingConnection: &models.OpenBankingConnection{
|
|
ConnectorID: models.ConnectorID{
|
|
Reference: uuid.New(),
|
|
Provider: "plaid-test",
|
|
},
|
|
AccessToken: &models.Token{Token: "test-token"},
|
|
ConnectionID: "test-connection",
|
|
},
|
|
FromPayload: json.RawMessage(`{}`),
|
|
}
|
|
fromPayloadBytes, _ := json.Marshal(fromPayload)
|
|
|
|
req := models.FetchNextAccountsRequest{
|
|
FromPayload: fromPayloadBytes,
|
|
}
|
|
|
|
m.EXPECT().ListAccounts(gomock.Any(), "test-token").Return(
|
|
plaid.AccountsGetResponse{
|
|
Accounts: []plaid.AccountBase{},
|
|
},
|
|
nil,
|
|
)
|
|
|
|
resp, err := plg.FetchNextAccounts(ctx, req)
|
|
Expect(err).To(BeNil())
|
|
Expect(resp.Accounts).To(HaveLen(0))
|
|
})
|
|
|
|
It("should handle invalid from payload", func(ctx SpecContext) {
|
|
req := models.FetchNextAccountsRequest{
|
|
FromPayload: json.RawMessage(`invalid json`),
|
|
}
|
|
|
|
resp, err := plg.FetchNextAccounts(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(resp).To(Equal(models.FetchNextAccountsResponse{}))
|
|
})
|
|
|
|
It("should handle invalid base webhook payload", func(ctx SpecContext) {
|
|
fromPayload := models.OpenBankingForwardedUserFromPayload{
|
|
OpenBankingConnection: &models.OpenBankingConnection{
|
|
ConnectorID: models.ConnectorID{
|
|
Reference: uuid.New(),
|
|
Provider: "plaid-test",
|
|
},
|
|
AccessToken: &models.Token{Token: "test-token"},
|
|
ConnectionID: "test-connection",
|
|
},
|
|
FromPayload: json.RawMessage(`invalid json`),
|
|
}
|
|
fromPayloadBytes, _ := json.Marshal(fromPayload)
|
|
|
|
req := models.FetchNextAccountsRequest{
|
|
FromPayload: fromPayloadBytes,
|
|
}
|
|
|
|
resp, err := plg.FetchNextAccounts(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(resp).To(Equal(models.FetchNextAccountsResponse{}))
|
|
})
|
|
})
|
|
})
|