"""IT-SET-001 — immutable settings rejected via API."""

from __future__ import annotations

import pytest
from fastapi import HTTPException

from server.api.schemas import SettingUpdatePayload
from server.api.settings import set_setting

pytestmark = pytest.mark.integration


@pytest.mark.asyncio
async def test_put_api_key_rejected_as_immutable(db_session, test_admin, mock_request):
    with pytest.raises(HTTPException) as exc:
        await set_setting(
            "api_key",
            SettingUpdatePayload(value="hacked"),
            mock_request,
            test_admin["admin"],
            db_session,
        )
    assert exc.value.status_code == 403
    assert "immutable" in exc.value.detail.lower()
