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

Function TestGetBookNonOwner

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

Source from the content-addressed store, hash-verified

258}
259
260func TestGetBookNonOwner(t *testing.T) {
261 db := testutils.InitMemoryDB(t)
262
263 // Setup
264 a := app.NewTest()
265 a.DB = db
266 a.Clock = clock.NewMock()
267 server := MustNewServer(t, &a)
268 defer server.Close()
269
270 user := testutils.SetupUserData(db, "alice@test.com", "pass1234")
271 nonOwner := testutils.SetupUserData(db, "bob@test.com", "pass1234")
272
273 b1 := database.Book{
274 UUID: testutils.MustUUID(t),
275 UserID: user.ID,
276 Label: "js",
277 }
278 testutils.MustExec(t, db.Save(&b1), "preparing b1")
279
280 // Execute
281 endpoint := fmt.Sprintf("/api/v3/books/%s", b1.UUID)
282 req := testutils.MakeReq(server.URL, "GET", endpoint, "")
283 res := testutils.HTTPAuthDo(t, db, req, nonOwner)
284
285 // Test
286 assert.StatusCodeEquals(t, res, http.StatusNotFound, "")
287
288 body, err := io.ReadAll(res.Body)
289 if err != nil {
290 t.Fatal(errors.Wrap(err, "reading body"))
291 }
292 assert.DeepEqual(t, string(body), "", "payload mismatch")
293}
294
295func TestCreateBook(t *testing.T) {
296 t.Run("success", func(t *testing.T) {

Callers

nothing calls this directly

Calls 12

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
CloseMethod · 0.65

Tested by

no test coverage detected