Fix tests broken by tts

This commit is contained in:
Tim Van Baak 2025-02-07 06:53:42 -08:00
parent 9fa1fd99be
commit 8125275936
2 changed files with 6 additions and 4 deletions

View File

@ -193,13 +193,15 @@ func GetItem(db DB, source string, id string) (Item, error) {
} }
func GetAllActiveItems(db DB) ([]Item, error) { func GetAllActiveItems(db DB) ([]Item, error) {
now := int(time.Now().Unix()) // TODO pass this value in
return getItems(db, ` return getItems(db, `
select select
source, id, created, active, title, author, body, link, time, ttl, ttd, tts, json(action) source, id, created, active, title, author, body, link, time, ttl, ttd, tts, json(action)
from items from items
where active <> 0 where active <> 0
and (tts = 0 or created + tts < ?)
order by case when time = 0 then created else time end, id order by case when time = 0 then created else time end, id
`) `, now)
} }
func GetAllItems(db DB) ([]Item, error) { func GetAllItems(db DB) ([]Item, error) {
@ -220,7 +222,7 @@ func GetActiveItemsForSource(db DB, source string) ([]Item, error) {
where where
source = ? source = ?
and active <> 0 and active <> 0
and created + tts < ? and (tts = 0 or created + tts < ?)
order by case when time = 0 then created else time end, id order by case when time = 0 then created else time end, id
`, source, now) `, source, now)
} }
@ -246,7 +248,7 @@ func GetActiveItemsForChannel(db DB, channel string) ([]Item, error) {
where where
c.name = ? c.name = ?
and i.active <> 0 and i.active <> 0
and i.created + i.tts < ? and (i.tts = 0 or i.created + i.tts < ?)
order by case when i.time = 0 then i.created else i.time end, i.id order by case when i.time = 0 then i.created else i.time end, i.id
`, channel, now) `, channel, now)
} }

View File

@ -33,7 +33,7 @@ func TestAddItem(t *testing.T) {
if err := AddItems(db, []Item{ if err := AddItems(db, []Item{
{Source: "test", Id: "one", Active: true}, {Source: "test", Id: "one", Active: true},
{"test", "two", 0, true, "title", "author", "body", "link", 123456, 1, 2, 3, nil}, {"test", "two", 0, true, "title", "author", "body", "link", 123456, 1, 2, -3, nil},
}); err != nil { }); err != nil {
t.Fatalf("failed to add items: %v", err) t.Fatalf("failed to add items: %v", err)
} }