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

Function TestCreateUser

pkg/server/app/users_test.go:177–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

175}
176
177func TestCreateUser(t *testing.T) {
178 t.Run("success", func(t *testing.T) {
179 db := testutils.InitMemoryDB(t)
180
181 a := NewTest()
182 a.DB = db
183 if _, err := a.CreateUser("alice@example.com", "pass1234", "pass1234"); err != nil {
184 t.Fatal(errors.Wrap(err, "executing"))
185 }
186
187 var userCount int64
188 testutils.MustExec(t, db.Model(&database.User{}).Count(&userCount), "counting user")
189 assert.Equal(t, userCount, int64(1), "user count mismatch")
190
191 var userRecord database.User
192 testutils.MustExec(t, db.First(&userRecord), "finding user")
193
194 assert.Equal(t, userRecord.Email.String, "alice@example.com", "user email mismatch")
195
196 passwordErr := bcrypt.CompareHashAndPassword([]byte(userRecord.Password.String), []byte("pass1234"))
197 assert.Equal(t, passwordErr, nil, "Password mismatch")
198 })
199
200 t.Run("duplicate email", func(t *testing.T) {
201 db := testutils.InitMemoryDB(t)
202
203 testutils.SetupUserData(db, "alice@example.com", "somepassword")
204
205 a := NewTest()
206 a.DB = db
207 _, err := a.CreateUser("alice@example.com", "newpassword", "newpassword")
208
209 assert.Equal(t, err, ErrDuplicateEmail, "error mismatch")
210
211 var userCount int64
212 testutils.MustExec(t, db.Model(&database.User{}).Count(&userCount), "counting user")
213
214 assert.Equal(t, userCount, int64(1), "user count mismatch")
215 })
216}
217
218func TestUpdateUserPassword(t *testing.T) {
219 t.Run("success", func(t *testing.T) {

Callers

nothing calls this directly

Calls 6

InitMemoryDBFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
SetupUserDataFunction · 0.92
NewTestFunction · 0.85
CreateUserMethod · 0.80

Tested by

no test coverage detected