You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.7 KiB
99 lines
2.7 KiB
package unit |
|
|
|
import ( |
|
"context" |
|
"time" |
|
|
|
"autostore/internal/domain/entities" |
|
"autostore/internal/domain/specifications" |
|
"autostore/internal/domain/value_objects" |
|
) |
|
|
|
// Common constants for tests |
|
const ( |
|
mockedNow = "2023-01-01 12:00:00" |
|
notExpiredDate = "2023-01-02 12:00:00" |
|
expiredDate = "2022-12-31 12:00:00" |
|
itemName = "Test Item" |
|
orderURL = "http://example.com/order" |
|
userID = "550e8400-e29b-41d4-a716-446655440000" // Valid UUID |
|
dateFormat = "2006-01-02 15:04:05" |
|
) |
|
|
|
// Mock implementations shared across tests |
|
type mockItemRepository struct { |
|
saveFunc func(ctx context.Context, item *entities.ItemEntity) error |
|
findWhereFunc func(ctx context.Context, spec specifications.Specification[*entities.ItemEntity]) ([]*entities.ItemEntity, error) |
|
deleteFunc func(ctx context.Context, id value_objects.ItemID) error |
|
} |
|
|
|
func (m *mockItemRepository) Save(ctx context.Context, item *entities.ItemEntity) error { |
|
if m.saveFunc != nil { |
|
return m.saveFunc(ctx, item) |
|
} |
|
return nil |
|
} |
|
|
|
func (m *mockItemRepository) FindByID(ctx context.Context, id value_objects.ItemID) (*entities.ItemEntity, error) { |
|
return nil, nil |
|
} |
|
|
|
func (m *mockItemRepository) FindByUserID(ctx context.Context, userID value_objects.UserID) ([]*entities.ItemEntity, error) { |
|
return nil, nil |
|
} |
|
|
|
func (m *mockItemRepository) FindWhere(ctx context.Context, spec specifications.Specification[*entities.ItemEntity]) ([]*entities.ItemEntity, error) { |
|
if m.findWhereFunc != nil { |
|
return m.findWhereFunc(ctx, spec) |
|
} |
|
return nil, nil |
|
} |
|
|
|
func (m *mockItemRepository) Delete(ctx context.Context, id value_objects.ItemID) error { |
|
if m.deleteFunc != nil { |
|
return m.deleteFunc(ctx, id) |
|
} |
|
return nil |
|
} |
|
|
|
func (m *mockItemRepository) Exists(ctx context.Context, id value_objects.ItemID) (bool, error) { |
|
return false, nil |
|
} |
|
|
|
type mockOrderService struct { |
|
orderItemFunc func(ctx context.Context, item *entities.ItemEntity) error |
|
} |
|
|
|
func (m *mockOrderService) OrderItem(ctx context.Context, item *entities.ItemEntity) error { |
|
if m.orderItemFunc != nil { |
|
return m.orderItemFunc(ctx, item) |
|
} |
|
return nil |
|
} |
|
|
|
type mockTimeProvider struct { |
|
nowFunc func() time.Time |
|
} |
|
|
|
func (m *mockTimeProvider) Now() time.Time { |
|
if m.nowFunc != nil { |
|
return m.nowFunc() |
|
} |
|
return time.Now() |
|
} |
|
|
|
type mockLogger struct { |
|
infoLogs []string |
|
errorLogs []string |
|
} |
|
|
|
func (m *mockLogger) Info(ctx context.Context, msg string, fields ...interface{}) { |
|
m.infoLogs = append(m.infoLogs, msg) |
|
} |
|
|
|
func (m *mockLogger) Error(ctx context.Context, msg string, fields ...interface{}) { |
|
m.errorLogs = append(m.errorLogs, msg) |
|
} |
|
|
|
func (m *mockLogger) Debug(ctx context.Context, msg string, fields ...interface{}) {} |
|
func (m *mockLogger) Warn(ctx context.Context, msg string, fields ...interface{}) {} |