Skip to content

Commit

Permalink
fix(modulr): fix modulr page size
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas committed Oct 17, 2024
1 parent 6ac480a commit c665a4d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
8 changes: 5 additions & 3 deletions internal/connectors/plugins/public/modulr/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func (p *Plugin) fetchNextAccounts(ctx context.Context, req models.FetchNextAcco
needMore := false
hasMore := false
for page := 0; ; page++ {
pageSize := req.PageSize - len(accounts)

pagedAccounts, err := p.client.GetAccounts(ctx, page, pageSize, oldState.LastCreatedAt)
pagedAccounts, err := p.client.GetAccounts(ctx, page, req.PageSize, oldState.LastCreatedAt)
if err != nil {
return models.FetchNextAccountsResponse{}, err
}
Expand All @@ -50,6 +48,10 @@ func (p *Plugin) fetchNextAccounts(ctx context.Context, req models.FetchNextAcco
}
}

if !needMore {
accounts = accounts[:req.PageSize]
}

if len(accounts) > 0 {
newState.LastCreatedAt = accounts[len(accounts)-1].CreatedAt
}
Expand Down
2 changes: 1 addition & 1 deletion internal/connectors/plugins/public/modulr/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var _ = Describe("Modulr Plugin Accounts", func() {
nil,
)

m.EXPECT().GetAccounts(ctx, 1, 39, lastCreatedAt.UTC()).Return(
m.EXPECT().GetAccounts(ctx, 1, 40, lastCreatedAt.UTC()).Return(
sampleAccounts[41:],
nil,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func (p *Plugin) fetchNextExternalAccounts(ctx context.Context, req models.Fetch
needMore := false
hasMore := false
for page := 0; ; page++ {
pageSize := req.PageSize - len(accounts)

pagedBeneficiaries, err := p.client.GetBeneficiaries(ctx, page, pageSize, oldState.LastModifiedSince)
pagedBeneficiaries, err := p.client.GetBeneficiaries(ctx, page, req.PageSize, oldState.LastModifiedSince)
if err != nil {
return models.FetchNextExternalAccountsResponse{}, err
}
Expand All @@ -48,6 +46,10 @@ func (p *Plugin) fetchNextExternalAccounts(ctx context.Context, req models.Fetch
}
}

if !needMore {
accounts = accounts[:req.PageSize]
}

if len(accounts) > 0 {
newState.LastModifiedSince = accounts[len(accounts)-1].CreatedAt
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var _ = Describe("Modulr Plugin External Accounts", func() {
nil,
)

m.EXPECT().GetBeneficiaries(ctx, 1, 39, lastCreatedAt.UTC()).Return(
m.EXPECT().GetBeneficiaries(ctx, 1, 40, lastCreatedAt.UTC()).Return(
sampleBeneficiaries[41:],
nil,
)
Expand Down
8 changes: 5 additions & 3 deletions internal/connectors/plugins/public/modulr/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ func (p *Plugin) fetchNextPayments(ctx context.Context, req models.FetchNextPaym
needMore := false
hasMore := false
for page := 0; ; page++ {
pageSize := req.PageSize - len(payments)

pagedTransactions, err := p.client.GetTransactions(ctx, from.Reference, page, pageSize, oldState.LastTransactionTime)
pagedTransactions, err := p.client.GetTransactions(ctx, from.Reference, page, req.PageSize, oldState.LastTransactionTime)
if err != nil {
return models.FetchNextPaymentsResponse{}, err
}
Expand All @@ -59,6 +57,10 @@ func (p *Plugin) fetchNextPayments(ctx context.Context, req models.FetchNextPaym
}
}

if !needMore {
payments = payments[:req.PageSize]
}

if len(payments) > 0 {
newState.LastTransactionTime = payments[len(payments)-1].CreatedAt
}
Expand Down
2 changes: 1 addition & 1 deletion internal/connectors/plugins/public/modulr/payments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ var _ = Describe("Modulr Plugin Payments", func() {
nil,
)

m.EXPECT().GetTransactions(ctx, "test", 1, 39, lastCreatedAt.UTC()).Return(
m.EXPECT().GetTransactions(ctx, "test", 1, 40, lastCreatedAt.UTC()).Return(
sampleTransactions[41:],
nil,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var _ = Describe("Moneycorp Plugin Payments - check types and minor conversion",
Attributes: client.TransactionAttributes{
AccountID: accRef,
Type: "Transfer",
Direction: "Debit",
Currency: "EUR",
Amount: json.Number("65"),
CreatedAt: strings.TrimSuffix(time.Now().UTC().Format(time.RFC3339Nano), "Z"),
Expand Down Expand Up @@ -227,13 +228,15 @@ var _ = Describe("Moneycorp Plugin Payments - check pagination", func() {

samplePayments []*client.Transaction
accRef int32
now time.Time
)

BeforeEach(func() {
ctrl := gomock.NewController(GinkgoT())
m = client.NewMockClient(ctrl)
plg = &Plugin{client: m}
accRef = 3796
now = time.Now().UTC()

samplePayments = make([]*client.Transaction, 0)
for i := 0; i < 50; i++ {
Expand All @@ -245,7 +248,7 @@ var _ = Describe("Moneycorp Plugin Payments - check pagination", func() {
Direction: "Debit",
Currency: "EUR",
Amount: json.Number("42"),
CreatedAt: strings.TrimSuffix(time.Now().UTC().Format(time.RFC3339Nano), "Z"),
CreatedAt: strings.TrimSuffix(now.Add(-time.Duration(60-i)*time.Minute).UTC().Format(time.RFC3339Nano), "Z"),
},
Relationships: client.RelationShips{
Data: client.Data{
Expand Down

0 comments on commit c665a4d

Please sign in to comment.