tercul-backend/test/fixtures/works.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

98 lines
2.5 KiB
Go

package fixtures
import (
"context"
"tercul/internal/domain"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// Work fixtures for testing
var (
// ClassicNovel is a fixture for a classic novel
ClassicNovel = domain.Work{
TranslatableModel: domain.TranslatableModel{
BaseModel: domain.BaseModel{
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440201"),
CreatedAt: time.Now().Add(-365 * 24 * time.Hour),
UpdatedAt: time.Now().Add(-30 * 24 * time.Hour),
},
Language: "ru",
},
Title: "War and Peace",
Description: "Epic historical novel by Leo Tolstoy",
Type: "novel",
Status: "published",
}
// ModernPoetry is a fixture for modern poetry
ModernPoetry = domain.Work{
TranslatableModel: domain.TranslatableModel{
BaseModel: domain.BaseModel{
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440202"),
CreatedAt: time.Now().Add(-180 * 24 * time.Hour),
UpdatedAt: time.Now().Add(-10 * 24 * time.Hour),
},
Language: "en",
},
Title: "The Waste Land",
Description: "Modernist poem by T.S. Eliot",
Type: "poetry",
Status: "published",
}
// ShortStory is a fixture for a short story
ShortStory = domain.Work{
TranslatableModel: domain.TranslatableModel{
BaseModel: domain.BaseModel{
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440203"),
CreatedAt: time.Now().Add(-90 * 24 * time.Hour),
UpdatedAt: time.Now().Add(-5 * 24 * time.Hour),
},
Language: "de",
},
Title: "The Metamorphosis",
Description: "Novella by Franz Kafka",
Type: "novella",
Status: "published",
}
// DraftWork is a fixture for a work in draft status
DraftWork = domain.Work{
TranslatableModel: domain.TranslatableModel{
BaseModel: domain.BaseModel{
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440204"),
CreatedAt: time.Now().Add(-7 * 24 * time.Hour),
UpdatedAt: time.Now().Add(-1 * time.Hour),
},
Language: "en",
},
Title: "Untitled Work",
Description: "Work in progress",
Type: "novel",
Status: "draft",
}
)
// AllWorks returns all work fixtures
func AllWorks() []domain.Work {
return []domain.Work{
ClassicNovel,
ModernPoetry,
ShortStory,
DraftWork,
}
}
// LoadWorks loads work fixtures into the database
func LoadWorks(ctx context.Context, db *gorm.DB) error {
for _, work := range AllWorks() {
if err := db.Create(&work).Error; err != nil {
return err
}
}
return nil
}