(t *testing.T)
| 400 | } |
| 401 | |
| 402 | func TestUpdateBook(t *testing.T) { |
| 403 | updatedLabel := "updated-label" |
| 404 | |
| 405 | b1UUID := "ead8790f-aff9-4bdf-8eec-f734ccd29202" |
| 406 | b2UUID := "0ecaac96-8d72-4e04-8925-5a21b79a16da" |
| 407 | |
| 408 | type payloadData struct { |
| 409 | Name *string `schema:"name" json:"name,omitempty"` |
| 410 | } |
| 411 | |
| 412 | testCases := []struct { |
| 413 | payload testutils.PayloadWrapper |
| 414 | bookUUID string |
| 415 | bookDeleted bool |
| 416 | bookLabel string |
| 417 | expectedBookLabel string |
| 418 | }{ |
| 419 | { |
| 420 | payload: testutils.PayloadWrapper{ |
| 421 | Data: payloadData{ |
| 422 | Name: &updatedLabel, |
| 423 | }, |
| 424 | }, |
| 425 | bookUUID: b1UUID, |
| 426 | bookDeleted: false, |
| 427 | bookLabel: "original-label", |
| 428 | expectedBookLabel: updatedLabel, |
| 429 | }, |
| 430 | // if a deleted book is updated, it should be un-deleted |
| 431 | { |
| 432 | payload: testutils.PayloadWrapper{ |
| 433 | Data: payloadData{ |
| 434 | Name: &updatedLabel, |
| 435 | }, |
| 436 | }, |
| 437 | bookUUID: b1UUID, |
| 438 | bookDeleted: true, |
| 439 | bookLabel: "", |
| 440 | expectedBookLabel: updatedLabel, |
| 441 | }, |
| 442 | } |
| 443 | |
| 444 | for idx, tc := range testCases { |
| 445 | t.Run(fmt.Sprintf("test case %d", idx), func(t *testing.T) { |
| 446 | db := testutils.InitMemoryDB(t) |
| 447 | |
| 448 | // Setup |
| 449 | a := app.NewTest() |
| 450 | a.DB = db |
| 451 | a.Clock = clock.NewMock() |
| 452 | server := MustNewServer(t, &a) |
| 453 | defer server.Close() |
| 454 | |
| 455 | user := testutils.SetupUserData(db, "alice@test.com", "pass1234") |
| 456 | testutils.MustExec(t, db.Model(&user).Update("max_usn", 101), "preparing user max_usn") |
| 457 | |
| 458 | b1 := database.Book{ |
| 459 | UUID: tc.bookUUID, |
nothing calls this directly
no test coverage detected