Skip to content

Commit

Permalink
BE-586 | Helper methods for mocks (#534)
Browse files Browse the repository at this point in the history
Adds helper methods for some of the mocks that allows to specify only
return parameters instead of providing full method signature. Such
approach significantly reduces code and cognitive load in test cases.
  • Loading branch information
deividaspetraitis authored Oct 25, 2024
1 parent e2295c4 commit 92b3b3f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions domain/mocks/orderbook_grpc_client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type OrderbookGRPCClientMock struct {
FetchTicksCb func(ctx context.Context, chunkSize int, contractAddress string, tickIDs []int64) ([]orderbookdomain.Tick, error)
}

func (o *OrderbookGRPCClientMock) WithGetOrdersByTickCb(orders orderbookdomain.Orders, err error) {
o.GetOrdersByTickCb = func(ctx context.Context, contractAddress string, tick int64) (orderbookdomain.Orders, error) {
return orders, err
}
}

func (o *OrderbookGRPCClientMock) GetOrdersByTick(ctx context.Context, contractAddress string, tick int64) (orderbookdomain.Orders, error) {
if o.GetOrdersByTickCb != nil {
return o.GetOrdersByTickCb(ctx, contractAddress, tick)
Expand Down
6 changes: 6 additions & 0 deletions domain/mocks/orderbook_repository_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func (m *OrderbookRepositoryMock) StoreTicks(poolID uint64, ticksMap map[int64]o
panic("StoreTicks not implemented")
}

func (m *OrderbookRepositoryMock) WithGetAllTicksFunc(ticks map[int64]orderbookdomain.OrderbookTick, ok bool) {
m.GetAllTicksFunc = func(poolID uint64) (map[int64]orderbookdomain.OrderbookTick, bool) {
return ticks, ok
}
}

// GetAllTicks implements OrderBookRepository.
func (m *OrderbookRepositoryMock) GetAllTicks(poolID uint64) (map[int64]orderbookdomain.OrderbookTick, bool) {
if m.GetAllTicksFunc != nil {
Expand Down
6 changes: 6 additions & 0 deletions domain/mocks/pools_usecase_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func (pm *PoolsUsecaseMock) GetAllCanonicalOrderbookPoolIDs() ([]domain.Canonica
panic("unimplemented")
}

func (pm *PoolsUsecaseMock) WithGetAllCanonicalOrderbookPoolIDs(result []domain.CanonicalOrderBooksResult, err error) {
pm.GetAllCanonicalOrderbookPoolIDsFunc = func() ([]domain.CanonicalOrderBooksResult, error) {
return result, err
}
}

// GetCanonicalOrderbookPool implements mvc.PoolsUsecase.
func (pm *PoolsUsecaseMock) GetCanonicalOrderbookPool(baseDenom string, quoteDenom string) (uint64, string, error) {
panic("unimplemented")
Expand Down

0 comments on commit 92b3b3f

Please sign in to comment.