mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/storage/bun/paginate"
|
|
"github.com/hanzo-fi/payments/internal/connectors/engine"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/hanzo-fi/payments/internal/storage"
|
|
"github.com/pkg/errors"
|
|
"github.com/stretchr/testify/require"
|
|
gomock "go.uber.org/mock/gomock"
|
|
)
|
|
|
|
func TestPaymentInitiationAdjustmentsGetLast(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
store := storage.NewMockStorage(ctrl)
|
|
eng := engine.NewMockEngine(ctrl)
|
|
|
|
s := New(store, eng, false)
|
|
|
|
pid := models.PaymentInitiationID{}
|
|
|
|
tests := []struct {
|
|
name string
|
|
storageResponse []models.PaymentInitiationAdjustment
|
|
err error
|
|
expectedError error
|
|
}{
|
|
{
|
|
name: "success",
|
|
err: nil,
|
|
storageResponse: []models.PaymentInitiationAdjustment{{}},
|
|
expectedError: nil,
|
|
},
|
|
{
|
|
name: "no adjustments",
|
|
err: nil,
|
|
storageResponse: []models.PaymentInitiationAdjustment{},
|
|
expectedError: errors.New("payment initiation's adjustments not found"),
|
|
},
|
|
{
|
|
name: "storage error not found",
|
|
err: storage.ErrNotFound,
|
|
expectedError: newStorageError(storage.ErrNotFound, "cannot list payment initiation's adjustments"),
|
|
},
|
|
{
|
|
name: "other error",
|
|
err: fmt.Errorf("error"),
|
|
expectedError: newStorageError(fmt.Errorf("error"), "cannot list payment initiation's adjustments"),
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
query := storage.NewListPaymentInitiationAdjustmentsQuery(
|
|
paginate.NewPaginatedQueryOptions(storage.PaymentInitiationAdjustmentsQuery{}).
|
|
WithPageSize(1),
|
|
)
|
|
store.EXPECT().PaymentInitiationAdjustmentsList(gomock.Any(), pid, query).Return(&paginate.Cursor[models.PaymentInitiationAdjustment]{
|
|
PageSize: 1,
|
|
HasMore: false,
|
|
Data: test.storageResponse,
|
|
}, test.err)
|
|
adj, err := s.PaymentInitiationAdjustmentsGetLast(context.Background(), pid)
|
|
if test.expectedError == nil {
|
|
require.NotNil(t, adj)
|
|
require.NoError(t, err)
|
|
} else {
|
|
require.Equal(t, test.expectedError.Error(), err.Error())
|
|
}
|
|
})
|
|
}
|
|
}
|