(t *testing.T)
| 123 | } |
| 124 | |
| 125 | func TestListNotes(t *testing.T) { |
| 126 | // Setup |
| 127 | db := database.InitTestMemoryDB(t) |
| 128 | defer db.Close() |
| 129 | |
| 130 | bookUUID := "js-book-uuid" |
| 131 | database.MustExec(t, "inserting book", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", bookUUID, "javascript") |
| 132 | database.MustExec(t, "inserting note 1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on) VALUES (?, ?, ?, ?)", "note-1", bookUUID, "first note", 1515199943) |
| 133 | database.MustExec(t, "inserting note 2", db, "INSERT INTO notes (uuid, book_uuid, body, added_on) VALUES (?, ?, ?, ?)", "note-2", bookUUID, "multiline note\nwith second line", 1515199945) |
| 134 | |
| 135 | ctx := context.DnoteCtx{DB: db} |
| 136 | var buf bytes.Buffer |
| 137 | |
| 138 | // Execute |
| 139 | err := listNotes(ctx, &buf, "javascript") |
| 140 | if err != nil { |
| 141 | t.Fatal(err) |
| 142 | } |
| 143 | |
| 144 | got := buf.String() |
| 145 | |
| 146 | // Verify output |
| 147 | assert.Equal(t, strings.Contains(got, "on book javascript"), true, "should show book name") |
| 148 | assert.Equal(t, strings.Contains(got, "first note"), true, "should contain first note") |
| 149 | assert.Equal(t, strings.Contains(got, "multiline note"), true, "should show first line of multiline note") |
| 150 | assert.Equal(t, strings.Contains(got, "[---More---]"), true, "should show more indicator for multiline note") |
| 151 | assert.Equal(t, strings.Contains(got, "with second line"), false, "should not show second line of multiline note") |
| 152 | } |
| 153 | |
| 154 | func TestListBooks(t *testing.T) { |
| 155 | // Setup |
nothing calls this directly
no test coverage detected