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

Function TestGetBooks

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

Source from the content-addressed store, hash-verified

38}
39
40func TestGetBooks(t *testing.T) {
41 db := testutils.InitMemoryDB(t)
42
43 // Setup
44 a := app.NewTest()
45 a.DB = db
46 a.Clock = clock.NewMock()
47 server := MustNewServer(t, &a)
48 defer server.Close()
49
50 user := testutils.SetupUserData(db, "alice@test.com", "pass1234")
51 anotherUser := testutils.SetupUserData(db, "bob@test.com", "pass1234")
52
53 b1 := database.Book{
54 UUID: testutils.MustUUID(t),
55 UserID: user.ID,
56 Label: "js",
57 USN: 1123,
58 Deleted: false,
59 }
60 testutils.MustExec(t, db.Save(&b1), "preparing b1")
61 b2 := database.Book{
62 UUID: testutils.MustUUID(t),
63 UserID: user.ID,
64 Label: "css",
65 USN: 1125,
66 Deleted: false,
67 }
68 testutils.MustExec(t, db.Save(&b2), "preparing b2")
69 b3 := database.Book{
70 UUID: testutils.MustUUID(t),
71 UserID: anotherUser.ID,
72 Label: "css",
73 USN: 1128,
74 Deleted: false,
75 }
76 testutils.MustExec(t, db.Save(&b3), "preparing b3")
77 b4 := database.Book{
78 UUID: testutils.MustUUID(t),
79 UserID: user.ID,
80 Label: "",
81 USN: 1129,
82 Deleted: true,
83 }
84 testutils.MustExec(t, db.Save(&b4), "preparing b4")
85
86 // Execute
87 endpoint := "/api/v3/books"
88
89 req := testutils.MakeReq(server.URL, "GET", endpoint, "")
90 res := testutils.HTTPAuthDo(t, db, req, user)
91
92 // Test
93 assert.StatusCodeEquals(t, res, http.StatusOK, "")
94
95 var payload []presenters.Book
96 if err := json.NewDecoder(res.Body).Decode(&payload); err != nil {
97 t.Fatal(errors.Wrap(err, "decoding payload"))

Callers

nothing calls this directly

Calls 13

InitMemoryDBFunction · 0.92
NewTestFunction · 0.92
NewMockFunction · 0.92
SetupUserDataFunction · 0.92
MustUUIDFunction · 0.92
MustExecFunction · 0.92
MakeReqFunction · 0.92
HTTPAuthDoFunction · 0.92
StatusCodeEqualsFunction · 0.92
DeepEqualFunction · 0.92
MustNewServerFunction · 0.85
truncateMicroFunction · 0.85

Tested by

no test coverage detected