diff --git a/orchestration/abri_orchestrator.py b/orchestration/abri_orchestrator.py index 3238066f4..397bc9d77 100644 --- a/orchestration/abri_orchestrator.py +++ b/orchestration/abri_orchestrator.py @@ -233,7 +233,19 @@ class AbriOrchestrator: def amend_job( self, booking: ConfirmedSurveyBooking ) -> AmendJobOrchestrationResult: - raise NotImplementedError + job_no = self._deal_database.job_no_for_deal(booking.deal_id) + if job_no is None: + raise JobNoNotYetRecordedError(deal_id=booking.deal_id) + + return self._abri.amend_job( + AmendJobRequest( + job_no=job_no, + appointment_date=booking.confirmed_survey_date, + appointment_time=slot_for_confirmed_time( + booking.confirmed_survey_time + ), + ) + ) def log_job(self, booking: ConfirmedSurveyBooking) -> LogJobOrchestrationResult: descriptions = build_job_descriptions(booking.deal_name) diff --git a/scripts/smoke_test_tenant_contacts.py b/scripts/smoke_test_tenant_contacts.py index f9b55dc3b..8dedeedac 100644 --- a/scripts/smoke_test_tenant_contacts.py +++ b/scripts/smoke_test_tenant_contacts.py @@ -22,7 +22,7 @@ All tenant details below are fictional (Ofcom-reserved number ranges). import os from pathlib import Path -from typing import Any, List, cast +from typing import Any, List, Optional, cast from dotenv import dotenv_values from hubspot.client import Client # type: ignore[reportMissingTypeStubs] @@ -101,11 +101,14 @@ def _stubbed_abri_client() -> AbriClient: class _UnusedDealDatabase: - """Satisfies the gateway dependency; the tenant-data flow never writes it.""" + """Satisfies the gateway dependency; the tenant-data flow never touches it.""" def record_job_no(self, deal_id: str, job_no: str) -> None: raise AssertionError("tenant-data sync must not touch the deal database") + def job_no_for_deal(self, deal_id: str) -> Optional[str]: + raise AssertionError("tenant-data sync must not touch the deal database") + def _archive_contacts(sdk_client: Client) -> None: if not CONTACT_IDS_TO_ARCHIVE: diff --git a/tests/orchestration/test_abri_orchestrator_log_job.py b/tests/orchestration/test_abri_orchestrator_log_job.py index b91739c52..c47a7fcd2 100644 --- a/tests/orchestration/test_abri_orchestrator_log_job.py +++ b/tests/orchestration/test_abri_orchestrator_log_job.py @@ -3,7 +3,7 @@ import traceback import xml.etree.ElementTree as ET from datetime import date from pathlib import Path -from typing import List, Tuple +from typing import List, Optional, Tuple from unittest.mock import MagicMock, patch import pytest @@ -57,6 +57,16 @@ class FakeDealDatabase: def record_job_no(self, deal_id: str, job_no: str) -> None: self.recorded_job_nos.append((deal_id, job_no)) + def job_no_for_deal(self, deal_id: str) -> Optional[str]: + return next( + ( + job_no + for recorded_deal_id, job_no in self.recorded_job_nos + if recorded_deal_id == deal_id + ), + None, + ) + @pytest.fixture() def mock_session() -> MagicMock: diff --git a/tests/orchestration/test_abri_orchestrator_tenant_data_sync.py b/tests/orchestration/test_abri_orchestrator_tenant_data_sync.py index e45e48686..58b82dd82 100644 --- a/tests/orchestration/test_abri_orchestrator_tenant_data_sync.py +++ b/tests/orchestration/test_abri_orchestrator_tenant_data_sync.py @@ -2,6 +2,7 @@ import json import traceback import xml.etree.ElementTree as ET from pathlib import Path +from typing import Optional from unittest.mock import MagicMock, patch import pytest @@ -66,6 +67,9 @@ class FakeDealDatabase: def record_job_no(self, deal_id: str, job_no: str) -> None: raise AssertionError("tenant-data sync must not touch the deal database") + def job_no_for_deal(self, deal_id: str) -> Optional[str]: + raise AssertionError("tenant-data sync must not touch the deal database") + @pytest.fixture() def orchestrator(