mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
This commit addresses a broken build state caused by a mid-stream architectural refactoring. The changes align the existing code with the new Domain-Driven Design (DDD-lite) structure outlined in `refactor.md`. Key changes include: - Defined missing domain interfaces for `Auth`, `Localization`, and `Search`. - Refactored application services to use a `Commands` and `Queries` pattern. - Updated GraphQL resolvers to call application services instead of accessing repositories directly. - Fixed dependency injection in `cmd/api/main.go` by removing the non-existent `ApplicationBuilder` and manually instantiating services. - Corrected numerous test files (`integration`, `unit`, and `repository` tests) to reflect the new architecture, including fixing mock objects and test suite setups. - Added missing database migrations for test schemas to resolve "no such table" errors. This effort successfully gets the application to a compilable state and passes a significant portion of the test suite, laying the groundwork for further development and fixing the remaining test failures.
86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
package testutil
|
|
|
|
import (
|
|
"context"
|
|
graph "tercul/internal/adapters/graphql"
|
|
"tercul/internal/app"
|
|
"tercul/internal/app/localization"
|
|
"tercul/internal/app/work"
|
|
"tercul/internal/domain"
|
|
domain_localization "tercul/internal/domain/localization"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
// SimpleTestSuite provides a minimal test environment with just the essentials
|
|
type SimpleTestSuite struct {
|
|
suite.Suite
|
|
WorkRepo *UnifiedMockWorkRepository
|
|
WorkService *work.Service
|
|
MockSearchClient *MockSearchClient
|
|
}
|
|
|
|
// MockSearchClient is a mock implementation of the search.SearchClient interface.
|
|
type MockSearchClient struct{}
|
|
|
|
// IndexWork is the mock implementation of the IndexWork method.
|
|
func (m *MockSearchClient) IndexWork(ctx context.Context, work *domain.Work, pipeline string) error {
|
|
return nil
|
|
}
|
|
|
|
// SetupSuite sets up the test suite
|
|
func (s *SimpleTestSuite) SetupSuite() {
|
|
s.WorkRepo = NewUnifiedMockWorkRepository()
|
|
s.MockSearchClient = &MockSearchClient{}
|
|
s.WorkService = work.NewService(s.WorkRepo, s.MockSearchClient)
|
|
}
|
|
|
|
// SetupTest resets test data for each test
|
|
func (s *SimpleTestSuite) SetupTest() {
|
|
s.WorkRepo.Reset()
|
|
}
|
|
|
|
// MockLocalizationRepository is a mock implementation of the localization repository.
|
|
type MockLocalizationRepository struct{}
|
|
|
|
func (m *MockLocalizationRepository) GetTranslation(ctx context.Context, key string, language string) (string, error) {
|
|
return "Test translation", nil
|
|
}
|
|
|
|
func (m *MockLocalizationRepository) GetTranslations(ctx context.Context, keys []string, language string) (map[string]string, error) {
|
|
results := make(map[string]string)
|
|
for _, key := range keys {
|
|
results[key] = "Test translation for " + key
|
|
}
|
|
return results, nil
|
|
}
|
|
|
|
// GetResolver returns a minimal GraphQL resolver for testing
|
|
func (s *SimpleTestSuite) GetResolver() *graph.Resolver {
|
|
var mockLocalizationRepo domain_localization.LocalizationRepository = &MockLocalizationRepository{}
|
|
localizationService := localization.NewService(mockLocalizationRepo)
|
|
|
|
return &graph.Resolver{
|
|
App: &app.Application{
|
|
Work: s.WorkService,
|
|
Localization: localizationService,
|
|
},
|
|
}
|
|
}
|
|
|
|
// CreateTestWork creates a test work with optional content
|
|
func (s *SimpleTestSuite) CreateTestWork(title, language string, content string) *domain.Work {
|
|
work := &domain.Work{
|
|
Title: title,
|
|
TranslatableModel: domain.TranslatableModel{Language: language},
|
|
}
|
|
|
|
// Add work to the mock repository
|
|
createdWork, err := s.WorkService.Commands.CreateWork(context.Background(), work)
|
|
s.Require().NoError(err)
|
|
|
|
// If content is provided, we'll need to handle it differently
|
|
// since the mock repository doesn't support translations yet
|
|
// For now, just return the work
|
|
return createdWork
|
|
} |