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
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package wise
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math/big"
|
|
|
|
"github.com/formancehq/payments/internal/connectors/plugins/public/wise/client"
|
|
"github.com/formancehq/payments/internal/models"
|
|
"go.uber.org/mock/gomock"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Wise Plugin Balances", 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()
|
|
})
|
|
|
|
Context("fetch next balances", func() {
|
|
var (
|
|
balance client.Balance
|
|
expectedProfileID uint64
|
|
profileVal uint64
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
expectedProfileID = 123454
|
|
profileVal = 999999
|
|
balance = client.Balance{
|
|
ID: 14556,
|
|
Type: "type1",
|
|
Amount: client.BalanceAmount{Value: json.Number("44.99"), Currency: "USD"},
|
|
}
|
|
})
|
|
|
|
It("fetches balances from wise client", func(ctx SpecContext) {
|
|
req := models.FetchNextBalancesRequest{
|
|
State: json.RawMessage(`{}`),
|
|
FromPayload: json.RawMessage(fmt.Sprintf(
|
|
`{"Reference":"%d","Metadata":{"%s":"%d"}}`,
|
|
expectedProfileID,
|
|
metadataProfileIDKey,
|
|
profileVal,
|
|
)),
|
|
PageSize: 10,
|
|
}
|
|
m.EXPECT().GetBalance(gomock.Any(), profileVal, expectedProfileID).Return(
|
|
&balance,
|
|
nil,
|
|
)
|
|
|
|
res, err := plg.FetchNextBalances(ctx, req)
|
|
Expect(err).To(BeNil())
|
|
Expect(res.HasMore).To(BeFalse())
|
|
Expect(res.Balances).To(HaveLen(1)) // always returns 1
|
|
Expect(res.Balances[0].AccountReference).To(Equal(fmt.Sprint(expectedProfileID)))
|
|
expectedBalance, err := balance.Amount.Value.Float64()
|
|
Expect(err).To(BeNil())
|
|
Expect(res.Balances[0].Amount).To(BeEquivalentTo(big.NewInt(int64(expectedBalance * 100))))
|
|
})
|
|
})
|
|
})
|