MCPcopy Index your code
hub / github.com/dnote/dnote / SetupUserData

Function SetupUserData

pkg/server/testutils/main.go:77–99  ·  view source on GitHub ↗

SetupUserData creates and returns a new user with email and password for testing purposes

(db *gorm.DB, email, password string)

Source from the content-addressed store, hash-verified

75
76// SetupUserData creates and returns a new user with email and password for testing purposes
77func 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
102func SetupSession(db *gorm.DB, user database.User) database.Session {

Callers 15

TestViewNoteFunction · 0.92
TestGetNotesFunction · 0.92
TestGetNoteFunction · 0.92
TestCreateNoteFunction · 0.92
TestDeleteNoteFunction · 0.92
TestUpdateNoteFunction · 0.92
TestGetBooksFunction · 0.92
TestGetBooksByNameFunction · 0.92
TestGetBookFunction · 0.92
TestGetBookNonOwnerFunction · 0.92
TestCreateBookFunction · 0.92
TestUpdateBookFunction · 0.92

Calls 2

GenUUIDFunction · 0.92
ToNullStringFunction · 0.92

Tested by 15

TestViewNoteFunction · 0.74
TestGetNotesFunction · 0.74
TestGetNoteFunction · 0.74
TestCreateNoteFunction · 0.74
TestDeleteNoteFunction · 0.74
TestUpdateNoteFunction · 0.74
TestGetBooksFunction · 0.74
TestGetBooksByNameFunction · 0.74
TestGetBookFunction · 0.74
TestGetBookNonOwnerFunction · 0.74
TestCreateBookFunction · 0.74
TestUpdateBookFunction · 0.74