Update query in MarkResolved method to include 'manual_needed' status
- Modified the SQL query in the MarkResolved function to select torrents with both 'active' and 'manual_needed' statuses, enhancing the functionality of the method.
This commit is contained in:
@@ -79,7 +79,7 @@ func (s *Store) UpsertSeen(torrent model.Torrent, now time.Time) (State, error)
|
||||
}
|
||||
|
||||
func (s *Store) MarkResolved(activeIDs map[int64]bool, now time.Time) error {
|
||||
rows, err := s.db.Query(`SELECT ncore_id FROM torrents WHERE status = 'active'`)
|
||||
rows, err := s.db.Query(`SELECT ncore_id FROM torrents WHERE status IN ('active', 'manual_needed')`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
45
internal/store/store_test.go
Normal file
45
internal/store/store_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"ncore-hnr/internal/model"
|
||||
)
|
||||
|
||||
func TestMarkResolvedResolvesManualNeededTorrent(t *testing.T) {
|
||||
db, err := Open(t.TempDir() + "/state.sqlite")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
now := time.Date(2026, 5, 7, 1, 0, 0, 0, time.UTC)
|
||||
torrent := model.Torrent{ID: 123, Name: "The Black Dagger Brotherhood S01E01 720p"}
|
||||
if _, err := db.UpsertSeen(torrent, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.MarkManualNeeded(torrent.ID, now.Add(time.Hour)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
resolvedAt := now.Add(2 * time.Hour)
|
||||
if err := db.MarkResolved(map[int64]bool{}, resolvedAt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
status, err := db.Status()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(status.Torrents) != 1 {
|
||||
t.Fatalf("expected 1 tracked torrent, got %d", len(status.Torrents))
|
||||
}
|
||||
got := status.Torrents[0]
|
||||
if got.Status != "resolved" {
|
||||
t.Fatalf("expected status resolved, got %q", got.Status)
|
||||
}
|
||||
if got.LastResolvedAt != resolvedAt.Format(time.RFC3339) {
|
||||
t.Fatalf("expected last_resolved_at %q, got %q", resolvedAt.Format(time.RFC3339), got.LastResolvedAt)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user