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

Function TestViewNote

pkg/server/permissions/permissions_test.go:26–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestViewNote(t *testing.T) {
27 db := testutils.InitMemoryDB(t)
28
29 user := testutils.SetupUserData(db, "user@test.com", "password123")
30 anotherUser := testutils.SetupUserData(db, "another@test.com", "password123")
31
32 b1 := database.Book{
33 UUID: testutils.MustUUID(t),
34 UserID: user.ID,
35 Label: "js",
36 }
37 testutils.MustExec(t, db.Save(&b1), "preparing b1")
38
39 note := database.Note{
40 UUID: testutils.MustUUID(t),
41 UserID: user.ID,
42 BookUUID: b1.UUID,
43 Body: "note content",
44 Deleted: false,
45 }
46 testutils.MustExec(t, db.Save(&note), "preparing note")
47
48 t.Run("owner accessing note", func(t *testing.T) {
49 result := ViewNote(&user, note)
50 assert.Equal(t, result, true, "result mismatch")
51 })
52
53 t.Run("non-owner accessing note", func(t *testing.T) {
54 result := ViewNote(&anotherUser, note)
55 assert.Equal(t, result, false, "result mismatch")
56 })
57
58 t.Run("guest accessing note", func(t *testing.T) {
59 result := ViewNote(nil, note)
60 assert.Equal(t, result, false, "result mismatch")
61 })
62}

Callers

nothing calls this directly

Calls 6

InitMemoryDBFunction · 0.92
SetupUserDataFunction · 0.92
MustUUIDFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
ViewNoteFunction · 0.85

Tested by

no test coverage detected