tercul-backend/internal/app/copyright/main_test.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

226 lines
9.4 KiB
Go

package copyright
import (
"context"
"gorm.io/gorm"
"tercul/internal/domain"
"tercul/internal/domain/work"
)
type mockCopyrightRepository struct {
createFunc func(ctx context.Context, copyright *domain.Copyright) error
updateFunc func(ctx context.Context, copyright *domain.Copyright) error
deleteFunc func(ctx context.Context, id uint) error
addCopyrightToWorkFunc func(ctx context.Context, workID uint, copyrightID uint) error
removeCopyrightFromWorkFunc func(ctx context.Context, workID uint, copyrightID uint) error
addCopyrightToAuthorFunc func(ctx context.Context, authorID uint, copyrightID uint) error
removeCopyrightFromAuthorFunc func(ctx context.Context, authorID uint, copyrightID uint) error
addCopyrightToBookFunc func(ctx context.Context, bookID uint, copyrightID uint) error
removeCopyrightFromBookFunc func(ctx context.Context, bookID uint, copyrightID uint) error
addCopyrightToPublisherFunc func(ctx context.Context, publisherID uint, copyrightID uint) error
removeCopyrightFromPublisherFunc func(ctx context.Context, publisherID uint, copyrightID uint) error
addCopyrightToSourceFunc func(ctx context.Context, sourceID uint, copyrightID uint) error
removeCopyrightFromSourceFunc func(ctx context.Context, sourceID uint, copyrightID uint) error
addTranslationFunc func(ctx context.Context, translation *domain.CopyrightTranslation) error
getByIDFunc func(ctx context.Context, id uint) (*domain.Copyright, error)
listAllFunc func(ctx context.Context) ([]domain.Copyright, error)
getTranslationsFunc func(ctx context.Context, copyrightID uint) ([]domain.CopyrightTranslation, error)
getTranslationByLanguageFunc func(ctx context.Context, copyrightID uint, languageCode string) (*domain.CopyrightTranslation, error)
}
func (m *mockCopyrightRepository) Create(ctx context.Context, copyright *domain.Copyright) error {
if m.createFunc != nil {
return m.createFunc(ctx, copyright)
}
return nil
}
func (m *mockCopyrightRepository) Update(ctx context.Context, copyright *domain.Copyright) error {
if m.updateFunc != nil {
return m.updateFunc(ctx, copyright)
}
return nil
}
func (m *mockCopyrightRepository) Delete(ctx context.Context, id uint) error {
if m.deleteFunc != nil {
return m.deleteFunc(ctx, id)
}
return nil
}
func (m *mockCopyrightRepository) AddCopyrightToWork(ctx context.Context, workID uint, copyrightID uint) error {
if m.addCopyrightToWorkFunc != nil {
return m.addCopyrightToWorkFunc(ctx, workID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) RemoveCopyrightFromWork(ctx context.Context, workID uint, copyrightID uint) error {
if m.removeCopyrightFromWorkFunc != nil {
return m.removeCopyrightFromWorkFunc(ctx, workID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) AddCopyrightToAuthor(ctx context.Context, authorID uint, copyrightID uint) error {
if m.addCopyrightToAuthorFunc != nil {
return m.addCopyrightToAuthorFunc(ctx, authorID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) RemoveCopyrightFromAuthor(ctx context.Context, authorID uint, copyrightID uint) error {
if m.removeCopyrightFromAuthorFunc != nil {
return m.removeCopyrightFromAuthorFunc(ctx, authorID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) AddCopyrightToBook(ctx context.Context, bookID uint, copyrightID uint) error {
if m.addCopyrightToBookFunc != nil {
return m.addCopyrightToBookFunc(ctx, bookID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) RemoveCopyrightFromBook(ctx context.Context, bookID uint, copyrightID uint) error {
if m.removeCopyrightFromBookFunc != nil {
return m.removeCopyrightFromBookFunc(ctx, bookID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) AddCopyrightToPublisher(ctx context.Context, publisherID uint, copyrightID uint) error {
if m.addCopyrightToPublisherFunc != nil {
return m.addCopyrightToPublisherFunc(ctx, publisherID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) RemoveCopyrightFromPublisher(ctx context.Context, publisherID uint, copyrightID uint) error {
if m.removeCopyrightFromPublisherFunc != nil {
return m.removeCopyrightFromPublisherFunc(ctx, publisherID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) AddCopyrightToSource(ctx context.Context, sourceID uint, copyrightID uint) error {
if m.addCopyrightToSourceFunc != nil {
return m.addCopyrightToSourceFunc(ctx, sourceID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) RemoveCopyrightFromSource(ctx context.Context, sourceID uint, copyrightID uint) error {
if m.removeCopyrightFromSourceFunc != nil {
return m.removeCopyrightFromSourceFunc(ctx, sourceID, copyrightID)
}
return nil
}
func (m *mockCopyrightRepository) AddTranslation(ctx context.Context, translation *domain.CopyrightTranslation) error {
if m.addTranslationFunc != nil {
return m.addTranslationFunc(ctx, translation)
}
return nil
}
func (m *mockCopyrightRepository) GetByID(ctx context.Context, id uint) (*domain.Copyright, error) {
if m.getByIDFunc != nil {
return m.getByIDFunc(ctx, id)
}
return nil, nil
}
func (m *mockCopyrightRepository) ListAll(ctx context.Context) ([]domain.Copyright, error) {
if m.listAllFunc != nil {
return m.listAllFunc(ctx)
}
return nil, nil
}
func (m *mockCopyrightRepository) GetTranslations(ctx context.Context, copyrightID uint) ([]domain.CopyrightTranslation, error) {
if m.getTranslationsFunc != nil {
return m.getTranslationsFunc(ctx, copyrightID)
}
return nil, nil
}
func (m *mockCopyrightRepository) GetTranslationByLanguage(ctx context.Context, copyrightID uint, languageCode string) (*domain.CopyrightTranslation, error) {
if m.getTranslationByLanguageFunc != nil {
return m.getTranslationByLanguageFunc(ctx, copyrightID, languageCode)
}
return nil, nil
}
// Implement the rest of the CopyrightRepository interface with empty methods.
func (m *mockCopyrightRepository) List(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[domain.Copyright], error) {
return nil, nil
}
func (m *mockCopyrightRepository) Count(ctx context.Context) (int64, error) { return 0, nil }
func (m *mockCopyrightRepository) CreateInTx(ctx context.Context, tx *gorm.DB, entity *domain.Copyright) error {
return nil
}
func (m *mockCopyrightRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Copyright, error) {
return nil, nil
}
func (m *mockCopyrightRepository) UpdateInTx(ctx context.Context, tx *gorm.DB, entity *domain.Copyright) error {
return nil
}
func (m *mockCopyrightRepository) DeleteInTx(ctx context.Context, tx *gorm.DB, id uint) error {
return nil
}
func (m *mockCopyrightRepository) ListWithOptions(ctx context.Context, options *domain.QueryOptions) ([]domain.Copyright, error) {
return nil, nil
}
func (m *mockCopyrightRepository) CountWithOptions(ctx context.Context, options *domain.QueryOptions) (int64, error) {
return 0, nil
}
func (m *mockCopyrightRepository) FindWithPreload(ctx context.Context, preloads []string, id uint) (*domain.Copyright, error) {
return nil, nil
}
func (m *mockCopyrightRepository) GetAllForSync(ctx context.Context, batchSize, offset int) ([]domain.Copyright, error) {
return nil, nil
}
func (m *mockCopyrightRepository) Exists(ctx context.Context, id uint) (bool, error) { return false, nil }
func (m *mockCopyrightRepository) BeginTx(ctx context.Context) (*gorm.DB, error) { return nil, nil }
func (m *mockCopyrightRepository) WithTx(ctx context.Context, fn func(tx *gorm.DB) error) error {
return nil
}
type mockWorkRepository struct {
work.WorkRepository
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*work.Work, error)
}
func (m *mockWorkRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*work.Work, error) {
if m.getByIDWithOptionsFunc != nil {
return m.getByIDWithOptionsFunc(ctx, id, options)
}
return nil, nil
}
type mockAuthorRepository struct {
domain.AuthorRepository
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Author, error)
}
func (m *mockAuthorRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Author, error) {
if m.getByIDWithOptionsFunc != nil {
return m.getByIDWithOptionsFunc(ctx, id, options)
}
return nil, nil
}
type mockBookRepository struct {
domain.BookRepository
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Book, error)
}
func (m *mockBookRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Book, error) {
if m.getByIDWithOptionsFunc != nil {
return m.getByIDWithOptionsFunc(ctx, id, options)
}
return nil, nil
}
type mockPublisherRepository struct {
domain.PublisherRepository
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Publisher, error)
}
func (m *mockPublisherRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Publisher, error) {
if m.getByIDWithOptionsFunc != nil {
return m.getByIDWithOptionsFunc(ctx, id, options)
}
return nil, nil
}
type mockSourceRepository struct {
domain.SourceRepository
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Source, error)
}
func (m *mockSourceRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Source, error) {
if m.getByIDWithOptionsFunc != nil {
return m.getByIDWithOptionsFunc(ctx, id, options)
}
return nil, nil
}