# retoor <retoor@molodetz.nl>

from devplacepy.services.devrant import serializers


def _rant(author):
    return serializers.serialize_rant(
        {
            "id": 1,
            "uid": "post-1",
            "user_uid": "u1",
            "content": "hello",
            "created_at": "2026-06-20T00:00:00+00:00",
        },
        authors={"u1": author},
        comment_counts={},
        user_scores={},
        my_votes={},
    )


def test_rant_avatar_uses_seed_when_present():
    rant = _rant({"id": 7, "username": "neo", "avatar_seed": "seed-abc"})
    assert rant["user_avatar"]["i"] == "u/seed-abc.png"
    assert rant["user_avatar_lg"]["i"] == "u/seed-abc.png"


def test_rant_avatar_falls_back_to_username():
    rant = _rant({"id": 7, "username": "neo"})
    assert rant["user_avatar"]["i"] == "u/neo.png"


def test_comment_avatar_uses_seed_when_present():
    comment = serializers.serialize_comment(
        {
            "id": 3,
            "uid": "c1",
            "user_uid": "u1",
            "content": "reply",
            "created_at": "2026-06-20T00:00:00+00:00",
        },
        rant_id=1,
        authors={"u1": {"id": 7, "username": "neo", "avatar_seed": "seed-abc"}},
        user_scores={},
        my_votes={},
        score_map={},
    )
    assert comment["user_avatar"]["i"] == "u/seed-abc.png"
