"""Tests for handle-error handler.""" import pytest from pytest_mock import MockerFixture from src.index import handler def test_handler_patches_job_failed(mocker: MockerFixture) -> None: mock_patch = mocker.patch("src.index.patch_transfer_job") result = handler({"job_id": 42, "error": {"Cause": "boom"}}, object()) assert result == {"statusCode": 200} mock_patch.assert_called_once_with(42, {"status": "FAILED", "failure_reason": "boom"}) def test_handler_raises_on_missing_job_id() -> None: with pytest.raises(KeyError): handler({}, object()) def test_handler_raises_on_missing_error() -> None: with pytest.raises(ValueError, match="event\\['error'\\] must be an object"): handler({"job_id": 42}, object()) def test_handler_uses_error_name_when_cause_missing(mocker: MockerFixture) -> None: mock_patch = mocker.patch("src.index.patch_transfer_job") handler({"job_id": 42, "error": {"Error": "States.TaskFailed"}}, object()) mock_patch.assert_called_once_with( 42, {"status": "FAILED", "failure_reason": "States.TaskFailed"}, ) def test_handler_raises_on_invalid_job_id() -> None: with pytest.raises(ValueError, match="must be an integer"): handler({"job_id": "not-an-int", "error": {"Cause": "boom"}}, object())