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

Function TestGetNote

pkg/server/operations/notes_test.go:27–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestGetNote(t *testing.T) {
28 db := testutils.InitMemoryDB(t)
29
30 user := testutils.SetupUserData(db, "user@test.com", "password123")
31 anotherUser := testutils.SetupUserData(db, "another@test.com", "password123")
32
33 b1 := database.Book{
34 UUID: testutils.MustUUID(t),
35 UserID: user.ID,
36 Label: "js",
37 }
38 testutils.MustExec(t, db.Save(&b1), "preparing b1")
39
40 note := database.Note{
41 UUID: testutils.MustUUID(t),
42 UserID: user.ID,
43 BookUUID: b1.UUID,
44 Body: "note content",
45 Deleted: false,
46 }
47 testutils.MustExec(t, db.Save(&note), "preparing note")
48
49 var noteRecord database.Note
50 testutils.MustExec(t, db.Where("uuid = ?", note.UUID).Preload("Book").Preload("User").First(&noteRecord), "finding note")
51
52 testCases := []struct {
53 name string
54 user database.User
55 note database.Note
56 expectedOK bool
57 expectedNote database.Note
58 }{
59 {
60 name: "owner accessing note",
61 user: user,
62 note: note,
63 expectedOK: true,
64 expectedNote: noteRecord,
65 },
66 {
67 name: "non-owner accessing note",
68 user: anotherUser,
69 note: note,
70 expectedOK: false,
71 expectedNote: database.Note{},
72 },
73 {
74 name: "guest accessing note",
75 user: database.User{},
76 note: note,
77 expectedOK: false,
78 expectedNote: database.Note{},
79 },
80 }
81
82 for _, tc := range testCases {
83 t.Run(tc.name, func(t *testing.T) {
84 note, ok, err := GetNote(db, tc.note.UUID, &tc.user)

Callers

nothing calls this directly

Calls 7

InitMemoryDBFunction · 0.92
SetupUserDataFunction · 0.92
MustUUIDFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
DeepEqualFunction · 0.92
GetNoteFunction · 0.85

Tested by

no test coverage detected