(t *testing.T)
| 231 | } |
| 232 | |
| 233 | func TestUpdateNote_SameContent(t *testing.T) { |
| 234 | db := testutils.InitMemoryDB(t) |
| 235 | |
| 236 | user := testutils.SetupUserData(db, "user@test.com", "password123") |
| 237 | b1 := database.Book{UserID: user.ID, Label: "testBook"} |
| 238 | testutils.MustExec(t, db.Save(&b1), "preparing book") |
| 239 | |
| 240 | note := database.Note{UserID: user.ID, Deleted: false, Body: "test content", BookUUID: b1.UUID} |
| 241 | testutils.MustExec(t, db.Save(¬e), "preparing note") |
| 242 | |
| 243 | a := NewTest() |
| 244 | a.DB = db |
| 245 | a.Clock = clock.NewMock() |
| 246 | |
| 247 | // Update note with same content |
| 248 | sameContent := "test content" |
| 249 | tx := db.Begin() |
| 250 | _, err := a.UpdateNote(tx, user, note, &UpdateNoteParams{ |
| 251 | Content: &sameContent, |
| 252 | }) |
| 253 | if err != nil { |
| 254 | tx.Rollback() |
| 255 | t.Fatal(errors.Wrap(err, "updating note with same content")) |
| 256 | } |
| 257 | tx.Commit() |
| 258 | |
| 259 | // Assert FTS still has the same content |
| 260 | var ftsBody string |
| 261 | testutils.MustExec(t, db.Raw("SELECT body FROM notes_fts WHERE rowid = ?", note.ID).Scan(&ftsBody), "querying notes_fts after update") |
| 262 | assert.Equal(t, ftsBody, "test content", "FTS body should still be 'test content'") |
| 263 | |
| 264 | // Assert it's still searchable |
| 265 | var searchCount int64 |
| 266 | testutils.MustExec(t, db.Raw("SELECT COUNT(*) FROM notes_fts WHERE notes_fts MATCH ?", "test").Scan(&searchCount), "searching notes_fts") |
| 267 | assert.Equal(t, searchCount, int64(1), "Note should still be searchable") |
| 268 | } |
| 269 | |
| 270 | func TestDeleteNote(t *testing.T) { |
| 271 | testCases := []struct { |
nothing calls this directly
no test coverage detected