mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package testutil
|
|
|
|
import (
|
|
"context"
|
|
graph "tercul/internal/adapters/graphql"
|
|
"tercul/internal/app"
|
|
"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 {
|
|
return &graph.Resolver{
|
|
App: &app.Application{
|
|
WorkCommands: s.WorkCommands,
|
|
WorkQueries: s.WorkQueries,
|
|
Localization: &MockLocalization{},
|
|
},
|
|
}
|
|
}
|
|
|
|
type MockLocalization struct{}
|
|
|
|
func (m *MockLocalization) GetWorkContent(ctx context.Context, workID uint, preferredLanguage string) (string, error) {
|
|
return "Test content for work", nil
|
|
}
|
|
|
|
func (m *MockLocalization) GetAuthorBiography(ctx context.Context, authorID uint, preferredLanguage string) (string, error) {
|
|
return "Test biography", nil
|
|
}
|
|
|
|
// 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
|
|
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
|
|
}
|