aboutsummaryrefslogtreecommitdiffstats
path: root/models/item/item_test.go
blob: 2f31ac71d0cbbecf55a55a4e927dc22872bf4667 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
package item

import (
	"bytes"
	"fmt"
	"net/http"
	"net/http/httptest"
	"os"
	"path/filepath"
	"strings"
	"testing"
	"time"

	goose "github.com/advancedlogic/GoOse"

	"adammathes.com/neko/config"
	"adammathes.com/neko/models"
)

func setupTestDB(t *testing.T) {
	t.Helper()
	config.Config.DBFile = filepath.Join(t.TempDir(), "test.db")
	models.InitDB()
	t.Cleanup(func() {
		if models.DB != nil {
			models.DB.Close()
		}
	})
}

func createTestFeed(t *testing.T) int64 {
	t.Helper()
	res, err := models.DB.Exec("INSERT INTO feed(url, title) VALUES(?, ?)", "https://example.com/feed", "Test Feed")
	if err != nil {
		t.Fatal(err)
	}
	id, _ := res.LastInsertId()
	return id
}

func TestPrint(t *testing.T) {
	old := os.Stdout
	r, w, _ := os.Pipe()
	os.Stdout = w

	i := &Item{Id: 42, Title: "Test Title", ReadState: true}
	i.Print()

	w.Close()
	os.Stdout = old

	var buf bytes.Buffer
	buf.ReadFrom(r)
	output := buf.String()

	expected := "id: 42\ntitle: Test Title\nReadState: true\n"
	if output != expected {
		t.Errorf("Print() output mismatch:\ngot:  %q\nwant: %q", output, expected)
	}
}

func TestCleanHeaderImage(t *testing.T) {
	tests := []struct {
		name     string
		input    string
		expected string
	}{
		{"blank wp image", "https://s0.wp.com/i/blank.jpg", ""},
		{"normal image", "https://example.com/image.jpg", "https://example.com/image.jpg"},
		{"empty string", "", ""},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			i := &Item{HeaderImage: tt.input}
			i.CleanHeaderImage()
			if i.HeaderImage != tt.expected {
				t.Errorf("got %q, want %q", i.HeaderImage, tt.expected)
			}
		})
	}
}

func TestProxyURL(t *testing.T) {
	url := "https://example.com/image.jpg"
	result := proxyURL(url)
	if result == "" {
		t.Error("proxyURL should not return empty string")
	}
	if result[:7] != "/image/" {
		t.Errorf("proxyURL should start with '/image/', got %q", result[:7])
	}
}

func TestRewriteImages(t *testing.T) {
	input := `<html><head></head><body><img src="https://example.com/image.jpg"/></body></html>`
	result := rewriteImages(input)
	if result == "" {
		t.Error("rewriteImages should not return empty")
	}
	// The src should be rewritten to use the proxy
	if !bytes.Contains([]byte(result), []byte("/image/")) {
		t.Errorf("rewriteImages should contain proxy URL, got %q", result)
	}
}

func TestRewriteImagesNoImages(t *testing.T) {
	input := `<html><head></head><body><p>No images here</p></body></html>`
	result := rewriteImages(input)
	if result == "" {
		t.Error("rewriteImages should not return empty for input without images")
	}
}

