package search import ( "context" "errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "tercul/internal/domain" "testing" ) type mockLocalizationService struct { getWorkContentFunc func(ctx context.Context, workID uint, preferredLanguage string) (string, error) } func (m *mockLocalizationService) GetWorkContent(ctx context.Context, workID uint, preferredLanguage string) (string, error) { if m.getWorkContentFunc != nil { return m.getWorkContentFunc(ctx, workID, preferredLanguage) } return "", nil } func (m *mockLocalizationService) GetAuthorBiography(ctx context.Context, authorID uint, preferredLanguage string) (string, error) { return "", nil } type mockWeaviateWrapper struct { indexWorkFunc func(ctx context.Context, work *domain.Work, content string) error } func (m *mockWeaviateWrapper) IndexWork(ctx context.Context, work *domain.Work, content string) error { if m.indexWorkFunc != nil { return m.indexWorkFunc(ctx, work, content) } return nil } type SearchServiceSuite struct { suite.Suite localization *mockLocalizationService weaviate *mockWeaviateWrapper service IndexService } func (s *SearchServiceSuite) SetupTest() { s.localization = &mockLocalizationService{} s.weaviate = &mockWeaviateWrapper{} s.service = NewIndexService(s.localization, s.weaviate) } func TestSearchServiceSuite(t *testing.T) { suite.Run(t, new(SearchServiceSuite)) } func (s *SearchServiceSuite) TestIndexWork_Success() { work := domain.Work{Title: "Test Work"} work.ID = 1 s.localization.getWorkContentFunc = func(ctx context.Context, workID uint, preferredLanguage string) (string, error) { return "test content", nil } s.weaviate.indexWorkFunc = func(ctx context.Context, work *domain.Work, content string) error { assert.Equal(s.T(), "test content", content) return nil } err := s.service.IndexWork(context.Background(), work) assert.NoError(s.T(), err) } func (s *SearchServiceSuite) TestIndexWork_LocalizationError() { work := domain.Work{Title: "Test Work"} work.ID = 1 s.localization.getWorkContentFunc = func(ctx context.Context, workID uint, preferredLanguage string) (string, error) { return "", errors.New("localization error") } err := s.service.IndexWork(context.Background(), work) assert.Error(s.T(), err) } func TestFormatID(t *testing.T) { assert.Equal(t, "123", formatID(123)) } func (s *SearchServiceSuite) TestIndexWork_WeaviateError() { work := domain.Work{Title: "Test Work"} work.ID = 1 s.localization.getWorkContentFunc = func(ctx context.Context, workID uint, preferredLanguage string) (string, error) { return "test content", nil } s.weaviate.indexWorkFunc = func(ctx context.Context, work *domain.Work, content string) error { return errors.New("weaviate error") } err := s.service.IndexWork(context.Background(), work) assert.Error(s.T(), err) }