Files
payments/internal/api/services/accounts_create_test.go
CrimsonandGitHub 3f41fffc53 feat(accounts): Return Connector as part of accounts response (#547)
* Return ConnectorBase as part of accounts response

* Fix link to capabilities page in error message

* Add connector to accounts response json functions

* Return Connector info on v3 create account response

* Address coderabbit feedback
2025-09-17 15:15:36 +00:00

79 lines
2.0 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 TestAccountsCreate(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
account *models.Account
err error
expectedError error
typedError bool
}{
{
name: "success",
account: &models.Account{ID: models.AccountID{Reference: "abc"}},
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: "connector capability not supported",
err: &engine.ErrConnectorCapabilityNotSupported{Capability: "CreateAccounts", Provider: "Stripe"},
expectedError: &engine.ErrConnectorCapabilityNotSupported{Capability: "CreateAccounts", 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().CreateFormanceAccount(gomock.Any(), gomock.Any()).Return(test.err)
if test.err == nil {
store.EXPECT().AccountsGet(gomock.Any(), gomock.Any()).Return(test.account, nil)
}
_, err := s.AccountsCreate(context.Background(), models.Account{})
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)
}
})
}
}