mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
Some checks failed
- 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.
119 lines
4.5 KiB
Go
119 lines
4.5 KiB
Go
package fixtures
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Translation fixtures for testing
|
|
var (
|
|
// WarAndPeaceEnglishTranslation is a fixture for War and Peace English translation
|
|
WarAndPeaceEnglishTranslation = domain.Translation{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440010"),
|
|
CreatedAt: time.Now().Add(-300 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-20 * 24 * time.Hour),
|
|
},
|
|
TranslatableID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440100"), // War and Peace
|
|
TranslatableType: "works",
|
|
TranslatorID: uuidPtr(uuid.MustParse("550e8400-e29b-41d4-a716-446655440002")), // Editor
|
|
Language: "en",
|
|
Title: "War and Peace",
|
|
Content: "Well, Prince, so Genoa and Lucca are now just family estates of the Buonapartes...",
|
|
Status: domain.TranslationStatusPublished,
|
|
}
|
|
|
|
// WarAndPeaceFrenchTranslation is a fixture for War and Peace French translation
|
|
WarAndPeaceFrenchTranslation = domain.Translation{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440011"),
|
|
CreatedAt: time.Now().Add(-250 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-15 * 24 * time.Hour),
|
|
},
|
|
TranslatableID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440100"), // War and Peace
|
|
TranslatableType: "works",
|
|
TranslatorID: uuidPtr(uuid.MustParse("550e8400-e29b-41d4-a716-446655440003")), // Contributor
|
|
Language: "fr",
|
|
Title: "Guerre et Paix",
|
|
Content: "Eh bien, mon prince, Gênes et Lucques ne sont plus que des apanages...",
|
|
Status: domain.TranslationStatusPublished,
|
|
}
|
|
|
|
// MetamorphosisEnglishTranslation is a fixture for Metamorphosis English translation
|
|
MetamorphosisEnglishTranslation = domain.Translation{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440012"),
|
|
CreatedAt: time.Now().Add(-80 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-3 * 24 * time.Hour),
|
|
},
|
|
TranslatableID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440101"), // The Metamorphosis
|
|
TranslatableType: "works",
|
|
TranslatorID: uuidPtr(uuid.MustParse("550e8400-e29b-41d4-a716-446655440002")), // Editor
|
|
Language: "en",
|
|
Title: "The Metamorphosis",
|
|
Content: "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed...",
|
|
Status: domain.TranslationStatusPublished,
|
|
}
|
|
|
|
// DraftTranslation is a fixture for a draft translation
|
|
DraftTranslation = domain.Translation{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440013"),
|
|
CreatedAt: time.Now().Add(-5 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-2 * time.Hour),
|
|
},
|
|
TranslatableID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440102"), // The Waste Land
|
|
TranslatableType: "works",
|
|
TranslatorID: uuidPtr(uuid.MustParse("550e8400-e29b-41d4-a716-446655440003")), // Contributor
|
|
Language: "es",
|
|
Title: "La tierra baldía",
|
|
Content: "Abril es el mes más cruel...",
|
|
Status: domain.TranslationStatusDraft,
|
|
}
|
|
|
|
// ReviewingTranslation is a fixture for a translation under review
|
|
ReviewingTranslation = domain.Translation{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440014"),
|
|
CreatedAt: time.Now().Add(-10 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-1 * 24 * time.Hour),
|
|
},
|
|
TranslatableID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440102"), // The Waste Land
|
|
TranslatableType: "works",
|
|
TranslatorID: uuidPtr(uuid.MustParse("550e8400-e29b-41d4-a716-446655440003")), // Contributor
|
|
Language: "de",
|
|
Title: "Das wüste Land",
|
|
Content: "April ist der grausamste Monat...",
|
|
Status: domain.TranslationStatusReviewing,
|
|
}
|
|
)
|
|
|
|
func uuidPtr(u uuid.UUID) *uuid.UUID {
|
|
return &u
|
|
}
|
|
|
|
// AllTranslations returns all translation fixtures
|
|
func AllTranslations() []domain.Translation {
|
|
return []domain.Translation{
|
|
WarAndPeaceEnglishTranslation,
|
|
WarAndPeaceFrenchTranslation,
|
|
MetamorphosisEnglishTranslation,
|
|
DraftTranslation,
|
|
ReviewingTranslation,
|
|
}
|
|
}
|
|
|
|
// LoadTranslations loads translation fixtures into the database
|
|
func LoadTranslations(ctx context.Context, db *gorm.DB) error {
|
|
for _, translation := range AllTranslations() {
|
|
if err := db.Create(&translation).Error; err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|