MCPcopy Create free account
hub / github.com/dnote/dnote / TestGetNotes_FTSSearch_Snippet

Function TestGetNotes_FTSSearch_Snippet

pkg/server/app/notes_test.go:414–446  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

412}
413
414func 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
448func TestGetNotes_FTSSearch_ShortWord(t *testing.T) {
449 db := testutils.InitMemoryDB(t)

Callers

nothing calls this directly

Calls 7

InitMemoryDBFunction · 0.92
SetupUserDataFunction · 0.92
MustExecFunction · 0.92
NewMockFunction · 0.92
EqualFunction · 0.92
NewTestFunction · 0.85
GetNotesMethod · 0.80

Tested by

no test coverage detected