tercul-backend/internal/app/copyright/main_test.go
Damir Mukimov d50722dad5
Some checks failed
Test / Integration Tests (push) Successful in 4s
Build / Build Binary (push) Failing after 2m9s
Docker Build / Build Docker Image (push) Failing after 2m32s
Test / Unit Tests (push) Failing after 3m12s
Lint / Go Lint (push) Failing after 1m0s
Refactor ID handling to use UUIDs across the application
- Updated database models and repositories to replace uint IDs with UUIDs.
- Modified test fixtures to generate and use UUIDs for authors, translations, users, and works.
- Adjusted mock implementations to align with the new UUID structure.
- Ensured all relevant functions and methods are updated to handle UUIDs correctly.
- Added necessary imports for UUID handling in various files.
2025-12-27 00:33:34 +01:00

235 lines
9.6 KiB
Go

package copyright
import (
"context"
"gorm.io/gorm"
"tercul/internal/domain"
)
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 uuid.UUID) (*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 {
domain.WorkRepository
getByIDWithOptionsFunc func(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.Work, error)
}
func (m *mockWorkRepository) GetByIDWithOptions(ctx context.Context, id uint, options *domain.QueryOptions) (*domain.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
}