From de96851d8eb0a0b45d7bf0cee67339fea54349f0 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Thu, 12 Feb 2026 21:35:46 -0800 Subject: wip: tui updates (buggy) --- models/item/item.go | 5 ++++- models/item/item_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) (limited to 'models/item') diff --git a/models/item/item.go b/models/item/item.go index 9639595..571e942 100644 --- a/models/item/item.go +++ b/models/item/item.go @@ -83,7 +83,10 @@ func filterPolicy() *bluemonday.Policy { } func ItemById(id int64) *Item { - items, _ := Filter(0, 0, "", false, false, id, "") + items, err := Filter(0, 0, "", false, false, id, "") + if err != nil || len(items) == 0 { + return nil + } return items[0] } diff --git a/models/item/item_test.go b/models/item/item_test.go index ef81c76..cbd0ca0 100644 --- a/models/item/item_test.go +++ b/models/item/item_test.go @@ -3,7 +3,11 @@ package item import ( "bytes" "fmt" + "net/http" + "net/http/httptest" "os" + "path/filepath" + "strings" "testing" "adammathes.com/neko/config" @@ -12,7 +16,7 @@ import ( func setupTestDB(t *testing.T) { t.Helper() - config.Config.DBFile = ":memory:" + config.Config.DBFile = filepath.Join(t.TempDir(), "test.db") models.InitDB() t.Cleanup(func() { if models.DB != nil { @@ -46,7 +50,7 @@ func TestPrint(t *testing.T) { buf.ReadFrom(r) output := buf.String() - expected := fmt.Sprintf("id: 42\ntitle: Test Title\nReadState: true\n") + expected := "id: 42\ntitle: Test Title\nReadState: true\n" if output != expected { t.Errorf("Print() output mismatch:\ngot: %q\nwant: %q", output, expected) } @@ -513,6 +517,56 @@ func TestFilterCombined(t *testing.T) { } } +func TestGetFullContent(t *testing.T) { + setupTestDB(t) + feedId := createTestFeed(t) + + // Mock server to provide article content + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, `

Test Title

Full Article Content is here and it is long enough to be detected as content by GoOse.

`) + })) + defer ts.Close() + + i := &Item{ + Title: "Test Item", + Url: ts.URL, + FeedId: feedId, + } + i.Create() + + i.GetFullContent() + + // Verify content was fetched and saved + if !strings.Contains(i.FullContent, "Full Article Content") { + t.Errorf("Expected full content to be fetched, got %q", i.FullContent) + } + + var fullContent string + err := models.DB.QueryRow("SELECT full_content FROM item WHERE id=?", i.Id).Scan(&fullContent) + if err != nil { + t.Fatal(err) + } + // The DB uses md which is from article.CleanedText + if !strings.Contains(fullContent, "Full Article Content") { + t.Errorf("Full content (markdown) should be saved in DB, got %q", fullContent) + } +} + +func TestGetFullContentEmpty(t *testing.T) { + setupTestDB(t) + // Provide HTML without an article or clear content + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, ``) + })) + defer ts.Close() + + i := &Item{Url: ts.URL} + i.GetFullContent() + if i.FullContent != "" { + t.Errorf("Expected empty content for empty HTML, got %q", i.FullContent) + } +} + func TestRewriteImagesWithSrcset(t *testing.T) { input := `` result := rewriteImages(input) -- cgit v1.2.3