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" domain_work "tercul/internal/domain/work" "github.com/stretchr/testify/suite" ) // SimpleTestSuite provides a minimal test environment with just the essentials type SimpleTestSuite struct { suite.Suite WorkRepo *MockWorkRepository 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.Work, pipeline string) error { return nil } // SetupSuite sets up the test suite func (s *SimpleTestSuite) SetupSuite() { s.WorkRepo = NewMockWorkRepository() s.MockSearchClient = &MockSearchClient{} s.WorkService = work.NewService(s.WorkRepo, s.MockSearchClient) } // SetupTest resets test data for each test func (s *SimpleTestSuite) SetupTest() { s.WorkRepo = NewMockWorkRepository() } // 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 } // GetAuthorBiography is a mock implementation of the GetAuthorBiography method. func (m *MockLocalizationRepository) GetAuthorBiography(ctx context.Context, authorID uint, language string) (string, error) { return "This is a mock biography.", 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 { work := &domain_work.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 }