account

package
v0.0.0-...-308d6b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2021 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDomainError

func IsDomainError(err error) bool

Check if some error belongs to the account domain

Types

type Repository

type Repository interface {
	Create(ctx context.Context, account *entities.Account) error
	GetByID(ctx context.Context, accountID string) (*entities.Account, error)
	GetByCPF(ctx context.Context, CPF string) (*entities.Account, error)
	GetAccounts(ctx context.Context) ([]entities.Account, error)
	UpdateBalance(ctx context.Context, ID string) error
}

type RepositoryMock

type RepositoryMock struct {
	// CreateFunc mocks the Create method.
	CreateFunc func(ctx context.Context, account *entities.Account) error

	// GetAccountsFunc mocks the GetAccounts method.
	GetAccountsFunc func(ctx context.Context) ([]entities.Account, error)

	// GetByCPFFunc mocks the GetByCPF method.
	GetByCPFFunc func(ctx context.Context, CPF string) (*entities.Account, error)

	// GetByIDFunc mocks the GetByID method.
	GetByIDFunc func(ctx context.Context, accountID string) (*entities.Account, error)

	// UpdateBalanceFunc mocks the UpdateBalance method.
	UpdateBalanceFunc func(ctx context.Context, ID string) error
	// contains filtered or unexported fields
}

RepositoryMock is a mock implementation of Repository.

func TestSomethingThatUsesRepository(t *testing.T) {

	// make and configure a mocked Repository
	mockedRepository := &RepositoryMock{
		CreateFunc: func(ctx context.Context, account *entities.Account) error {
			panic("mock out the Create method")
		},
		GetAccountsFunc: func(ctx context.Context) ([]entities.Account, error) {
			panic("mock out the GetAccounts method")
		},
		GetByCPFFunc: func(ctx context.Context, CPF string) (*entities.Account, error) {
			panic("mock out the GetByCPF method")
		},
		GetByIDFunc: func(ctx context.Context, accountID string) (*entities.Account, error) {
			panic("mock out the GetByID method")
		},
		UpdateBalanceFunc: func(ctx context.Context, ID string) error {
			panic("mock out the UpdateBalance method")
		},
	}

	// use mockedRepository in code that requires Repository
	// and then make assertions.

}

func (*RepositoryMock) Create

func (mock *RepositoryMock) Create(ctx context.Context, account *entities.Account) error

Create calls CreateFunc.

func (*RepositoryMock) CreateCalls

func (mock *RepositoryMock) CreateCalls() []struct {
	Ctx     context.Context
	Account *entities.Account
}

CreateCalls gets all the calls that were made to Create. Check the length with:

len(mockedRepository.CreateCalls())

func (*RepositoryMock) GetAccounts

func (mock *RepositoryMock) GetAccounts(ctx context.Context) ([]entities.Account, error)

GetAccounts calls GetAccountsFunc.

func (*RepositoryMock) GetAccountsCalls

func (mock *RepositoryMock) GetAccountsCalls() []struct {
	Ctx context.Context
}

GetAccountsCalls gets all the calls that were made to GetAccounts. Check the length with:

len(mockedRepository.GetAccountsCalls())

func (*RepositoryMock) GetByCPF

func (mock *RepositoryMock) GetByCPF(ctx context.Context, CPF string) (*entities.Account, error)

GetByCPF calls GetByCPFFunc.

func (*RepositoryMock) GetByCPFCalls

func (mock *RepositoryMock) GetByCPFCalls() []struct {
	Ctx context.Context
	CPF string
}

GetByCPFCalls gets all the calls that were made to GetByCPF. Check the length with:

len(mockedRepository.GetByCPFCalls())

func (*RepositoryMock) GetByID

func (mock *RepositoryMock) GetByID(ctx context.Context, accountID string) (*entities.Account, error)

GetByID calls GetByIDFunc.

func (*RepositoryMock) GetByIDCalls

func (mock *RepositoryMock) GetByIDCalls() []struct {
	Ctx       context.Context
	AccountID string
}

GetByIDCalls gets all the calls that were made to GetByID. Check the length with:

