tercul-backend/internal/testutil/mock_base_repository.go
google-labs-jules[bot] 8797cec718 Refactor: In-progress refactoring to fix build.
This commit includes the following changes:
- Refactored all data repositories in `internal/data/sql/` to use a consistent `sql` package and to align with the new `domain` models.
- Fixed the GraphQL structure by moving the server creation logic from `internal/app` to `cmd/api`, which resolved an import cycle.
- Corrected numerous incorrect import paths for packages like `graph`, `linguistics`, `syncjob`, and the legacy `models` package.
- Resolved several package and function redeclaration errors.
- Removed legacy migration code.
2025-09-05 15:11:30 +00:00

73 lines
3.1 KiB
Go

package testutil
import (
"context"
"errors"
"fmt"
"tercul/internal/domain"
"gorm.io/gorm"
)
// 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
}