package ingest import ( "strings" "testing" ) func TestHTMLToText(t *testing.T) { in := `

Hello

` + `` + `

A & B 'quoted'

` out := htmlToText(in) if strings.Contains(out, "evil()") || strings.Contains(out, ".x{}") { t.Fatalf("script/style not stripped: %q", out) } for _, want := range []string{"Hello", "A & B", "'quoted'"} { if !strings.Contains(out, want) { t.Fatalf("missing %q in %q", want, out) } } } func TestKarakeepToResult(t *testing.T) { title := "My Link" k := &KarakeepIngester{Version: "test"} b := kaBookmark{ ID: "bm1", CreatedAt: "2026-01-02T03:04:05Z", ModifiedAt: "2026-01-02T03:04:05Z", Title: &title, Tags: []kaTag{{Name: "zigbee"}}, Content: kaContent{Type: "link", URL: "https://example.com/a", Description: "short desc"}, } r := k.toResult(b) if r == nil { t.Fatal("nil result") } if r.SourceID != "karakeep" || r.Title != "My Link" || r.SourcePath != "https://example.com/a" { t.Fatalf("unexpected mapping: %+v", r) } // No asset and no inline text -> content falls back to description. if r.Content != "short desc" { t.Fatalf("content=%q, want description fallback", r.Content) } if r.Fingerprint == "" || r.ContentHash == "" { t.Fatal("fingerprint/content hash must be set") } } func TestKarakeepUnconfigured(t *testing.T) { k := &KarakeepIngester{Version: "test"} // no BaseURL/APIKey got, err := k.IngestAll() if err != nil || got != nil { t.Fatalf("unconfigured ingester should no-op, got %v %v", got, err) } }