package services import ( "context" "testing" "tercul/internal/domain" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) // Mock Repositories type MockWorkRepository struct { mock.Mock domain.WorkRepository } func (m *MockWorkRepository) Count(ctx context.Context) (int64, error) { args := m.Called(ctx) return args.Get(0).(int64), args.Error(1) } // Implement other methods of the WorkRepository interface if needed for other tests type MockTranslationRepository struct { mock.Mock domain.TranslationRepository } func (m *MockTranslationRepository) Count(ctx context.Context) (int64, error) { args := m.Called(ctx) return args.Get(0).(int64), args.Error(1) } // Implement other methods of the TranslationRepository interface if needed for other tests type MockAuthorRepository struct { mock.Mock domain.AuthorRepository } func (m *MockAuthorRepository) Count(ctx context.Context) (int64, error) { args := m.Called(ctx) return args.Get(0).(int64), args.Error(1) } // Implement other methods of the AuthorRepository interface if needed for other tests type MockUserRepository struct { mock.Mock domain.UserRepository } func (m *MockUserRepository) Count(ctx context.Context) (int64, error) { args := m.Called(ctx) return args.Get(0).(int64), args.Error(1) } // Implement other methods of the UserRepository interface if needed for other tests type MockLikeRepository struct { mock.Mock domain.LikeRepository } func (m *MockLikeRepository) Count(ctx context.Context) (int64, error) { args := m.Called(ctx) return args.Get(0).(int64), args.Error(1) } // Implement other methods of the LikeRepository interface if needed for other tests func TestAnalyticsService_GetAnalytics(t *testing.T) { ctx := context.Background() mockWorkRepo := new(MockWorkRepository) mockTranslationRepo := new(MockTranslationRepository) mockAuthorRepo := new(MockAuthorRepository) mockUserRepo := new(MockUserRepository) mockLikeRepo := new(MockLikeRepository) mockWorkRepo.On("Count", ctx).Return(int64(10), nil) mockTranslationRepo.On("Count", ctx).Return(int64(20), nil) mockAuthorRepo.On("Count", ctx).Return(int64(5), nil) mockUserRepo.On("Count", ctx).Return(int64(100), nil) mockLikeRepo.On("Count", ctx).Return(int64(50), nil) service := NewAnalyticsService(mockWorkRepo, mockTranslationRepo, mockAuthorRepo, mockUserRepo, mockLikeRepo) analytics, err := service.GetAnalytics(ctx) assert.NoError(t, err) assert.NotNil(t, analytics) assert.Equal(t, int64(10), analytics.TotalWorks) assert.Equal(t, int64(20), analytics.TotalTranslations) assert.Equal(t, int64(5), analytics.TotalAuthors) assert.Equal(t, int64(100), analytics.TotalUsers) assert.Equal(t, int64(50), analytics.TotalLikes) mockWorkRepo.AssertExpectations(t) mockTranslationRepo.AssertExpectations(t) mockAuthorRepo.AssertExpectations(t) mockUserRepo.AssertExpectations(t) mockLikeRepo.AssertExpectations(t) }