diff --git a/tests/orchestration/test_abri_log_job_orchestrator.py b/tests/orchestration/test_abri_log_job_orchestrator.py index afdc02f39..2cfb265f8 100644 --- a/tests/orchestration/test_abri_log_job_orchestrator.py +++ b/tests/orchestration/test_abri_log_job_orchestrator.py @@ -5,6 +5,7 @@ from typing import List, Tuple from unittest.mock import MagicMock, patch import pytest +from hubspot.crm.deals import SimplePublicObjectInput # type: ignore[reportMissingTypeStubs] from domain.abri.models import PlaceRef from infrastructure.abri.abri_client import AbriClient @@ -13,6 +14,7 @@ from infrastructure.hubspot.deal_properties_client import HubspotDealPropertiesC from orchestration.abri_log_job_orchestrator import ( AbriLogJobOrchestrator, ConfirmedSurveyBooking, + LogJobSummary, ) FIXTURE_DIR = Path(__file__).parents[1] / "abri" @@ -119,3 +121,31 @@ def test_run_sends_a_logjob_envelope_built_from_the_deals_fields( "resource": "NAULKH", "resource_group": "Surveyors", } + + +# --- happy path: the returned job_no lands in HubSpot, then the database --- + + +def test_run_writes_the_job_no_to_the_hubspot_deal_and_then_the_database( + orchestrator: AbriLogJobOrchestrator, + mock_session: MagicMock, + sdk_client: MagicMock, + deal_database: FakeDealDatabase, +) -> None: + # Arrange + mock_session.post.return_value.content = _load_fixture( + "abri_relay_logjob_success_response.xml" + ) + + # Act + result = orchestrator.run(BOOKING) + + # Assert + assert result == LogJobSummary(deal_id=DEAL_ID, job_no="AD0226519") + sdk_client.crm.deals.basic_api.update.assert_called_once_with( + DEAL_ID, + simple_public_object_input=SimplePublicObjectInput( + properties={"client_booking_reference": "AD0226519"} + ), + ) + assert deal_database.recorded_job_nos == [(DEAL_ID, "AD0226519")]