func TestCreate(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i := &Item{
		Title:       "Test Item",
		Url:         "https://example.com/article",
		Description: "A test item",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	err := i.Create()
	if err != nil {
		t.Fatalf("Create() should not error: %v", err)
	}
	if i.Id == 0 {
		t.Error("Create() should set Id")
	}
}

func TestCreateDuplicateUrl(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i1 := &Item{
		Title:       "Item 1",
		Url:         "https://example.com/same-url",
		Description: "First",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i1.Create()

	i2 := &Item{
		Title:       "Item 2",
		Url:         "https://example.com/same-url",
		Description: "Duplicate",
		PublishDate: "2024-01-02 00:00:00",
		FeedId:      feedId,
	}
	err := i2.Create()
	if err == nil {
		t.Error("Create() with duplicate URL should error")
	}
}

func TestSave(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i := &Item{
		Title:       "Test Item",
		Url:         "https://example.com/article",
		Description: "A test item",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i.Create()

	i.ReadState = true
	i.Starred = true
	i.Save()

	// Verify via direct query
	var readState, starred bool
	err := models.DB.QueryRow("SELECT read_state, starred FROM item WHERE id=?", i.Id).Scan(&readState, &starred)
	if err != nil {
		t.Fatal(err)
	}
	if !readState {
		t.Error("ReadState should be true after Save")
	}
	if !starred {
		t.Error("Starred should be true after Save")
	}
}

func TestFullSave(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i := &Item{
		Title:       "Original Title",
		Url:         "https://example.com/article",
		Description: "Original desc",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i.Create()

	i.Title = "Updated Title"
	i.Description = "Updated desc"
	i.FullSave()

	// Verify via direct query
	var title, desc string
	err := models.DB.QueryRow("SELECT title, description FROM item WHERE id=?", i.Id).Scan(&title, &desc)
	if err != nil {
		t.Fatal(err)
	}
	if title != "Updated Title" {
		t.Errorf("Title should be 'Updated Title', got %q", title)
	}
	if desc != "Updated desc" {
		t.Errorf("Description should be 'Updated desc', got %q", desc)
	}
}

func TestFilterBasic(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	// Insert an item
	i := &Item{
		Title:       "Filterable Item",
		Url:         "https://example.com/filterable",
		Description: "A filterable item",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i.Create()

	// Filter with no constraints (except unread_only=false to not filter by read)
	items, err := Filter(0, 0, "", false, false, 0, "")
	if err != nil {
		t.Fatalf("Filter() should not error: %v", err)
	}
	if len(items) != 1 {
		t.Fatalf("Filter() should return 1 item, got %d", len(items))
	}
	if items[0].Title != "Filterable Item" {
		t.Errorf("Unexpected title: %q", items[0].Title)
	}
}

func TestFilterByFeedId(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i := &Item{
		Title:       "Item 1",
		Url:         "https://example.com/1",
		Description: "desc",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i.Create()

	// Filter by a non-matching feed id
	items, err := Filter(0, 999, "", false, false, 0, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 0 {
		t.Errorf("Filter by non-matching feed_id should return 0 items, got %d", len(items))
	}

	// Filter by matching feed id
	items, err = Filter(0, feedId, "", false, false, 0, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 1 {
		t.Errorf("Filter by matching feed_id should return 1 item, got %d", len(items))
	}
}

func TestFilterUnreadOnly(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i := &Item{
		Title:       "Unread Item",
		Url:         "https://example.com/unread",
		Description: "desc",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i.Create()

	// All items start unread (read_state=0)
	items, err := Filter(0, 0, "", true, false, 0, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 1 {
		t.Fatalf("Unread filter should return 1 item, got %d", len(items))
	}

	// Mark as read
	i.ReadState = true
	i.Save()

	items, err = Filter(0, 0, "", true, false, 0, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 0 {
		t.Errorf("Unread filter should return 0 items after marking read, got %d", len(items))
	}
}

func TestFilterStarredOnly(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i := &Item{
		Title:       "Starred Item",
		Url:         "https://example.com/starred",
		Description: "desc",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i.Create()

	// Not starred yet
	items, err := Filter(0, 0, "", false, true, 0, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 0 {
		t.Errorf("Starred filter should return 0 items initially, got %d", len(items))
	}

	// Star it
	i.Starred = true
	i.Save()

	items, err = Filter(0, 0, "", false, true, 0, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 1 {
		t.Errorf("Starred filter should return 1 item, got %d", len(items))
	}
}

func TestFilterByItemId(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i := &Item{
		Title:       "Specific Item",
		Url:         "https://example.com/specific",
		Description: "desc",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i.Create()

	items, err := Filter(0, 0, "", false, false, i.Id, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 1 {
		t.Fatalf("Filter by item_id should return 1 item, got %d", len(items))
	}
	if items[0].Id != i.Id {
		t.Errorf("Unexpected item id: %d", items[0].Id)
	}
}

func TestFilterByMaxId(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i1 := &Item{Title: "Item 1", Url: "https://example.com/1", Description: "d", PublishDate: "2024-01-01", FeedId: feedId}
	i1.Create()

	i2 := &Item{Title: "Item 2", Url: "https://example.com/2", Description: "d", PublishDate: "2024-01-02", FeedId: feedId}
	i2.Create()

	// max_id = i2.Id should only return items with id < i2.Id
	items, err := Filter(i2.Id, 0, "", false, false, 0, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 1 {
		t.Fatalf("MaxId filter should return 1 item, got %d", len(items))
	}
	if items[0].Id != i1.Id {
		t.Errorf("Expected item %d, got %d", i1.Id, items[0].Id)
	}
}

func TestFilterPolicy(t *testing.T) {
	p := filterPolicy()
	if p == nil {
		t.Fatal("filterPolicy should not return nil")
	}

	// Test that it strips disallowed tags
	unsafe := `<script>alert("xss")</script><p>safe</p>`
	result := p.Sanitize(unsafe)
	if bytes.Contains([]byte(result), []byte("<script>")) {
		t.Error("filterPolicy should strip script tags")
	}
	if !bytes.Contains([]byte(result), []byte("<p>safe</p>")) {
		t.Error("filterPolicy should allow p tags")
	}
}

func TestItemById(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i := &Item{
		Title:       "ById Item",
		Url:         "https://example.com/byid",
		Description: "desc",
		PublishDate: "2024-01-01 00:00:00",
		FeedId:      feedId,
	}
	i.Create()

	found := ItemById(i.Id)
	if found == nil {
		t.Fatal("ItemById should return an item")
	}
	if found.Title != "ById Item" {
		t.Errorf("Expected title 'ById Item', got %q", found.Title)
	}
}

func TestFilterByCategory(t *testing.T) {
	setupTestDB(t)

	// Create a feed with category
	res, err := models.DB.Exec("INSERT INTO feed(url, title, category) VALUES(?, ?, ?)",
		"https://tech.com/feed", "Tech Feed", "technology")
	if err != nil {
		t.Fatal(err)
	}
	feedId, _ := res.LastInsertId()

	// Create another feed with different category
	res2, err := models.DB.Exec("INSERT INTO feed(url, title, category) VALUES(?, ?, ?)",
		"https://news.com/feed", "News Feed", "news")
	if err != nil {
		t.Fatal(err)
	}
	feedId2, _ := res2.LastInsertId()

	i1 := &Item{Title: "Tech Article", Url: "https://tech.com/1", Description: "d", PublishDate: "2024-01-01", FeedId: feedId}
	i1.Create()
	i2 := &Item{Title: "News Article", Url: "https://news.com/1", Description: "d", PublishDate: "2024-01-01", FeedId: feedId2}
	i2.Create()

	// Filter by category "technology"
	items, err := Filter(0, 0, "technology", false, false, 0, "")
	if err != nil {
		t.Fatalf("Filter by category should not error: %v", err)
	}
	if len(items) != 1 {
		t.Fatalf("Filter by category should return 1 item, got %d", len(items))
	}
	if items[0].Title != "Tech Article" {
		t.Errorf("Expected 'Tech Article', got %q", items[0].Title)
	}
}

func TestFilterBySearch(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i1 := &Item{Title: "Golang Tutorial", Url: "https://example.com/go", Description: "Learn Go", PublishDate: "2024-01-01", FeedId: feedId}
	i1.Create()
	i2 := &Item{Title: "Python Guide", Url: "https://example.com/py", Description: "Learn Python", PublishDate: "2024-01-02", FeedId: feedId}
	i2.Create()

	// Search for "Golang"
	items, err := Filter(0, 0, "", false, false, 0, "Golang")
	if err != nil {
		t.Fatalf("Filter by search should not error: %v", err)
	}
	if len(items) != 1 {
		t.Fatalf("Search for 'Golang' should return 1 item, got %d", len(items))
	}
	if items[0].Title != "Golang Tutorial" {
		t.Errorf("Expected 'Golang Tutorial', got %q", items[0].Title)
	}
}

func TestFilterCombined(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	i1 := &Item{Title: "Item A", Url: "https://example.com/a", Description: "d", PublishDate: "2024-01-01", FeedId: feedId}
	i1.Create()
	i2 := &Item{Title: "Item B", Url: "https://example.com/b", Description: "d", PublishDate: "2024-01-02", FeedId: feedId}
	i2.Create()

	// Star item B and mark item A as read
	i2.Starred = true
	i2.Save()
	i1.ReadState = true
	i1.Save()

	// Filter: unread only + starred only — should get only starred unread
	items, err := Filter(0, 0, "", true, true, 0, "")
	if err != nil {
		t.Fatal(err)
	}
	if len(items) != 1 {
		t.Fatalf("Combined filter should return 1 item, got %d", len(items))
	}
}

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, `<html><body><article><h1>Test Title</h1><p>Full Article Content is here and it is long enough to be detected as content by GoOse.</p></article></body></html>`)
	}))
	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, `<html><body></body></html>`)
	}))
	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 := `<html><head></head><body><img src="https://example.com/image.jpg" srcset="https://example.com/big.jpg 2x"/></body></html>`
	result := rewriteImages(input)
	// srcset should be cleared
	_ = bytes.Contains([]byte(result), []byte("srcset"))
}

func TestRewriteImagesEmpty(t *testing.T) {
	result := rewriteImages("")
	_ = result
}

type mockExtractor struct {
	Article *goose.Article
	Err     error
}

func (m *mockExtractor) Extract(url string) (*goose.Article, error) {
	return m.Article, m.Err
}

func TestGetFullContentWithMock(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	oldExtractor := Extractor
	defer func() { Extractor = oldExtractor }()

	mock := &mockExtractor{
		Article: &goose.Article{
			CleanedText: "Mocked content",
			TopNode:     nil, // goose.TopNode is complex, simpler to mock article itself
		},
	}
	Extractor = mock

	i := &Item{Url: "http://mock", FeedId: feedId}
	i.Create()
	i.GetFullContent()

	// Since TopNode is nil, FullContent (sanitized HTML) won't be set,
	// but md (CleanedText) should be saved in DB.
	var md string
	err := models.DB.QueryRow("SELECT full_content FROM item WHERE id=?", i.Id).Scan(&md)
	if err != nil {
		t.Fatal(err)
	}
	if !strings.Contains(md, "Mocked content") {
		t.Errorf("Expected mocked content in DB, got %q", md)
	}
}

func TestRewriteImagesNoSrc(t *testing.T) {
	input := `<html><body><img alt="no src"/></body></html>`
	result := rewriteImages(input)
	if !strings.Contains(result, "alt=\"no src\"") {
		t.Errorf("Expected alt attribute to be preserved, got %q", result)
	}
}

func TestRewriteImagesSrcset(t *testing.T) {
	input := `<html><body><img srcset="img1.jpg 1x, img2.jpg 2x" src="img1.jpg"/></body></html>`
	result := rewriteImages(input)
	if !strings.Contains(result, "/image/") {
		t.Errorf("Expected srcset to be proxied, got %q", result)
	}
}

func TestItemSaveError(t *testing.T) {
	config.Config.DBFile = filepath.Join(t.TempDir(), "test_bad.db")
	models.InitDB()

	i := &Item{Id: 1}
	models.DB.Close()
	i.Save()
}

func TestItemFullSaveError(t *testing.T) {
	config.Config.DBFile = filepath.Join(t.TempDir(), "test_bad_2.db")
	models.InitDB()
	i := &Item{Id: 1}
	models.DB.Close()
	i.FullSave() // Should not panic
}
func TestPurge(t *testing.T) {
	setupTestDB(t)
	feedId := createTestFeed(t)

	// Create items with different dates and states
	now := time.Now()
	// Use explicit dates, ensure SQLite parses them correctly
	// Old date: 60 days ago
	oldDate := now.AddDate(0, 0, -60).Format("2006-01-02 15:04:05")
	// Very old date: 100 days ago
	veryOldDate := now.AddDate(0, 0, -100).Format("2006-01-02 15:04:05")

	items := []*Item{
		{Title: "Old Read", Url: "http://example.com/1", PublishDate: oldDate, FeedId: feedId, ReadState: true},
		{Title: "Old Unread", Url: "http://example.com/2", PublishDate: oldDate, FeedId: feedId, ReadState: false},
		{Title: "Old Starred", Url: "http://example.com/3", PublishDate: oldDate, FeedId: feedId, ReadState: true, Starred: true},
		{Title: "Very Old Read", Url: "http://example.com/4", PublishDate: veryOldDate, FeedId: feedId, ReadState: true},
	}

	for _, i := range items {
		err := i.Create()
		if err != nil {
			t.Fatal(err)
		}
	}

	// Purge read items older than 30 days
	affected, err := Purge(30, false)
	if err != nil {
		t.Fatal(err)
	}

	// Should have purged "Old Read" and "Very Old Read"
	if affected != 2 {
		t.Errorf("Expected 2 items purged, got %d", affected)
		// Debug logging to see what's left
		remaining, _ := Filter(0, 0, "", false, false, 0, "")
		for _, r := range remaining {
			t.Logf("Remaining: %s (%s) Read: %t Starred: %t", r.Title, r.PublishDate, r.ReadState, r.Starred)
		}
	}

	// Verify remaining items count
	remaining, _ := Filter(0, 0, "", false, false, 0, "")
	if len(remaining) != 2 {
		t.Errorf("Expected 2 items remaining, got %d", len(remaining))
	}

	// Purge all items older than 30 days (including unread)
	affected, err = Purge(30, true)
	if err != nil {
		t.Fatal(err)
	}

	// Should have purged "Old Unread"
	if affected != 1 {
		t.Errorf("Expected 1 item purged, got %d", affected)
	}

	//Verify "Old Starred" is still there
	remaining, _ = Filter(0, 0, "", false, false, 0, "")
	if len(remaining) != 1 || remaining[0].Title != "Old Starred" {
		t.Errorf("Expected only 'Old Starred' to remain, got %v", remaining)
	}
}