(t *testing.T)
| 356 | } |
| 357 | |
| 358 | func 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(¬e), "preparing note") |
| 413 | |
| 414 | // Execute |
| 415 | endpoint := fmt.Sprintf("/api/v3/notes/%s", note.UUID) |
nothing calls this directly
no test coverage detected