mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
Some checks failed
- Updated database models and repositories to replace uint IDs with UUIDs. - Modified test fixtures to generate and use UUIDs for authors, translations, users, and works. - Adjusted mock implementations to align with the new UUID structure. - Ensured all relevant functions and methods are updated to handle UUIDs correctly. - Added necessary imports for UUID handling in various files.
72 lines
3.1 KiB
Go
72 lines
3.1 KiB
Go
package testutil
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"gorm.io/gorm"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// MockBaseRepository provides common mock implementations for BaseRepository methods
|
|
type MockBaseRepository[T any] struct {
|
|
// This is a helper struct that can be embedded in mock repositories
|
|
// to provide common mock implementations
|
|
}
|
|
|
|
// BeginTx starts a new transaction (mock implementation)
|
|
func (m *MockBaseRepository[T]) BeginTx(ctx context.Context) (*gorm.DB, error) {
|
|
return nil, fmt.Errorf("transactions not supported in mock repository")
|
|
}
|
|
|
|
// WithTx executes a function within a transaction (mock implementation)
|
|
func (m *MockBaseRepository[T]) WithTx(ctx context.Context, fn func(tx *gorm.DB) error) error {
|
|
return fmt.Errorf("transactions not supported in mock repository")
|
|
}
|
|
|
|
// CreateInTx creates an entity within a transaction (mock implementation)
|
|
func (m *MockBaseRepository[T]) CreateInTx(ctx context.Context, tx *gorm.DB, entity *T) error {
|
|
return fmt.Errorf("CreateInTx not implemented in mock repository")
|
|
}
|
|
|
|
// UpdateInTx updates an entity within a transaction (mock implementation)
|
|
func (m *MockBaseRepository[T]) UpdateInTx(ctx context.Context, tx *gorm.DB, entity *T) error {
|
|
return fmt.Errorf("UpdateInTx not implemented in mock repository")
|
|
}
|
|
|
|
// DeleteInTx removes an entity by its ID within a transaction (mock implementation)
|
|
func (m *MockBaseRepository[T]) DeleteInTx(ctx context.Context, tx *gorm.DB, id uint) error {
|
|
return fmt.Errorf("DeleteInTx not implemented in mock repository")
|
|
}
|
|
|
|
// GetByIDWithOptions retrieves an entity by its ID with query options (mock implementation)
|
|
func (m *MockBaseRepository[T]) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*T, error) {
|
|
return nil, fmt.Errorf("GetByIDWithOptions not implemented in mock repository")
|
|
}
|
|
|
|
// ListWithOptions returns entities with query options (mock implementation)
|
|
func (m *MockBaseRepository[T]) ListWithOptions(ctx context.Context, options *domain.QueryOptions) ([]T, error) {
|
|
return nil, fmt.Errorf("ListWithOptions not implemented in mock repository")
|
|
}
|
|
|
|
// CountWithOptions returns the count with query options (mock implementation)
|
|
func (m *MockBaseRepository[T]) CountWithOptions(ctx context.Context, options *domain.QueryOptions) (int64, error) {
|
|
return 0, fmt.Errorf("CountWithOptions not implemented in mock repository")
|
|
}
|
|
|
|
// Exists checks if an entity exists by ID (mock implementation)
|
|
func (m *MockBaseRepository[T]) Exists(ctx context.Context, id uint) (bool, error) {
|
|
return false, fmt.Errorf("Exists not implemented in mock repository")
|
|
}
|
|
|
|
// GetAllForSync returns entities in batches for synchronization (mock implementation)
|
|
func (m *MockBaseRepository[T]) GetAllForSync(ctx context.Context, batchSize, offset int) ([]T, error) {
|
|
return nil, fmt.Errorf("GetAllForSync not implemented in mock repository")
|
|
}
|
|
|
|
// AddMockBaseRepositoryMethods adds all the missing BaseRepository methods to a mock repository
|
|
// This is a helper function to avoid duplicating code
|
|
func AddMockBaseRepositoryMethods[T any](repo interface{}) {
|
|
// This function would use reflection to add methods, but for now
|
|
// we'll implement them manually in each repository
|
|
}
|