tercul-backend/internal/testutil/mock_analytics_service.go
google-labs-jules[bot] 06e6e2be85 refactor(domain): Isolate Work aggregate
This commit isolates the `Work` aggregate into its own package at `internal/domain/work`, following the first step of the refactoring plan in `refactor.md`.

- The `Work` struct, related types, and the `WorkRepository` interface have been moved to the new package.
- A circular dependency between `domain` and `work` was resolved by moving the `AnalyticsRepository` to the `app` layer.
- All references to the moved types have been updated across the entire codebase to fix compilation errors.
- Test files, including mocks and integration tests, have been updated to reflect the new structure.
2025-10-03 16:15:09 +00:00

102 lines
3.2 KiB
Go

package testutil
import (
"context"
"tercul/internal/domain"
"tercul/internal/domain/work"
"time"
"github.com/stretchr/testify/mock"
)
// MockAnalyticsService is a mock implementation of the analytics.Service interface.
type MockAnalyticsService struct {
mock.Mock
}
func (m *MockAnalyticsService) GetTrendingWorks(ctx context.Context, timePeriod string, limit int) ([]*work.Work, error) {
args := m.Called(ctx, timePeriod, limit)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]*work.Work), args.Error(1)
}
func (m *MockAnalyticsService) UpdateTrending(ctx context.Context) error {
args := m.Called(ctx)
return args.Error(0)
}
func (m *MockAnalyticsService) IncrementWorkLikes(ctx context.Context, workID uint) {
m.Called(ctx, workID)
}
func (m *MockAnalyticsService) IncrementTranslationLikes(ctx context.Context, translationID uint) {
m.Called(ctx, translationID)
}
func (m *MockAnalyticsService) IncrementWorkComments(ctx context.Context, workID uint) {
m.Called(ctx, workID)
}
func (m *MockAnalyticsService) IncrementTranslationComments(ctx context.Context, translationID uint) {
m.Called(ctx, translationID)
}
func (m *MockAnalyticsService) IncrementWorkBookmarks(ctx context.Context, workID uint) {
m.Called(ctx, workID)
}
func (m *MockAnalyticsService) GetOrCreateWorkStats(ctx context.Context, workID uint) (*work.WorkStats, error) {
args := m.Called(ctx, workID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*work.WorkStats), args.Error(1)
}
func (m *MockAnalyticsService) GetOrCreateTranslationStats(ctx context.Context, translationID uint) (*domain.TranslationStats, error) {
args := m.Called(ctx, translationID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.TranslationStats), args.Error(1)
}
func (m *MockAnalyticsService) GetOrCreateUserEngagement(ctx context.Context, userID uint, date time.Time) (*domain.UserEngagement, error) {
args := m.Called(ctx, userID, date)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.UserEngagement), args.Error(1)
}
func (m *MockAnalyticsService) UpdateUserEngagement(ctx context.Context, engagement *domain.UserEngagement) error {
args := m.Called(ctx, engagement)
return args.Error(0)
}
func (m *MockAnalyticsService) IncrementWorkCounter(ctx context.Context, workID uint, counter string, value int) error {
args := m.Called(ctx, workID, counter, value)
return args.Error(0)
}
func (m *MockAnalyticsService) IncrementTranslationCounter(ctx context.Context, translationID uint, counter string, value int) error {
args := m.Called(ctx, translationID, counter, value)
return args.Error(0)
}
func (m *MockAnalyticsService) UpdateWorkStats(ctx context.Context, workID uint, stats work.WorkStats) error {
args := m.Called(ctx, workID, stats)
return args.Error(0)
}
func (m *MockAnalyticsService) UpdateTranslationStats(ctx context.Context, translationID uint, stats domain.TranslationStats) error {
args := m.Called(ctx, translationID, stats)
return args.Error(0)
}
func (m *MockAnalyticsService) UpdateTrendingWorks(ctx context.Context, timePeriod string, trendingWorks []*domain.Trending) error {
args := m.Called(ctx, timePeriod, trendingWorks)
return args.Error(0)
}