MCPcopy
hub / github.com/dnote/dnote / TestListBooks

Function TestListBooks

pkg/cli/cmd/view/book_test.go:154–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

152}
153
154func TestListBooks(t *testing.T) {
155 // Setup
156 db := database.InitTestMemoryDB(t)
157 defer db.Close()
158
159 b1UUID := "js-book-uuid"
160 b2UUID := "linux-book-uuid"
161
162 database.MustExec(t, "inserting book 1", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b1UUID, "javascript")
163 database.MustExec(t, "inserting book 2", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b2UUID, "linux")
164
165 // Add notes to test count
166 database.MustExec(t, "inserting note 1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on) VALUES (?, ?, ?, ?)", "note-1", b1UUID, "note body 1", 1515199943)
167 database.MustExec(t, "inserting note 2", db, "INSERT INTO notes (uuid, book_uuid, body, added_on) VALUES (?, ?, ?, ?)", "note-2", b1UUID, "note body 2", 1515199944)
168
169 ctx := context.DnoteCtx{DB: db}
170 var buf bytes.Buffer
171
172 // Execute
173 err := listBooks(ctx, &buf, false)
174 if err != nil {
175 t.Fatal(err)
176 }
177
178 got := buf.String()
179
180 // Verify output
181 assert.Equal(t, strings.Contains(got, "javascript"), true, "should contain javascript book")
182 assert.Equal(t, strings.Contains(got, "linux"), true, "should contain linux book")
183 assert.Equal(t, strings.Contains(got, "(2)"), true, "should show 2 notes for javascript")
184}

Callers

nothing calls this directly

Calls 5

InitTestMemoryDBFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
listBooksFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected