# retoor <retoor@molodetz.nl>

from datetime import datetime, timezone

from devplacepy.database import get_table
from devplacepy.utils import generate_uid
from devplacepy.services.messaging.persist import stamp_content_revision


def test_stamp_content_revision_sets_updated_at(local_db):
    uid = generate_uid()
    get_table("messages").insert(
        {
            "uid": uid,
            "sender_uid": "s1",
            "receiver_uid": "r1",
            "content": "hello",
            "read": False,
            "created_at": datetime.now(timezone.utc).isoformat(),
            "updated_at": None,
        }
    )
    row = stamp_content_revision(uid)
    assert row is not None
    assert row["updated_at"]
    stored = get_table("messages").find_one(uid=uid)
    assert stored["updated_at"] == row["updated_at"]
    assert stored["content"] == "hello"
