tercul-backend/internal/testutil/simple_test_utils.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

67 lines
1.9 KiB
Go

package testutil
import (
"context"
graph "tercul/internal/adapters/graphql"
"tercul/internal/app/work"
"tercul/internal/domain"
"github.com/stretchr/testify/suite"
)
// SimpleTestSuite provides a minimal test environment with just the essentials
type SimpleTestSuite struct {
suite.Suite
WorkRepo *UnifiedMockWorkRepository
WorkCommands *work.WorkCommands
WorkQueries *work.WorkQueries
MockAnalyzer *MockAnalyzer
}
// MockAnalyzer is a mock implementation of the analyzer interface.
type MockAnalyzer struct{}
// AnalyzeWork is the mock implementation of the AnalyzeWork method.
func (m *MockAnalyzer) AnalyzeWork(ctx context.Context, workID uint) error {
return nil
}
// SetupSuite sets up the test suite
func (s *SimpleTestSuite) SetupSuite() {
s.WorkRepo = NewUnifiedMockWorkRepository()
s.MockAnalyzer = &MockAnalyzer{}
s.WorkCommands = work.NewWorkCommands(s.WorkRepo, s.MockAnalyzer)
s.WorkQueries = work.NewWorkQueries(s.WorkRepo)
}
// SetupTest resets test data for each test
func (s *SimpleTestSuite) SetupTest() {
s.WorkRepo.Reset()
}
// GetResolver returns a minimal GraphQL resolver for testing
func (s *SimpleTestSuite) GetResolver() *graph.Resolver {
// This needs to be updated to reflect the new resolver structure
// For now, we'll return a resolver with the work commands and queries
return &graph.Resolver{
// WorkRepo: s.WorkRepo, // This should be removed from resolver
// WorkService: s.WorkService, // This is replaced by commands/queries
}
}
// CreateTestWork creates a test work with optional content
func (s *SimpleTestSuite) CreateTestWork(title, language string, content string) *domain.Work {
work := &domain.Work{
Title: title,
Language: language,
}
// Add work to the mock repository
s.WorkRepo.AddWork(work)
// 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 work
}