tercul-backend/internal/app/work/main_test.go
Damir Mukimov 4fd1e71bf0
fix: Resolve CI/CD workflow failures and GraphQL integration test issues
- Fix Application struct mismatch in application_builder.go
- Add global config.Cfg variable and BleveIndexPath field
- Regenerate GraphQL code to fix ProcessArgField errors
- Add search.InitBleve() call in main.go
- Fix all errcheck issues (12 total) in main.go files and test files
- Fix staticcheck issues (deprecated handler.NewDefaultServer, tagged switch)
- Remove all unused code (50 unused items including mock implementations)
- Fix GraphQL 'transport not supported' error in integration tests
- Add comprehensive database cleanup for integration tests
- Update GraphQL server setup with proper error presenter
2025-11-27 06:13:38 +01:00

162 lines
5.8 KiB
Go

package work
import (
"context"
"tercul/internal/domain"
"github.com/stretchr/testify/mock"
"gorm.io/gorm"
)
// #region Mocks
// mockWorkRepository is a mock implementation of domain.WorkRepository
type mockWorkRepository struct{ mock.Mock }
func (m *mockWorkRepository) Create(ctx context.Context, entity *domain.Work) error {
args := m.Called(ctx, entity)
return args.Error(0)
}
func (m *mockWorkRepository) CreateInTx(ctx context.Context, tx *gorm.DB, entity *domain.Work) error {
args := m.Called(ctx, tx, entity)
return args.Error(0)
}
func (m *mockWorkRepository) GetByID(ctx context.Context, id uint) (*domain.Work, error) {
args := m.Called(ctx, id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Work), args.Error(1)
}
func (m *mockWorkRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Work, error) {
args := m.Called(ctx, id, options)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Work), args.Error(1)
}
func (m *mockWorkRepository) Update(ctx context.Context, entity *domain.Work) error {
args := m.Called(ctx, entity)
return args.Error(0)
}
func (m *mockWorkRepository) UpdateInTx(ctx context.Context, tx *gorm.DB, entity *domain.Work) error {
args := m.Called(ctx, tx, entity)
return args.Error(0)
}
func (m *mockWorkRepository) Delete(ctx context.Context, id uint) error {
args := m.Called(ctx, id)
return args.Error(0)
}
func (m *mockWorkRepository) DeleteInTx(ctx context.Context, tx *gorm.DB, id uint) error {
args := m.Called(ctx, tx, id)
return args.Error(0)
}
func (m *mockWorkRepository) List(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[domain.Work], error) {
args := m.Called(ctx, page, pageSize)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.PaginatedResult[domain.Work]), args.Error(1)
}
func (m *mockWorkRepository) ListWithOptions(ctx context.Context, options *domain.QueryOptions) ([]domain.Work, error) {
args := m.Called(ctx, options)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Work), args.Error(1)
}
func (m *mockWorkRepository) ListAll(ctx context.Context) ([]domain.Work, error) {
args := m.Called(ctx)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Work), args.Error(1)
}
func (m *mockWorkRepository) Count(ctx context.Context) (int64, error) {
args := m.Called(ctx)
return args.Get(0).(int64), args.Error(1)
}
func (m *mockWorkRepository) CountWithOptions(ctx context.Context, options *domain.QueryOptions) (int64, error) {
args := m.Called(ctx, options)
return args.Get(0).(int64), args.Error(1)
}
func (m *mockWorkRepository) FindWithPreload(ctx context.Context, preloads []string, id uint) (*domain.Work, error) {
args := m.Called(ctx, preloads, id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Work), args.Error(1)
}
func (m *mockWorkRepository) GetAllForSync(ctx context.Context, batchSize, offset int) ([]domain.Work, error) {
args := m.Called(ctx, batchSize, offset)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]domain.Work), args.Error(1)
}
func (m *mockWorkRepository) Exists(ctx context.Context, id uint) (bool, error) {
args := m.Called(ctx, id)
return args.Bool(0), args.Error(1)
}
func (m *mockWorkRepository) BeginTx(ctx context.Context) (*gorm.DB, error) {
args := m.Called(ctx)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*gorm.DB), args.Error(1)
}
func (m *mockWorkRepository) WithTx(ctx context.Context, fn func(tx *gorm.DB) error) error {
return fn(nil)
}
func (m *mockWorkRepository) FindByTitle(ctx context.Context, title string) ([]domain.Work, error) {
args := m.Called(ctx, title)
return args.Get(0).([]domain.Work), args.Error(1)
}
func (m *mockWorkRepository) FindByAuthor(ctx context.Context, authorID uint) ([]domain.Work, error) {
args := m.Called(ctx, authorID)
return args.Get(0).([]domain.Work), args.Error(1)
}
func (m *mockWorkRepository) FindByCategory(ctx context.Context, categoryID uint) ([]domain.Work, error) {
args := m.Called(ctx, categoryID)
return args.Get(0).([]domain.Work), args.Error(1)
}
func (m *mockWorkRepository) FindByLanguage(ctx context.Context, language string, page, pageSize int) (*domain.PaginatedResult[domain.Work], error) {
args := m.Called(ctx, language, page, pageSize)
return args.Get(0).(*domain.PaginatedResult[domain.Work]), args.Error(1)
}
func (m *mockWorkRepository) GetWithTranslations(ctx context.Context, id uint) (*domain.Work, error) {
args := m.Called(ctx, id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Work), args.Error(1)
}
func (m *mockWorkRepository) IsAuthor(ctx context.Context, workID uint, authorID uint) (bool, error) {
args := m.Called(ctx, workID, authorID)
return args.Bool(0), args.Error(1)
}
func (m *mockWorkRepository) ListByCollectionID(ctx context.Context, collectionID uint) ([]domain.Work, error) {
args := m.Called(ctx, collectionID)
return args.Get(0).([]domain.Work), args.Error(1)
}
func (m *mockWorkRepository) GetWithAssociations(ctx context.Context, id uint) (*domain.Work, error) {
args := m.Called(ctx, id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Work), args.Error(1)
}
func (m *mockWorkRepository) GetWithAssociationsInTx(ctx context.Context, tx *gorm.DB, id uint) (*domain.Work, error) {
args := m.Called(ctx, tx, id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*domain.Work), args.Error(1)
}
func (m *mockWorkRepository) ListWithTranslations(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[domain.Work], error) {
args := m.Called(ctx, page, pageSize)
return args.Get(0).(*domain.PaginatedResult[domain.Work]), args.Error(1)
}
// #endregion Mocks