mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* 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
146 lines
3.4 KiB
Go
146 lines
3.4 KiB
Go
package currencycloud
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/formancehq/payments/internal/connectors/plugins/public/currencycloud/client"
|
|
"github.com/formancehq/payments/internal/models"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
var _ = Describe("CurrencyCloud 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
|
|
now time.Time
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
now = time.Now().UTC()
|
|
|
|
sampleBalances = []*client.Balance{
|
|
{
|
|
ID: "test1",
|
|
AccountID: "test1",
|
|
Currency: "EUR",
|
|
Amount: "100",
|
|
CreatedAt: now.Add(-time.Duration(50) * time.Minute).UTC(),
|
|
UpdatedAt: now.Add(-time.Duration(50) * time.Minute).UTC(),
|
|
},
|
|
{
|
|
ID: "test2",
|
|
AccountID: "test2",
|
|
Currency: "USD",
|
|
Amount: "200",
|
|
CreatedAt: now.Add(-time.Duration(40) * time.Minute).UTC(),
|
|
UpdatedAt: now.Add(-time.Duration(35) * time.Minute).UTC(),
|
|
},
|
|
{
|
|
ID: "test3",
|
|
AccountID: "test1",
|
|
Currency: "DKK",
|
|
Amount: "150",
|
|
CreatedAt: now.Add(-time.Duration(30) * time.Minute).UTC(),
|
|
UpdatedAt: now.Add(-time.Duration(15) * time.Minute).UTC(),
|
|
},
|
|
}
|
|
})
|
|
|
|
It("should return an error - get balances error", func(ctx SpecContext) {
|
|
req := models.FetchNextBalancesRequest{
|
|
PageSize: 60,
|
|
}
|
|
|
|
m.EXPECT().GetBalances(gomock.Any(), 1, 60).Return(
|
|
[]*client.Balance{},
|
|
-1,
|
|
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,
|
|
}
|
|
|
|
m.EXPECT().GetBalances(gomock.Any(), 1, 60).Return(
|
|
[]*client.Balance{},
|
|
-1,
|
|
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,
|
|
}
|
|
|
|
m.EXPECT().GetBalances(gomock.Any(), 1, 60).Return(
|
|
sampleBalances,
|
|
-1,
|
|
nil,
|
|
)
|
|
|
|
resp, err := plg.FetchNextBalances(ctx, req)
|
|
Expect(err).To(BeNil())
|
|
Expect(resp.Balances).To(HaveLen(3))
|
|
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: 2,
|
|
}
|
|
|
|
m.EXPECT().GetBalances(gomock.Any(), 1, 2).Return(
|
|
sampleBalances[:2],
|
|
2,
|
|
nil,
|
|
)
|
|
|
|
m.EXPECT().GetBalances(gomock.Any(), 2, 2).Return(
|
|
sampleBalances[2:],
|
|
-1,
|
|
nil,
|
|
)
|
|
|
|
resp, err := plg.FetchNextBalances(ctx, req)
|
|
Expect(err).To(BeNil())
|
|
Expect(resp.Balances).To(HaveLen(3))
|
|
Expect(resp.HasMore).To(BeFalse())
|
|
Expect(resp.NewState).To(BeNil())
|
|
})
|
|
})
|
|
})
|