# tests/test_state.py
import state


def test_posts_seen_roundtrip(tmp_path):
    con = state.connect(tmp_path / "s.db")
    assert state.was_seen_post(con, "tg:a:1") is False
    state.mark_posts_seen(con, ["tg:a:1", "tg:a:2"])
    assert state.was_seen_post(con, "tg:a:1") is True
    assert state.was_seen_post(con, "tg:a:3") is False


def test_new_entries_dedup(tmp_path):
    con = state.connect(tmp_path / "s.db")
    recs = [{"link": "http://x/1", "title": "A"}, {"link": "http://x/2", "title": "B"}]
    first = state.new_entries(con, recs)
    assert {r["link"] for r in first} == {"http://x/1", "http://x/2"}
    again = state.new_entries(con, recs + [{"link": "http://x/3", "title": "C"}])
    assert {r["link"] for r in again} == {"http://x/3"}
