(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func 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(¬e), "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 | } |
nothing calls this directly
no test coverage detected