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.
191 lines
5.7 KiB
Go
191 lines
5.7 KiB
Go
package plaid
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"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"
|
|
gomock "go.uber.org/mock/gomock"
|
|
)
|
|
|
|
var _ = Describe("Plaid *Plugin Complete User Link", func() {
|
|
Context("complete user link", 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 return an error - missing related attempt", func(ctx SpecContext) {
|
|
req := models.CompleteUserLinkRequest{}
|
|
|
|
resp, err := plg.CompleteUserLink(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(err.Error()).To(ContainSubstring("related attempt is required"))
|
|
Expect(resp).To(Equal(models.CompleteUserLinkResponse{}))
|
|
})
|
|
|
|
It("should return an error - missing temporary token", func(ctx SpecContext) {
|
|
req := models.CompleteUserLinkRequest{
|
|
RelatedAttempt: &models.OpenBankingConnectionAttempt{
|
|
ID: uuid.New(),
|
|
},
|
|
}
|
|
|
|
resp, err := plg.CompleteUserLink(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(err.Error()).To(ContainSubstring("missing temporary token"))
|
|
Expect(resp).To(Equal(models.CompleteUserLinkResponse{}))
|
|
})
|
|
|
|
It("should return an error - missing link token", func(ctx SpecContext) {
|
|
req := models.CompleteUserLinkRequest{
|
|
RelatedAttempt: &models.OpenBankingConnectionAttempt{
|
|
ID: uuid.New(),
|
|
TemporaryToken: &models.Token{
|
|
Token: "temp-token-123",
|
|
},
|
|
},
|
|
HTTPCallInformation: models.HTTPCallInformation{
|
|
QueryValues: map[string][]string{},
|
|
},
|
|
}
|
|
|
|
resp, err := plg.CompleteUserLink(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(err.Error()).To(ContainSubstring("missing link token"))
|
|
Expect(resp).To(Equal(models.CompleteUserLinkResponse{}))
|
|
})
|
|
|
|
It("should return an error - link token mismatch", func(ctx SpecContext) {
|
|
req := models.CompleteUserLinkRequest{
|
|
RelatedAttempt: &models.OpenBankingConnectionAttempt{
|
|
ID: uuid.New(),
|
|
TemporaryToken: &models.Token{
|
|
Token: "temp-token-123",
|
|
},
|
|
},
|
|
HTTPCallInformation: models.HTTPCallInformation{
|
|
QueryValues: map[string][]string{
|
|
client.LinkTokenQueryParamID: {"different-token"},
|
|
},
|
|
},
|
|
}
|
|
|
|
resp, err := plg.CompleteUserLink(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(err.Error()).To(ContainSubstring("link token mismatch"))
|
|
Expect(resp).To(Equal(models.CompleteUserLinkResponse{}))
|
|
})
|
|
|
|
It("should return an error - missing query values", func(ctx SpecContext) {
|
|
req := models.CompleteUserLinkRequest{
|
|
RelatedAttempt: &models.OpenBankingConnectionAttempt{
|
|
ID: uuid.New(),
|
|
TemporaryToken: &models.Token{
|
|
Token: "temp-token-123",
|
|
},
|
|
},
|
|
}
|
|
|
|
resp, err := plg.CompleteUserLink(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(err.Error()).To(ContainSubstring("missing link token: invalid request"))
|
|
Expect(resp).To(Equal(models.CompleteUserLinkResponse{}))
|
|
})
|
|
|
|
It("should return an error - missing public token", func(ctx SpecContext) {
|
|
req := models.CompleteUserLinkRequest{
|
|
RelatedAttempt: &models.OpenBankingConnectionAttempt{
|
|
ID: uuid.New(),
|
|
TemporaryToken: &models.Token{
|
|
Token: "temp-token-123",
|
|
},
|
|
},
|
|
HTTPCallInformation: models.HTTPCallInformation{
|
|
QueryValues: map[string][]string{
|
|
client.LinkTokenQueryParamID: {"temp-token-123"},
|
|
},
|
|
},
|
|
}
|
|
|
|
resp, err := plg.CompleteUserLink(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(err.Error()).To(ContainSubstring("missing public token"))
|
|
Expect(resp).To(Equal(models.CompleteUserLinkResponse{}))
|
|
})
|
|
|
|
It("should complete user link successfully", func(ctx SpecContext) {
|
|
req := models.CompleteUserLinkRequest{
|
|
RelatedAttempt: &models.OpenBankingConnectionAttempt{
|
|
ID: uuid.New(),
|
|
TemporaryToken: &models.Token{
|
|
Token: "temp-token-123",
|
|
},
|
|
},
|
|
HTTPCallInformation: models.HTTPCallInformation{
|
|
QueryValues: map[string][]string{
|
|
client.LinkTokenQueryParamID: {"temp-token-123"},
|
|
client.PublicTokenQueryParamID: {"public-token-123"},
|
|
},
|
|
},
|
|
}
|
|
|
|
expectedReq := client.ExchangePublicTokenRequest{
|
|
PublicToken: "public-token-123",
|
|
}
|
|
|
|
expectedResp := client.ExchangePublicTokenResponse{
|
|
AccessToken: "access-token-123",
|
|
ItemID: "item-id-123",
|
|
}
|
|
|
|
m.EXPECT().ExchangePublicToken(gomock.Any(), expectedReq).Return(expectedResp, nil)
|
|
|
|
resp, err := plg.CompleteUserLink(ctx, req)
|
|
Expect(err).To(BeNil())
|
|
Expect(resp.Success).ToNot(BeNil())
|
|
Expect(resp.Success.Connections).To(HaveLen(1))
|
|
Expect(resp.Success.Connections[0].ConnectionID).To(Equal("item-id-123"))
|
|
Expect(resp.Success.Connections[0].AccessToken.Token).To(Equal("access-token-123"))
|
|
})
|
|
|
|
It("should return an error - client exchange public token error", func(ctx SpecContext) {
|
|
req := models.CompleteUserLinkRequest{
|
|
RelatedAttempt: &models.OpenBankingConnectionAttempt{
|
|
ID: uuid.New(),
|
|
TemporaryToken: &models.Token{
|
|
Token: "temp-token-123",
|
|
},
|
|
},
|
|
HTTPCallInformation: models.HTTPCallInformation{
|
|
QueryValues: map[string][]string{
|
|
client.LinkTokenQueryParamID: {"temp-token-123"},
|
|
client.PublicTokenQueryParamID: {"public-token-123"},
|
|
},
|
|
},
|
|
}
|
|
|
|
m.EXPECT().ExchangePublicToken(gomock.Any(), gomock.Any()).Return(client.ExchangePublicTokenResponse{}, errors.New("client error"))
|
|
|
|
resp, err := plg.CompleteUserLink(ctx, req)
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(err).To(MatchError("client error"))
|
|
Expect(resp).To(Equal(models.CompleteUserLinkResponse{}))
|
|
})
|
|
})
|
|
})
|