Files
Paul NicolasandGitHub d66040c0eb feat(*): add plaid bank bridge connector and boilerplate (#499)
* feat(models): add bank bridge models

* feat(storage): add bank bridge migrations and functions

* feat(engine): add bank bridge workflows

* feat(connectors): add plaid bank bridge connector

* feat(events): add bank bridge events

* feat(api): add bank bridge router

* feat(*): bank bridge boilerplate

* fix nil pointer crash

* add more check when getting link attempts + change enum

* fix tests

* remove print

* fixes after reviews

* add specific table for access tokens

* fixes after reviews

* fix go mod tidy

* remove indexes + null default

* plaid: add tests

* *: add more tests

* fix after rebase
2025-07-30 13:44:31 +00:00

134 lines
4.6 KiB
Go

package plaid_test
import (
"context"
"encoding/json"
"testing"
"github.com/formancehq/go-libs/v3/logging"
"github.com/formancehq/payments/internal/connectors/plugins"
"github.com/formancehq/payments/internal/connectors/plugins/public/plaid"
"github.com/formancehq/payments/internal/models"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestPlugin(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Plaid *Plugin Suite")
}
var _ = Describe("Plaid *Plugin", func() {
var (
plg *plaid.Plugin
config json.RawMessage
logger = logging.NewDefaultLogger(GinkgoWriter, true, false, false)
)
BeforeEach(func() {
plg = &plaid.Plugin{
Plugin: plugins.NewBasePlugin(),
}
config = json.RawMessage(`{"clientID":"1234","clientSecret":"abc123","isSandbox":true}`)
})
Context("install", func() {
It("reports validation errors in the config", func(ctx SpecContext) {
config := json.RawMessage(`{}`)
connectorID := models.ConnectorID{Reference: uuid.New(), Provider: "plaid"}
_, err := plaid.New("plaid", logger, connectorID, config)
Expect(err.Error()).To(ContainSubstring("validation"))
})
It("returns valid install response", func(ctx SpecContext) {
connectorID := models.ConnectorID{Reference: uuid.New(), Provider: "plaid"}
_, err := plaid.New("plaid", logger, connectorID, config)
Expect(err).To(BeNil())
res, err := plg.Install(context.Background(), models.InstallRequest{})
Expect(err).To(BeNil())
Expect(res.Workflow).ToNot(BeEmpty())
})
})
Context("uninstall", func() {
It("returns valid uninstall response", func(ctx SpecContext) {
req := models.UninstallRequest{ConnectorID: "dummyID"}
_, err := plg.Uninstall(context.Background(), req)
Expect(err).To(BeNil())
})
})
Context("calling functions on uninstalled plugins", func() {
It("fails when fetch next accounts is called before install", func(ctx SpecContext) {
req := models.FetchNextAccountsRequest{
State: json.RawMessage(`{}`),
}
_, err := plg.FetchNextAccounts(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when fetch next payments is called before install", func(ctx SpecContext) {
req := models.FetchNextPaymentsRequest{
State: json.RawMessage(`{}`),
}
_, err := plg.FetchNextPayments(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when create user is called before install", func(ctx SpecContext) {
req := models.CreateUserRequest{}
_, err := plg.CreateUser(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when create user link is called before install", func(ctx SpecContext) {
req := models.CreateUserLinkRequest{}
_, err := plg.CreateUserLink(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when complete user link is called before install", func(ctx SpecContext) {
req := models.CompleteUserLinkRequest{}
_, err := plg.CompleteUserLink(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when update user link is called before install", func(ctx SpecContext) {
req := models.UpdateUserLinkRequest{}
_, err := plg.UpdateUserLink(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when delete user is called before install", func(ctx SpecContext) {
req := models.DeleteUserRequest{}
_, err := plg.DeleteUser(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when delete user connection is called before install", func(ctx SpecContext) {
req := models.DeleteUserConnectionRequest{}
_, err := plg.DeleteUserConnection(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when create webhooks is called before install", func(ctx SpecContext) {
req := models.CreateWebhooksRequest{}
_, err := plg.CreateWebhooks(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when verify webhook is called before install", func(ctx SpecContext) {
req := models.VerifyWebhookRequest{}
_, err := plg.VerifyWebhook(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
It("fails when translate webhook is called before install", func(ctx SpecContext) {
req := models.TranslateWebhookRequest{}
_, err := plg.TranslateWebhook(context.Background(), req)
Expect(err).To(MatchError(plugins.ErrNotYetInstalled))
})
})
})