(t *testing.T)
| 348 | } |
| 349 | |
| 350 | func TestGetNotes_FTSSearch(t *testing.T) { |
| 351 | db := testutils.InitMemoryDB(t) |
| 352 | |
| 353 | user := testutils.SetupUserData(db, "user@test.com", "password123") |
| 354 | b1 := database.Book{UserID: user.ID, Label: "testBook"} |
| 355 | testutils.MustExec(t, db.Save(&b1), "preparing book") |
| 356 | |
| 357 | // Create notes with different content |
| 358 | note1 := database.Note{UserID: user.ID, Deleted: false, Body: "foo bar baz bar", BookUUID: b1.UUID} |
| 359 | testutils.MustExec(t, db.Save(¬e1), "preparing note1") |
| 360 | |
| 361 | note2 := database.Note{UserID: user.ID, Deleted: false, Body: "hello run foo", BookUUID: b1.UUID} |
| 362 | testutils.MustExec(t, db.Save(¬e2), "preparing note2") |
| 363 | |
| 364 | note3 := database.Note{UserID: user.ID, Deleted: false, Body: "running quz succeeded", BookUUID: b1.UUID} |
| 365 | testutils.MustExec(t, db.Save(¬e3), "preparing note3") |
| 366 | |
| 367 | a := NewTest() |
| 368 | a.DB = db |
| 369 | a.Clock = clock.NewMock() |
| 370 | |
| 371 | // Search "baz" |
| 372 | result, err := a.GetNotes(user.ID, GetNotesParams{ |
| 373 | Search: "baz", |
| 374 | Page: 1, |
| 375 | PerPage: 30, |
| 376 | }) |
| 377 | if err != nil { |
| 378 | t.Fatal(errors.Wrap(err, "getting notes with FTS search")) |
| 379 | } |
| 380 | assert.Equal(t, result.Total, int64(1), "Should find 1 note with 'baz'") |
| 381 | assert.Equal(t, len(result.Notes), 1, "Should return 1 note") |
| 382 | for i, note := range result.Notes { |
| 383 | assert.Equal(t, strings.Contains(note.Body, "<dnotehl>baz</dnotehl>"), true, fmt.Sprintf("Note %d should contain highlighted dnote", i)) |
| 384 | } |
| 385 | |
| 386 | // Search for "running" - should return 1 note |
| 387 | result, err = a.GetNotes(user.ID, GetNotesParams{ |
| 388 | Search: "running", |
| 389 | Page: 1, |
| 390 | PerPage: 30, |
| 391 | }) |
| 392 | if err != nil { |
| 393 | t.Fatal(errors.Wrap(err, "getting notes with FTS search for review")) |
| 394 | } |
| 395 | assert.Equal(t, result.Total, int64(2), "Should find 2 note with 'running'") |
| 396 | assert.Equal(t, len(result.Notes), 2, "Should return 2 notes") |
| 397 | assert.Equal(t, result.Notes[0].Body, "<dnotehl>running</dnotehl> quz succeeded", "Should return the review note with highlighting") |
| 398 | assert.Equal(t, result.Notes[1].Body, "hello <dnotehl>run</dnotehl> foo", "Should return the review note with highlighting") |
| 399 | |
| 400 | // Search for non-existent term - should return 0 notes |
| 401 | result, err = a.GetNotes(user.ID, GetNotesParams{ |
| 402 | Search: "nonexistent", |
| 403 | Page: 1, |
| 404 | PerPage: 30, |
| 405 | }) |
| 406 | if err != nil { |
| 407 | t.Fatal(errors.Wrap(err, "getting notes with FTS search for nonexistent")) |
nothing calls this directly
no test coverage detected