mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
package wise
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math/big"
|
|
|
|
logging "github.com/hanzo-fi/go-libs/v5/pkg/observe/log"
|
|
"github.com/hanzo-fi/payments/ce/plugins/wise/client"
|
|
"github.com/hanzo-fi/payments/pkg/domain/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, logger: logging.NewDefaultLogger(GinkgoWriter, true, false, false)}
|
|
})
|
|
|
|
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))))
|
|
})
|
|
|
|
It("skips balances with unsupported currencies", func(ctx SpecContext) {
|
|
req := models.FetchNextBalancesRequest{
|
|
State: json.RawMessage(`{}`),
|
|
FromPayload: json.RawMessage(fmt.Sprintf(
|
|
`{"Reference":"%d","Metadata":{"%s":"%d"}}`,
|
|
expectedProfileID,
|
|
metadataProfileIDKey,
|
|
profileVal,
|
|
)),
|
|
PageSize: 10,
|
|
}
|
|
unsupported := client.Balance{
|
|
ID: 14556,
|
|
Type: "type1",
|
|
Amount: client.BalanceAmount{Value: json.Number("44.99"), Currency: "ZZZ"},
|
|
}
|
|
m.EXPECT().GetBalance(gomock.Any(), profileVal, expectedProfileID).Return(
|
|
&unsupported,
|
|
nil,
|
|
)
|
|
|
|
res, err := plg.FetchNextBalances(ctx, req)
|
|
Expect(err).To(BeNil())
|
|
Expect(res.Balances).To(BeEmpty())
|
|
Expect(res.HasMore).To(BeFalse())
|
|
})
|
|
})
|
|
})
|