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

Function TestGetActiveNote

pkg/cli/database/queries_test.go:230–280  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

228}
229
230func TestGetActiveNote(t *testing.T) {
231 t.Run("not deleted", func(t *testing.T) {
232 // set up
233 db := InitTestMemoryDB(t)
234
235 n1UUID := "n1-uuid"
236 MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n1UUID, "b1-uuid", "n1 content", 1542058875, 1542058876, 1, false, true)
237
238 var n1RowID int
239 MustScan(t, "getting rowid", db.QueryRow("SELECT rowid FROM notes WHERE uuid = ?", n1UUID), &n1RowID)
240
241 // execute
242 got, err := GetActiveNote(db, n1RowID)
243 if err != nil {
244 t.Fatal(errors.Wrap(err, "executing"))
245 }
246
247 // test
248 assert.Equal(t, got.RowID, n1RowID, "RowID mismatch")
249 assert.Equal(t, got.UUID, n1UUID, "UUID mismatch")
250 assert.Equal(t, got.BookUUID, "b1-uuid", "BookUUID mismatch")
251 assert.Equal(t, got.Body, "n1 content", "Body mismatch")
252 assert.Equal(t, got.AddedOn, int64(1542058875), "AddedOn mismatch")
253 assert.Equal(t, got.EditedOn, int64(1542058876), "EditedOn mismatch")
254 assert.Equal(t, got.USN, 1, "USN mismatch")
255 assert.Equal(t, got.Deleted, false, "Deleted mismatch")
256 assert.Equal(t, got.Dirty, true, "Dirty mismatch")
257 })
258
259 t.Run("deleted", func(t *testing.T) {
260 // set up
261 db := InitTestMemoryDB(t)
262
263 n1UUID := "n1-uuid"
264 MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n1UUID, "b1-uuid", "n1 content", 1542058875, 1542058876, 1, true, true)
265
266 var n1RowID int
267 MustScan(t, "getting rowid", db.QueryRow("SELECT rowid FROM notes WHERE uuid = ?", n1UUID), &n1RowID)
268
269 // execute
270 _, err := GetActiveNote(db, n1RowID)
271
272 // test
273 if err == nil {
274 t.Error("Should have returned an error")
275 }
276 if err != nil && err != sql.ErrNoRows {
277 t.Error(errors.Wrap(err, "executing"))
278 }
279 })
280}
281
282func TestUpdateNoteContent(t *testing.T) {
283 // set up

Callers

nothing calls this directly

Calls 7

EqualFunction · 0.92
InitTestMemoryDBFunction · 0.85
MustScanFunction · 0.85
GetActiveNoteFunction · 0.85
MustExecFunction · 0.70
QueryRowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected