fix(tests): update mock repo to match interface
This commit is contained in:
parent
51a8293a11
commit
e64b3a4855
2 changed files with 68 additions and 24 deletions
|
|
@ -17,20 +17,22 @@ import (
|
||||||
|
|
||||||
// MockRepository implements the Repository interface for testing without database
|
// MockRepository implements the Repository interface for testing without database
|
||||||
type MockRepository struct {
|
type MockRepository struct {
|
||||||
companies []domain.Company
|
companies []domain.Company
|
||||||
products []domain.Product
|
products []domain.Product
|
||||||
users []domain.User
|
users []domain.User
|
||||||
orders []domain.Order
|
orders []domain.Order
|
||||||
shipping []domain.ShippingMethod
|
shipping []domain.ShippingMethod
|
||||||
|
shippingSettings map[uuid.UUID]domain.ShippingSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMockRepository() *MockRepository {
|
func NewMockRepository() *MockRepository {
|
||||||
return &MockRepository{
|
return &MockRepository{
|
||||||
companies: make([]domain.Company, 0),
|
companies: make([]domain.Company, 0),
|
||||||
products: make([]domain.Product, 0),
|
products: make([]domain.Product, 0),
|
||||||
users: make([]domain.User, 0),
|
users: make([]domain.User, 0),
|
||||||
orders: make([]domain.Order, 0),
|
orders: make([]domain.Order, 0),
|
||||||
shipping: make([]domain.ShippingMethod, 0),
|
shipping: make([]domain.ShippingMethod, 0),
|
||||||
|
shippingSettings: make(map[uuid.UUID]domain.ShippingSettings),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,6 +276,26 @@ func (m *MockRepository) UpsertShippingMethods(ctx context.Context, methods []do
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockRepository) GetShippingSettings(ctx context.Context, vendorID uuid.UUID) (*domain.ShippingSettings, error) {
|
||||||
|
if s, ok := m.shippingSettings[vendorID]; ok {
|
||||||
|
return &s, nil
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockRepository) UpsertShippingSettings(ctx context.Context, settings *domain.ShippingSettings) error {
|
||||||
|
m.shippingSettings[settings.VendorID] = *settings
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockRepository) ListReviews(ctx context.Context, filter domain.ReviewFilter) ([]domain.Review, int64, error) {
|
||||||
|
return []domain.Review{}, 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockRepository) ListShipments(ctx context.Context, filter domain.ShipmentFilter) ([]domain.Shipment, int64, error) {
|
||||||
|
return []domain.Shipment{}, 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
// MockPaymentGateway implements the PaymentGateway interface for testing
|
// MockPaymentGateway implements the PaymentGateway interface for testing
|
||||||
type MockPaymentGateway struct{}
|
type MockPaymentGateway struct{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,24 +11,26 @@ import (
|
||||||
|
|
||||||
// MockRepository implements Repository interface for testing
|
// MockRepository implements Repository interface for testing
|
||||||
type MockRepository struct {
|
type MockRepository struct {
|
||||||
companies []domain.Company
|
companies []domain.Company
|
||||||
products []domain.Product
|
products []domain.Product
|
||||||
users []domain.User
|
users []domain.User
|
||||||
orders []domain.Order
|
orders []domain.Order
|
||||||
cartItems []domain.CartItem
|
cartItems []domain.CartItem
|
||||||
reviews []domain.Review
|
reviews []domain.Review
|
||||||
shipping []domain.ShippingMethod
|
shipping []domain.ShippingMethod
|
||||||
|
shippingSettings map[uuid.UUID]domain.ShippingSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMockRepository() *MockRepository {
|
func NewMockRepository() *MockRepository {
|
||||||
return &MockRepository{
|
return &MockRepository{
|
||||||
companies: make([]domain.Company, 0),
|
companies: make([]domain.Company, 0),
|
||||||
products: make([]domain.Product, 0),
|
products: make([]domain.Product, 0),
|
||||||
users: make([]domain.User, 0),
|
users: make([]domain.User, 0),
|
||||||
orders: make([]domain.Order, 0),
|
orders: make([]domain.Order, 0),
|
||||||
cartItems: make([]domain.CartItem, 0),
|
cartItems: make([]domain.CartItem, 0),
|
||||||
reviews: make([]domain.Review, 0),
|
reviews: make([]domain.Review, 0),
|
||||||
shipping: make([]domain.ShippingMethod, 0),
|
shipping: make([]domain.ShippingMethod, 0),
|
||||||
|
shippingSettings: make(map[uuid.UUID]domain.ShippingSettings),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,6 +295,26 @@ func (m *MockRepository) UpsertShippingMethods(ctx context.Context, methods []do
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockRepository) GetShippingSettings(ctx context.Context, vendorID uuid.UUID) (*domain.ShippingSettings, error) {
|
||||||
|
if s, ok := m.shippingSettings[vendorID]; ok {
|
||||||
|
return &s, nil
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockRepository) UpsertShippingSettings(ctx context.Context, settings *domain.ShippingSettings) error {
|
||||||
|
m.shippingSettings[settings.VendorID] = *settings
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockRepository) ListReviews(ctx context.Context, filter domain.ReviewFilter) ([]domain.Review, int64, error) {
|
||||||
|
return m.reviews, int64(len(m.reviews)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockRepository) ListShipments(ctx context.Context, filter domain.ShipmentFilter) ([]domain.Shipment, int64, error) {
|
||||||
|
return []domain.Shipment{}, 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
// MockPaymentGateway for testing
|
// MockPaymentGateway for testing
|
||||||
type MockPaymentGateway struct{}
|
type MockPaymentGateway struct{}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue