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

Function TestUpdateBook

pkg/server/controllers/books_test.go:402–499  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

400}
401
402func 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,

Callers

nothing calls this directly

Calls 14

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

Tested by

no test coverage detected