"""Tests for auth service."""

import hashlib

from src.services.auth_service import hash_api_key


class TestHashApiKey:
    """Tests for hash_api_key function."""

    def test_hash_api_key_returns_sha256(self) -> None:
        """Test that hash_api_key returns correct SHA-256 hash."""
        test_key = "test_api_key_12345"
        expected = hashlib.sha256(test_key.encode("utf-8")).hexdigest()

        result = hash_api_key(test_key)

        assert result == expected
        assert len(result) == 64  # SHA-256 produces 64 hex chars

    def test_hash_api_key_is_deterministic(self) -> None:
        """Test that same key always produces same hash."""
        test_key = "my_secret_key"

        hash1 = hash_api_key(test_key)
        hash2 = hash_api_key(test_key)

        assert hash1 == hash2

    def test_hash_api_key_different_keys_different_hashes(self) -> None:
        """Test that different keys produce different hashes."""
        key1 = "key_one"
        key2 = "key_two"

        hash1 = hash_api_key(key1)
        hash2 = hash_api_key(key2)

        assert hash1 != hash2

    def test_hash_api_key_handles_special_characters(self) -> None:
        """Test that hash handles special characters."""
        test_key = "key-with_special.chars!@#$%^&*()"

        result = hash_api_key(test_key)

        assert len(result) == 64
        assert all(c in "0123456789abcdef" for c in result)
