-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(payments): add unit test for wise accounts and balances methods
- Loading branch information
Showing
6 changed files
with
154 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package wise | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"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 Accounts", func() { | ||
var ( | ||
plg *Plugin | ||
m *client.MockClient | ||
) | ||
|
||
BeforeEach(func() { | ||
plg = &Plugin{} | ||
|
||
ctrl := gomock.NewController(GinkgoT()) | ||
m = client.NewMockClient(ctrl) | ||
plg.SetClient(m) | ||
}) | ||
|
||
Context("fetch next accounts", func() { | ||
var ( | ||
balances []client.Balance | ||
expectedProfileID uint64 | ||
) | ||
|
||
BeforeEach(func() { | ||
expectedProfileID = 123454 | ||
balances = []client.Balance{ | ||
{ID: 14556, Type: "type1"}, | ||
{ID: 3334, Type: "type2"}, | ||
} | ||
}) | ||
|
||
It("fetches accounts from wise", func(ctx SpecContext) { | ||
req := models.FetchNextAccountsRequest{ | ||
State: json.RawMessage(`{}`), | ||
FromPayload: json.RawMessage(fmt.Sprintf(`{"ID":%d}`, expectedProfileID)), | ||
PageSize: len(balances), | ||
} | ||
m.EXPECT().GetBalances(ctx, expectedProfileID).Return( | ||
balances, | ||
nil, | ||
) | ||
|
||
res, err := plg.FetchNextAccounts(ctx, req) | ||
Expect(err).To(BeNil()) | ||
Expect(res.HasMore).To(BeTrue()) | ||
Expect(res.Accounts).To(HaveLen(req.PageSize)) | ||
Expect(res.Accounts[0].Reference).To(Equal(fmt.Sprint(balances[0].ID))) | ||
Expect(res.Accounts[1].Reference).To(Equal(fmt.Sprint(balances[1].ID))) | ||
|
||
var state accountsState | ||
|
||
err = json.Unmarshal(res.NewState, &state) | ||
Expect(err).To(BeNil()) | ||
Expect(fmt.Sprint(state.LastAccountID)).To(Equal(res.Accounts[len(res.Accounts)-1].Reference)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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 ( | ||
plg *Plugin | ||
m *client.MockClient | ||
) | ||
|
||
BeforeEach(func() { | ||
plg = &Plugin{} | ||
|
||
ctrl := gomock.NewController(GinkgoT()) | ||
m = client.NewMockClient(ctrl) | ||
plg.SetClient(m) | ||
}) | ||
|
||
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(ctx, 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)))) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package wise | ||
|
||
const ( | ||
metadataProfileIDKey = "profile_id" | ||
MetadataProfileIDKey = "profile_id" | ||
) |