Files
Paul NicolasandGitHub 04517d36e0 fix(connectors): fix webhook idempotency key and tests (#445)
* feat(workflows): handle webhook idempotency in a different way

* feat(adyen): add verify webhook and fix tests

* fix(atlar): ensure plugin functions are tested

* fix(bankingcircle): ensure plugin functions are tested

* feat(column): add verify webhook method and fix tests

* fix(currencycloud): ensure plugin functions are tested

* fix(generic): ensure plugin functions are tested

* feat(mangopay): add verify webhook method and fix tests

* fix(modulr): ensure plugin functions are tested

* fix(moneycorp): ensure plugin functions are tested

* fix(stripe): ensure plugin functions are tested

* feat(wise): add verify webhook method and fix tests

* fix dirty

* fix postgres idempotency key

* fix wrong go libs version

* fix coderabbitai

* webhooks failing verification should stop temporal workflow
2025-05-14 15:27:14 +00:00

127 lines
3.0 KiB
Go

package bankingcircle
import (
"errors"
"github.com/formancehq/payments/internal/connectors/plugins/public/bankingcircle/client"
"github.com/formancehq/payments/internal/models"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("BankingCircle Plugin Balances", func() {
var (
ctrl *gomock.Controller
m *client.MockClient
plg models.Plugin
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
m = client.NewMockClient(ctrl)
plg = &Plugin{client: m}
})
AfterEach(func() {
ctrl.Finish()
})
Context("fetching next balances", func() {
var (
sampleBalances []client.Balance
sampleAccount *client.Account
)
BeforeEach(func() {
sampleBalances = []client.Balance{
{
Currency: "EUR",
BeginOfDayAmount: "100",
IntraDayAmount: "150",
},
{
Currency: "USD",
BeginOfDayAmount: "100",
IntraDayAmount: "-100",
},
}
sampleAccount = &client.Account{
Balances: sampleBalances,
}
})
It("should return an error - get balances error", func(ctx SpecContext) {
req := models.FetchNextBalancesRequest{
PageSize: 60,
FromPayload: []byte(`{"reference": "123"}`),
}
m.EXPECT().GetAccount(gomock.Any(), "123").Return(
sampleAccount,
errors.New("test error"),
)
resp, err := plg.FetchNextBalances(ctx, req)
Expect(err).ToNot(BeNil())
Expect(err).To(MatchError("test error"))
Expect(resp).To(Equal(models.FetchNextBalancesResponse{}))
})
It("should fetch next balances - no state no results", func(ctx SpecContext) {
req := models.FetchNextBalancesRequest{
PageSize: 60,
FromPayload: []byte(`{"reference": "123"}`),
}
m.EXPECT().GetAccount(gomock.Any(), "123").Return(
&client.Account{},
nil,
)
resp, err := plg.FetchNextBalances(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Balances).To(HaveLen(0))
Expect(resp.HasMore).To(BeFalse())
Expect(resp.NewState).To(BeNil())
})
It("should fetch all balances - page size > sample balances", func(ctx SpecContext) {
req := models.FetchNextBalancesRequest{
PageSize: 60,
FromPayload: []byte(`{"reference": "123"}`),
}
m.EXPECT().GetAccount(gomock.Any(), "123").Return(
sampleAccount,
nil,
)
resp, err := plg.FetchNextBalances(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Balances).To(HaveLen(2))
Expect(resp.HasMore).To(BeFalse())
Expect(resp.NewState).To(BeNil())
})
It("should fetch all balances - page size < sample balances", func(ctx SpecContext) {
req := models.FetchNextBalancesRequest{
PageSize: 1,
FromPayload: []byte(`{"reference": "123"}`),
}
m.EXPECT().GetAccount(gomock.Any(), "123").Return(
sampleAccount,
nil,
)
resp, err := plg.FetchNextBalances(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Balances).To(HaveLen(2))
Expect(resp.HasMore).To(BeFalse())
Expect(resp.NewState).To(BeNil())
})
})
})