SetupUserData creates and returns a new user with email and password for testing purposes
(db *gorm.DB, email, password string)
| 75 | |
| 76 | // SetupUserData creates and returns a new user with email and password for testing purposes |
| 77 | func SetupUserData(db *gorm.DB, email, password string) database.User { |
| 78 | uuid, err := helpers.GenUUID() |
| 79 | if err != nil { |
| 80 | panic(errors.Wrap(err, "Failed to generate UUID")) |
| 81 | } |
| 82 | |
| 83 | hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) |
| 84 | if err != nil { |
| 85 | panic(errors.Wrap(err, "Failed to hash password")) |
| 86 | } |
| 87 | |
| 88 | user := database.User{ |
| 89 | UUID: uuid, |
| 90 | Email: database.ToNullString(email), |
| 91 | Password: database.ToNullString(string(hashedPassword)), |
| 92 | } |
| 93 | |
| 94 | if err := db.Save(&user).Error; err != nil { |
| 95 | panic(errors.Wrap(err, "Failed to prepare user")) |
| 96 | } |
| 97 | |
| 98 | return user |
| 99 | } |
| 100 | |
| 101 | // SetupSession creates and returns a new user session |
| 102 | func SetupSession(db *gorm.DB, user database.User) database.Session { |