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

Function TestDeleteNote

pkg/server/controllers/notes_test.go:358–445  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

356}
357
358func TestDeleteNote(t *testing.T) {
359 b1UUID := "37868a8e-a844-4265-9a4f-0be598084733"
360
361 testCases := []struct {
362 content string
363 deleted bool
364 originalUSN int
365 expectedUSN int
366 expectedMaxUSN int
367 }{
368 {
369 content: "n1 content",
370 deleted: false,
371 originalUSN: 12,
372 expectedUSN: 982,
373 expectedMaxUSN: 982,
374 },
375 {
376 content: "",
377 deleted: true,
378 originalUSN: 12,
379 expectedUSN: 982,
380 expectedMaxUSN: 982,
381 },
382 }
383
384 for idx, tc := range testCases {
385 t.Run(fmt.Sprintf("test case %d", idx), func(t *testing.T) {
386 db := testutils.InitMemoryDB(t)
387
388 // Setup
389 a := app.NewTest()
390 a.DB = db
391 a.Clock = clock.NewMock()
392 server := MustNewServer(t, &a)
393 defer server.Close()
394
395 user := testutils.SetupUserData(db, "alice@test.com", "pass1234")
396 testutils.MustExec(t, db.Model(&user).Update("max_usn", 981), "preparing user max_usn")
397
398 b1 := database.Book{
399 UUID: b1UUID,
400 UserID: user.ID,
401 Label: "js",
402 }
403 testutils.MustExec(t, db.Save(&b1), "preparing b1")
404 note := database.Note{
405 UUID: testutils.MustUUID(t),
406 UserID: user.ID,
407 BookUUID: b1.UUID,
408 Body: tc.content,
409 Deleted: tc.deleted,
410 USN: tc.originalUSN,
411 }
412 testutils.MustExec(t, db.Save(&note), "preparing note")
413
414 // Execute
415 endpoint := fmt.Sprintf("/api/v3/notes/%s", note.UUID)

Callers

nothing calls this directly

Calls 14

InitMemoryDBFunction · 0.92
NewTestFunction · 0.92
NewMockFunction · 0.92
SetupUserDataFunction · 0.92
MustExecFunction · 0.92
MustUUIDFunction · 0.92
MakeReqFunction · 0.92
HTTPAuthDoFunction · 0.92
StatusCodeEqualsFunction · 0.92
EqualfFunction · 0.92
EqualFunction · 0.92
MustNewServerFunction · 0.85

Tested by

no test coverage detected