mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat(pools): add update query for dynamic pools * fixex after reviews * fix tests
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/formancehq/payments/internal/connectors/engine"
|
|
"github.com/formancehq/payments/internal/storage"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
gomock "go.uber.org/mock/gomock"
|
|
)
|
|
|
|
func TestPoolsUpdateQuery(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
|
|
typedError bool
|
|
}{
|
|
{
|
|
name: "success",
|
|
err: nil,
|
|
expectedError: nil,
|
|
},
|
|
{
|
|
name: "validation error",
|
|
err: engine.ErrValidation,
|
|
expectedError: ErrValidation,
|
|
typedError: true,
|
|
},
|
|
{
|
|
name: "not found error",
|
|
err: engine.ErrNotFound,
|
|
expectedError: ErrNotFound,
|
|
typedError: true,
|
|
},
|
|
{
|
|
name: "other error",
|
|
err: fmt.Errorf("error"),
|
|
expectedError: fmt.Errorf("error"),
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
eng.EXPECT().UpdatePoolQuery(gomock.Any(), gomock.Any(), gomock.Any()).Return(test.err)
|
|
err := s.PoolsUpdateQuery(context.Background(), uuid.New(), map[string]any{})
|
|
if test.expectedError == nil {
|
|
require.NoError(t, err)
|
|
} else if test.typedError {
|
|
require.ErrorIs(t, err, test.expectedError)
|
|
} else {
|
|
require.Equal(t, test.expectedError, err)
|
|
}
|
|
})
|
|
}
|
|
}
|