mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 02:51: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.
98 lines
2.5 KiB
Go
98 lines
2.5 KiB
Go
package fixtures
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Author fixtures for testing
|
|
var (
|
|
// TolstoyAuthor is a fixture for Leo Tolstoy
|
|
TolstoyAuthor = domain.Author{
|
|
TranslatableModel: domain.TranslatableModel{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440001"),
|
|
CreatedAt: time.Now().Add(-365 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-30 * 24 * time.Hour),
|
|
},
|
|
Language: "en",
|
|
},
|
|
Name: "Leo Tolstoy",
|
|
BirthDate: timePtr("1828-09-09T00:00:00Z"),
|
|
DeathDate: timePtr("1910-11-20T00:00:00Z"),
|
|
}
|
|
|
|
// EliotAuthor is a fixture for T.S. Eliot
|
|
EliotAuthor = domain.Author{
|
|
TranslatableModel: domain.TranslatableModel{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440002"),
|
|
CreatedAt: time.Now().Add(-180 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-10 * 24 * time.Hour),
|
|
},
|
|
Language: "en",
|
|
},
|
|
Name: "T.S. Eliot",
|
|
BirthDate: timePtr("1888-09-26T00:00:00Z"),
|
|
DeathDate: timePtr("1965-01-04T00:00:00Z"),
|
|
}
|
|
|
|
// KafkaAuthor is a fixture for Franz Kafka
|
|
KafkaAuthor = domain.Author{
|
|
TranslatableModel: domain.TranslatableModel{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440003"),
|
|
CreatedAt: time.Now().Add(-90 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-5 * 24 * time.Hour),
|
|
},
|
|
Language: "en",
|
|
},
|
|
Name: "Franz Kafka",
|
|
BirthDate: timePtr("1883-07-03T00:00:00Z"),
|
|
DeathDate: timePtr("1924-06-03T00:00:00Z"),
|
|
}
|
|
|
|
// ContemporaryAuthor is a fixture for a contemporary author
|
|
ContemporaryAuthor = domain.Author{
|
|
TranslatableModel: domain.TranslatableModel{
|
|
BaseModel: domain.BaseModel{
|
|
ID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440004"),
|
|
CreatedAt: time.Now().Add(-30 * 24 * time.Hour),
|
|
UpdatedAt: time.Now(),
|
|
},
|
|
Language: "en",
|
|
},
|
|
Name: "Jane Modern",
|
|
BirthDate: timePtr("1985-03-15T00:00:00Z"),
|
|
}
|
|
)
|
|
|
|
// AllAuthors returns all author fixtures
|
|
func AllAuthors() []domain.Author {
|
|
return []domain.Author{
|
|
TolstoyAuthor,
|
|
EliotAuthor,
|
|
KafkaAuthor,
|
|
ContemporaryAuthor,
|
|
}
|
|
}
|
|
|
|
// LoadAuthors loads author fixtures into the database
|
|
func LoadAuthors(ctx context.Context, db *gorm.DB) error {
|
|
for _, author := range AllAuthors() {
|
|
if err := db.Create(&author).Error; err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func timePtr(s string) *time.Time {
|
|
t, _ := time.Parse(time.RFC3339, s)
|
|
return &t
|
|
}
|