Files
payments/internal/api/services/pools_list_test.go
Paul NicolasandGitHub 1c854a145c feat(pools): add possibility to create dynamic pool (#598)
* feat(pools): add dynamic pools creation

* fix(pools): fix missing json handling

* feat(openapi): add pool type enum
2025-11-24 12:50:07 +00:00

61 lines
1.4 KiB
Go

package services
import (
"context"
"fmt"
"testing"
"github.com/formancehq/go-libs/v3/bun/bunpaginate"
"github.com/formancehq/payments/internal/connectors/engine"
"github.com/formancehq/payments/internal/models"
"github.com/formancehq/payments/internal/storage"
"github.com/stretchr/testify/require"
gomock "go.uber.org/mock/gomock"
)
func TestPoolsList(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)
tests := []struct {
name string
err error
expectedError error
}{
{
name: "success",
err: nil,
expectedError: nil,
},
{
name: "storage error not found",
err: storage.ErrNotFound,
expectedError: newStorageError(storage.ErrNotFound, "cannot list pools"),
},
{
name: "other error",
err: fmt.Errorf("error"),
expectedError: newStorageError(fmt.Errorf("error"), "cannot list pools"),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
query := storage.ListPoolsQuery{}
store.EXPECT().PoolsList(gomock.Any(), query).Return(&bunpaginate.Cursor[models.Pool]{}, test.err)
_, err := s.PoolsList(context.Background(), query)
if test.expectedError == nil {
require.NoError(t, err)
} else {
require.Equal(t, test.expectedError, err)
}
})
}
}