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

Function TestRemoveUser

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

Source from the content-addressed store, hash-verified

316}
317
318func TestRemoveUser(t *testing.T) {
319 t.Run("success", func(t *testing.T) {
320 db := testutils.InitMemoryDB(t)
321
322 testutils.SetupUserData(db, "alice@example.com", "password123")
323
324 a := NewTest()
325 a.DB = db
326
327 err := a.RemoveUser("alice@example.com")
328
329 assert.Equal(t, err, nil, "should not error")
330
331 // Verify user was deleted
332 var userCount int64
333 testutils.MustExec(t, db.Model(&database.User{}).Count(&userCount), "counting users")
334 assert.Equal(t, userCount, int64(0), "user should be deleted")
335 })
336
337 t.Run("user not found", func(t *testing.T) {
338 db := testutils.InitMemoryDB(t)
339
340 a := NewTest()
341 a.DB = db
342
343 err := a.RemoveUser("nonexistent@example.com")
344
345 assert.Equal(t, err, ErrNotFound, "should return ErrNotFound")
346 })
347
348 t.Run("user has notes", func(t *testing.T) {
349 db := testutils.InitMemoryDB(t)
350
351 user := testutils.SetupUserData(db, "alice@example.com", "password123")
352
353 book := database.Book{UserID: user.ID, Label: "testbook", Deleted: false}
354 testutils.MustExec(t, db.Save(&book), "creating book")
355
356 note := database.Note{UserID: user.ID, BookUUID: book.UUID, Body: "test note", Deleted: false}
357 testutils.MustExec(t, db.Save(&note), "creating note")
358
359 a := NewTest()
360 a.DB = db
361
362 err := a.RemoveUser("alice@example.com")
363
364 assert.Equal(t, err, ErrUserHasExistingResources, "should return ErrUserHasExistingResources")
365
366 // Verify user was NOT deleted
367 var userCount int64
368 testutils.MustExec(t, db.Model(&database.User{}).Count(&userCount), "counting users")
369 assert.Equal(t, userCount, int64(1), "user should not be deleted")
370
371 })
372
373 t.Run("user has books", func(t *testing.T) {
374 db := testutils.InitMemoryDB(t)
375

Callers

nothing calls this directly

Calls 7

InitMemoryDBFunction · 0.92
SetupUserDataFunction · 0.92
EqualFunction · 0.92
MustExecFunction · 0.92
NewTestFunction · 0.85
RemoveUserMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected