tercul-backend/internal/testutil/mock_translation_repository.go
Damir Mukimov d50722dad5
Some checks failed
Test / Integration Tests (push) Successful in 4s
Build / Build Binary (push) Failing after 2m9s
Docker Build / Build Docker Image (push) Failing after 2m32s
Test / Unit Tests (push) Failing after 3m12s
Lint / Go Lint (push) Failing after 1m0s
Refactor ID handling to use UUIDs across the application
- 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.
2025-12-27 00:33:34 +01:00

185 lines
6.0 KiB
Go

package testutil
import (
"context"
"tercul/internal/domain"
"github.com/google/uuid"
"github.com/stretchr/testify/mock"
"gorm.io/gorm"
)
// MockTranslationRepository is an in-memory implementation of TranslationRepository
type MockTranslationRepository struct {
mock.Mock
}
func NewMockTranslationRepository() *MockTranslationRepository {
return new(MockTranslationRepository)
}
var _ domain.TranslationRepository = (*MockTranslationRepository)(nil)
// BaseRepository methods with context support
func (m *MockTranslationRepository) Create(ctx context.Context, t *domain.Translation) error {
args := m.Called(ctx, t)
return args.Error(0)
}
func (m *MockTranslationRepository) GetByID(ctx context.Context, id uuid.UUID) (*domain.Translation, error) {
args := m.Called(ctx, id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Translation), args.Error(1)
}
func (m *MockTranslationRepository) Update(ctx context.Context, t *domain.Translation) error {
args := m.Called(ctx, t)
return args.Error(0)
}
func (m *MockTranslationRepository) Delete(ctx context.Context, id uuid.UUID) error {
args := m.Called(ctx, id)
return args.Error(0)
}
func (m *MockTranslationRepository) List(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[domain.Translation], error) {
args := m.Called(ctx, page, pageSize)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.PaginatedResult[domain.Translation]), args.Error(1)
}
func (m *MockTranslationRepository) ListAll(ctx context.Context) ([]domain.Translation, error) {
args := m.Called(ctx)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Translation), args.Error(1)
}
func (m *MockTranslationRepository) ListByWorkIDPaginated(ctx context.Context, workID uuid.UUID, language *string, page, pageSize int) (*domain.PaginatedResult[domain.Translation], error) {
args := m.Called(ctx, workID, language, page, pageSize)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.PaginatedResult[domain.Translation]), args.Error(1)
}
func (m *MockTranslationRepository) Count(ctx context.Context) (int64, error) {
args := m.Called(ctx)
return args.Get(0).(int64), args.Error(1)
}
func (m *MockTranslationRepository) FindWithPreload(ctx context.Context, preloads []string, id uuid.UUID) (*domain.Translation, error) {
args := m.Called(ctx, preloads, id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Translation), args.Error(1)
}
func (m *MockTranslationRepository) GetAllForSync(ctx context.Context, batchSize, offset int) ([]domain.Translation, error) {
args := m.Called(ctx, batchSize, offset)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Translation), args.Error(1)
}
// New BaseRepository methods
func (m *MockTranslationRepository) CreateInTx(ctx context.Context, tx *gorm.DB, entity *domain.Translation) error {
args := m.Called(ctx, tx, entity)
return args.Error(0)
}
func (m *MockTranslationRepository) GetByIDWithOptions(ctx context.Context, id uuid.UUID, options *domain.QueryOptions) (*domain.Translation, error) {
args := m.Called(ctx, id, options)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Translation), args.Error(1)
}
func (m *MockTranslationRepository) UpdateInTx(ctx context.Context, tx *gorm.DB, entity *domain.Translation) error {
args := m.Called(ctx, tx, entity)
return args.Error(0)
}
func (m *MockTranslationRepository) DeleteInTx(ctx context.Context, tx *gorm.DB, id uuid.UUID) error {
args := m.Called(ctx, tx, id)
return args.Error(0)
}
func (m *MockTranslationRepository) ListWithOptions(ctx context.Context, options *domain.QueryOptions) ([]domain.Translation, error) {
args := m.Called(ctx, options)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Translation), args.Error(1)
}
func (m *MockTranslationRepository) CountWithOptions(ctx context.Context, options *domain.QueryOptions) (int64, error) {
args := m.Called(ctx, options)
return args.Get(0).(int64), args.Error(1)
}
func (m *MockTranslationRepository) Exists(ctx context.Context, id uuid.UUID) (bool, error) {
args := m.Called(ctx, id)
return args.Bool(0), args.Error(1)
}
func (m *MockTranslationRepository) BeginTx(ctx context.Context) (*gorm.DB, error) {
args := m.Called(ctx)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*gorm.DB), args.Error(1)
}
func (m *MockTranslationRepository) WithTx(ctx context.Context, fn func(tx *gorm.DB) error) error {
// This is tricky to mock. For now, just execute the function.
// A real test might want to mock the transaction itself.
return fn(nil)
}
func (m *MockTranslationRepository) Upsert(ctx context.Context, t *domain.Translation) error {
args := m.Called(ctx, t)
return args.Error(0)
}
// TranslationRepository specific methods
func (m *MockTranslationRepository) ListByWorkID(ctx context.Context, workID uuid.UUID) ([]domain.Translation, error) {
args := m.Called(ctx, workID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Translation), args.Error(1)
}
func (m *MockTranslationRepository) ListByEntity(ctx context.Context, entityType string, entityID uuid.UUID) ([]domain.Translation, error) {
args := m.Called(ctx, entityType, entityID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Translation), args.Error(1)
}
func (m *MockTranslationRepository) ListByTranslatorID(ctx context.Context, translatorID uuid.UUID) ([]domain.Translation, error) {
args := m.Called(ctx, translatorID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Translation), args.Error(1)
}
func (m *MockTranslationRepository) ListByStatus(ctx context.Context, status domain.TranslationStatus) ([]domain.Translation, error) {
args := m.Called(ctx, status)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Translation), args.Error(1)
}