len(mockedRepository.GetByIDCalls())

func (*RepositoryMock) UpdateBalance

func (mock *RepositoryMock) UpdateBalance(ctx context.Context, ID string) error

UpdateBalance calls UpdateBalanceFunc.

func (*RepositoryMock) UpdateBalanceCalls

func (mock *RepositoryMock) UpdateBalanceCalls() []struct {
	Ctx context.Context
	ID  string
}

UpdateBalanceCalls gets all the calls that were made to UpdateBalance. Check the length with:

len(mockedRepository.UpdateBalanceCalls())

type UseCase

type UseCase interface {
	List(ctx context.Context) ([]entities.Account, error)
	Create(ctx context.Context, input entities.CreateAccountInput) (*entities.Account, error)
	GetByID(ctx context.Context, accountID string) (*entities.Account, error)
	GetByCPF(ctx context.Context, CPF string) (*entities.Account, error)
}

type UseCaseMock

type UseCaseMock struct {
	// CreateFunc mocks the Create method.
	CreateFunc func(ctx context.Context, input entities.CreateAccountInput) (*entities.Account, error)

	// GetByCPFFunc mocks the GetByCPF method.
	GetByCPFFunc func(ctx context.Context, CPF string) (*entities.Account, error)

	// GetByIDFunc mocks the GetByID method.
	GetByIDFunc func(ctx context.Context, accountID string) (*entities.Account, error)

	// ListFunc mocks the List method.
	ListFunc func(ctx context.Context) ([]entities.Account, error)
	// contains filtered or unexported fields
}

UseCaseMock is a mock implementation of UseCase.

func TestSomethingThatUsesUseCase(t *testing.T) {

	// make and configure a mocked UseCase
	mockedUseCase := &UseCaseMock{
		CreateFunc: func(ctx context.Context, input entities.CreateAccountInput) (*entities.Account, error) {
			panic("mock out the Create method")
		},
		GetByCPFFunc: func(ctx context.Context, CPF string) (*entities.Account, error) {
			panic("mock out the GetByCPF method")
		},
		GetByIDFunc: func(ctx context.Context, accountID string) (*entities.Account, error) {
			panic("mock out the GetByID method")
		},
		ListFunc: func(ctx context.Context) ([]entities.Account, error) {
			panic("mock out the List method")
		},
	}

	// use mockedUseCase in code that requires UseCase
	// and then make assertions.

}

func (*UseCaseMock) Create

Create calls CreateFunc.

func (*UseCaseMock) CreateCalls

func (mock *UseCaseMock) CreateCalls() []struct {
	Ctx   context.Context
	Input entities.CreateAccountInput
}

CreateCalls gets all the calls that were made to Create. Check the length with:

len(mockedUseCase.CreateCalls())

func (*UseCaseMock) GetByCPF

func (mock *UseCaseMock) GetByCPF(ctx context.Context, CPF string) (*entities.Account, error)

GetByCPF calls GetByCPFFunc.

func (*UseCaseMock) GetByCPFCalls

func (mock *UseCaseMock) GetByCPFCalls() []struct {
	Ctx context.Context
	CPF string
}

GetByCPFCalls gets all the calls that were made to GetByCPF. Check the length with:

len(mockedUseCase.GetByCPFCalls())

func (*UseCaseMock) GetByID

func (mock *UseCaseMock) GetByID(ctx context.Context, accountID string) (*entities.Account, error)

GetByID calls GetByIDFunc.

func (*UseCaseMock) GetByIDCalls

func (mock *UseCaseMock) GetByIDCalls() []struct {
	Ctx       context.Context
	AccountID string
}

GetByIDCalls gets all the calls that were made to GetByID. Check the length with:

len(mockedUseCase.GetByIDCalls())

func (*UseCaseMock) List

func (mock *UseCaseMock) List(ctx context.Context) ([]entities.Account, error)

List calls ListFunc.

func (*UseCaseMock) ListCalls

func (mock *UseCaseMock) ListCalls() []struct {
	Ctx context.Context
}

ListCalls gets all the calls that were made to List. Check the length with:

len(mockedUseCase.ListCalls())

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL