package fixtures import ( "context" "tercul/internal/domain" "time" "golang.org/x/crypto/bcrypt" "gorm.io/gorm" ) // User fixtures for testing var ( // AdminUser is a fixture for an admin user AdminUser = domain.User{ BaseModel: domain.BaseModel{ ID: 1, CreatedAt: time.Now().Add(-30 * 24 * time.Hour), UpdatedAt: time.Now().Add(-1 * 24 * time.Hour), }, Username: "admin", Email: "admin@tercul.com", Password: hashPassword("admin123"), FirstName: "Admin", LastName: "User", DisplayName: "Admin", Bio: "Platform administrator", Role: domain.UserRoleAdmin, Verified: true, Active: true, } // EditorUser is a fixture for an editor user EditorUser = domain.User{ BaseModel: domain.BaseModel{ ID: 2, CreatedAt: time.Now().Add(-20 * 24 * time.Hour), UpdatedAt: time.Now().Add(-2 * 24 * time.Hour), }, Username: "editor", Email: "editor@tercul.com", Password: hashPassword("editor123"), FirstName: "Editor", LastName: "User", DisplayName: "Editor", Bio: "Content editor", Role: domain.UserRoleEditor, Verified: true, Active: true, } // ContributorUser is a fixture for a contributor user ContributorUser = domain.User{ BaseModel: domain.BaseModel{ ID: 3, CreatedAt: time.Now().Add(-15 * 24 * time.Hour), UpdatedAt: time.Now().Add(-1 * time.Hour), }, Username: "contributor", Email: "contributor@tercul.com", Password: hashPassword("contributor123"), FirstName: "Contributor", LastName: "User", DisplayName: "Contributor", Bio: "Active contributor", Role: domain.UserRoleContributor, Verified: true, Active: true, } // ReaderUser is a fixture for a reader user ReaderUser = domain.User{ BaseModel: domain.BaseModel{ ID: 4, CreatedAt: time.Now().Add(-10 * 24 * time.Hour), UpdatedAt: time.Now(), }, Username: "reader", Email: "reader@tercul.com", Password: hashPassword("reader123"), FirstName: "Reader", LastName: "User", DisplayName: "Reader", Bio: "Book enthusiast", Role: domain.UserRoleReader, Verified: true, Active: true, } // InactiveUser is a fixture for an inactive user InactiveUser = domain.User{ BaseModel: domain.BaseModel{ ID: 5, CreatedAt: time.Now().Add(-5 * 24 * time.Hour), UpdatedAt: time.Now().Add(-3 * 24 * time.Hour), }, Username: "inactive", Email: "inactive@tercul.com", Password: hashPassword("inactive123"), Role: domain.UserRoleReader, Verified: false, Active: false, } ) // AllUsers returns all user fixtures func AllUsers() []domain.User { return []domain.User{ AdminUser, EditorUser, ContributorUser, ReaderUser, InactiveUser, } } // hashPassword hashes a password for testing func hashPassword(password string) string { hash, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) return string(hash) } // LoadUsers loads user fixtures into the database func LoadUsers(ctx context.Context, db *gorm.DB) error { for _, user := range AllUsers() { if err := db.Create(&user).Error; err != nil { return err } } return nil }