mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
0067971779
* fix(api): PMNT-121 Return 400 when connector cannot create account * Replace capacity with capability Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Fix renaming capacity into capability * Fix test name * Add missing api test * Add create payment and v2 error handling * Refactor error handling and fix inconsistent naming of ConnectorID * Refactor error handling and fix inconsistent naming of ConnectorID --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"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 TestPaymentsCreate(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: "capability not supported",
|
|
err: &engine.ErrConnectorCapabilityNotSupported{Capability: "CreatePayments", Provider: "Stripe"},
|
|
expectedError: &engine.ErrConnectorCapabilityNotSupported{Capability: "CreatePayments", Provider: "Stripe"},
|
|
},
|
|
{
|
|
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().CreateFormancePayment(gomock.Any(), gomock.Any()).Return(test.err)
|
|
err := s.PaymentsCreate(context.Background(), models.Payment{})
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|