(t *testing.T)
| 412 | } |
| 413 | |
| 414 | func TestGetNotes_FTSSearch_Snippet(t *testing.T) { |
| 415 | db := testutils.InitMemoryDB(t) |
| 416 | |
| 417 | user := testutils.SetupUserData(db, "user@test.com", "password123") |
| 418 | b1 := database.Book{UserID: user.ID, Label: "testBook"} |
| 419 | testutils.MustExec(t, db.Save(&b1), "preparing book") |
| 420 | |
| 421 | // Create a long note to test snippet truncation with "..." |
| 422 | // The snippet limit is 50 tokens, so we generate enough words to exceed it |
| 423 | longBody := strings.Repeat("filler ", 100) + "the important keyword appears here" |
| 424 | longNote := database.Note{UserID: user.ID, Deleted: false, Body: longBody, BookUUID: b1.UUID} |
| 425 | testutils.MustExec(t, db.Save(&longNote), "preparing long note") |
| 426 | |
| 427 | a := NewTest() |
| 428 | a.DB = db |
| 429 | a.Clock = clock.NewMock() |
| 430 | |
| 431 | // Search for "keyword" in long note - should return snippet with "..." |
| 432 | result, err := a.GetNotes(user.ID, GetNotesParams{ |
| 433 | Search: "keyword", |
| 434 | Page: 1, |
| 435 | PerPage: 30, |
| 436 | }) |
| 437 | if err != nil { |
| 438 | t.Fatal(errors.Wrap(err, "getting notes with FTS search for keyword")) |
| 439 | } |
| 440 | |
| 441 | assert.Equal(t, result.Total, int64(1), "Should find 1 note with 'keyword'") |
| 442 | assert.Equal(t, len(result.Notes), 1, "Should return 1 note") |
| 443 | // The snippet should contain "..." to indicate truncation and the highlighted keyword |
| 444 | assert.Equal(t, strings.Contains(result.Notes[0].Body, "..."), true, "Snippet should contain '...' for truncation") |
| 445 | assert.Equal(t, strings.Contains(result.Notes[0].Body, "<dnotehl>keyword</dnotehl>"), true, "Snippet should contain highlighted keyword") |
| 446 | } |
| 447 | |
| 448 | func TestGetNotes_FTSSearch_ShortWord(t *testing.T) { |
| 449 | db := testutils.InitMemoryDB(t) |
nothing calls this directly
no test coverage detected