import hashlib

from app.utils import compute_sha256, generate_short_id


def test_sha256_known_bytes():
    data = b"hello world"
    expected = hashlib.sha256(data).hexdigest()
    assert compute_sha256(data) == expected


def test_sha256_empty_bytes():
    data = b""
    expected = hashlib.sha256(data).hexdigest()
    assert compute_sha256(data) == expected


def test_sha256_returns_64_char_hex():
    result = compute_sha256(b"test data")
    assert len(result) == 64
    assert all(c in "0123456789abcdef" for c in result)


def test_generate_short_id_length():
    assert len(generate_short_id()) == 8


def test_generate_short_id_charset():
    result = generate_short_id()
    assert all(
        c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for c in result
    )


def test_generate_short_id_randomness():
    assert generate_short_id() != generate_short_id()


def test_generate_short_id_importable():
    from app.utils import generate_short_id as fn

    assert callable(fn)
