Skip to content

Commit

Permalink
fix(storage): fix payment list sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas committed Jan 28, 2025
1 parent 1841401 commit 6412fdb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/storage/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (s *store) PaymentsList(ctx context.Context, q ListPaymentsQuery) (*bunpagi
select status
from payment_adjustments apd
where payment_id = payment.id
order by created_at desc
order by created_at desc, sort_id desc
limit 1
) apd on true`)

Expand Down
73 changes: 73 additions & 0 deletions internal/storage/payments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,79 @@ func TestPaymentsDeleteFromConnectorID(t *testing.T) {
})
}

func TestPaymentsListSorting(t *testing.T) {
t.Parallel()

ctx := logging.TestingContext()
store := newStore(t)

upsertConnector(t, ctx, store, defaultConnector)
upsertAccounts(t, ctx, store, defaultAccounts())

p := models.Payment{
ID: pID1,
ConnectorID: defaultConnector.ID,
Reference: "test1",
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
Type: models.PAYMENT_TYPE_TRANSFER,
InitialAmount: big.NewInt(100),
Amount: big.NewInt(100),
Asset: "USD/2",
Scheme: models.PAYMENT_SCHEME_OTHER,
SourceAccountID: &defaultAccounts()[0].ID,
DestinationAccountID: &defaultAccounts()[1].ID,
Metadata: map[string]string{
"key1": "value1",
},
Adjustments: []models.PaymentAdjustment{
{
ID: models.PaymentAdjustmentID{
PaymentID: pID1,
Reference: "test1",
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
Status: models.PAYMENT_STATUS_PENDING,
},
Reference: "test1",
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
Status: models.PAYMENT_STATUS_PENDING,
Amount: big.NewInt(100),
Asset: pointer.For("USD/2"),
Raw: []byte(`{}`),
},
{
ID: models.PaymentAdjustmentID{
PaymentID: pID1,
Reference: "test1",
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
Status: models.PAYMENT_STATUS_SUCCEEDED,
},
Reference: "test1",
CreatedAt: now.Add(-60 * time.Minute).UTC().Time,
Status: models.PAYMENT_STATUS_SUCCEEDED,
Amount: big.NewInt(100),
Asset: pointer.For("USD/2"),
Raw: []byte(`{}`),
},
},
}

upsertPayments(t, ctx, store, []models.Payment{p})

q := NewListPaymentsQuery(
bunpaginate.NewPaginatedQueryOptions(PaymentQuery{}).
WithPageSize(1),
)

cursor, err := store.PaymentsList(ctx, q)
require.NoError(t, err)
require.Len(t, cursor.Data, 1)
require.False(t, cursor.HasMore)
require.Empty(t, cursor.Previous)
require.Empty(t, cursor.Next)

require.Equal(t, models.PAYMENT_STATUS_SUCCEEDED, cursor.Data[0].Status)
}

func TestPaymentsList(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 6412fdb

Please sign in to comment.