-
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.
Merge pull request #115 from formancehq/feat/payments-v3-ENG-1429
feat: (payments) simplify loop logic in moneycorp plugin and add unit tests
- Loading branch information
Showing
19 changed files
with
826 additions
and
151 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
60 changes: 60 additions & 0 deletions
60
internal/connectors/plugins/public/moneycorp/accounts_test.go
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,60 @@ | ||
package moneycorp | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/formancehq/payments/internal/connectors/plugins/public/moneycorp/client" | ||
"github.com/formancehq/payments/internal/models" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
gomock "go.uber.org/mock/gomock" | ||
) | ||
|
||
var _ = Describe("Moneycorp Plugin Accounts", func() { | ||
Context("fetch next accounts", func() { | ||
var ( | ||
plg *Plugin | ||
m *client.MockClient | ||
|
||
pageSize int | ||
sampleAccounts []*client.Account | ||
) | ||
|
||
BeforeEach(func() { | ||
ctrl := gomock.NewController(GinkgoT()) | ||
m = client.NewMockClient(ctrl) | ||
plg = &Plugin{client: m} | ||
pageSize = 15 | ||
|
||
sampleAccounts = make([]*client.Account, 0) | ||
for i := 0; i < pageSize; i++ { | ||
sampleAccounts = append(sampleAccounts, &client.Account{ | ||
ID: fmt.Sprintf("moneycorp-reference-%d", i), | ||
}) | ||
} | ||
|
||
}) | ||
It("fetches next accounts", func(ctx SpecContext) { | ||
req := models.FetchNextAccountsRequest{ | ||
State: json.RawMessage(`{}`), | ||
PageSize: pageSize, | ||
} | ||
m.EXPECT().GetAccounts(ctx, gomock.Any(), pageSize).Return( | ||
sampleAccounts, | ||
nil, | ||
) | ||
res, err := plg.FetchNextAccounts(ctx, req) | ||
Expect(err).To(BeNil()) | ||
Expect(res.HasMore).To(BeTrue()) | ||
Expect(res.Accounts).To(HaveLen(req.PageSize)) | ||
|
||
var state accountsState | ||
|
||
err = json.Unmarshal(res.NewState, &state) | ||
Expect(err).To(BeNil()) | ||
Expect(state.LastPage).To(Equal(0)) | ||
Expect(state.LastIDCreated).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
62 changes: 62 additions & 0 deletions
62
internal/connectors/plugins/public/moneycorp/balances_test.go
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,62 @@ | ||
package moneycorp | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
"strings" | ||
|
||
"github.com/formancehq/payments/internal/connectors/plugins/public/moneycorp/client" | ||
"github.com/formancehq/payments/internal/models" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
gomock "go.uber.org/mock/gomock" | ||
) | ||
|
||
var _ = Describe("Moneycorp Plugin Balances", func() { | ||
var ( | ||
plg *Plugin | ||
) | ||
|
||
Context("fetch next balances", func() { | ||
var ( | ||
m *client.MockClient | ||
|
||
accRef string | ||
sampleBalance *client.Balance | ||
expectedAmount *big.Int | ||
) | ||
|
||
BeforeEach(func() { | ||
ctrl := gomock.NewController(GinkgoT()) | ||
m = client.NewMockClient(ctrl) | ||
plg = &Plugin{client: m} | ||
|
||
accRef = "abc" | ||
expectedAmount = big.NewInt(309900) | ||
sampleBalance = &client.Balance{ | ||
Attributes: client.Attributes{ | ||
CurrencyCode: "AED", | ||
AvailableBalance: json.Number("3099"), | ||
}, | ||
} | ||
}) | ||
It("fetches next balances", func(ctx SpecContext) { | ||
req := models.FetchNextBalancesRequest{ | ||
FromPayload: json.RawMessage(fmt.Sprintf(`{"reference": "%s"}`, accRef)), | ||
State: json.RawMessage(`{}`), | ||
} | ||
m.EXPECT().GetAccountBalances(ctx, accRef).Return( | ||
[]*client.Balance{sampleBalance}, | ||
nil, | ||
) | ||
res, err := plg.FetchNextBalances(ctx, req) | ||
Expect(err).To(BeNil()) | ||
Expect(res.Balances).To(HaveLen(1)) | ||
|
||
Expect(res.Balances[0].AccountReference).To(Equal(accRef)) | ||
Expect(res.Balances[0].Amount).To(BeEquivalentTo(expectedAmount)) | ||
Expect(res.Balances[0].Asset).To(HavePrefix(strings.ToUpper(sampleBalance.Attributes.CurrencyCode))) | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.