From 9921d545efcee4db18deaf3990c8f542446d6f20 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Fri, 24 Jul 2026 15:52:09 +0000 Subject: [PATCH] =?UTF-8?q?Carry=20the=20deal's=20client=5Fbooking=5Frefer?= =?UTF-8?q?ence=20into=20the=20Abri=20message=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- etl/hubspot/tests/test_abri_flow_triggers.py | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/etl/hubspot/tests/test_abri_flow_triggers.py b/etl/hubspot/tests/test_abri_flow_triggers.py index d8bbfb668..77aa04daf 100644 --- a/etl/hubspot/tests/test_abri_flow_triggers.py +++ b/etl/hubspot/tests/test_abri_flow_triggers.py @@ -227,6 +227,64 @@ def test_the_message_carries_the_deals_third_party_surveyor_identifier() -> None assert message["third_party_surveyor_identifier"] == "THIRDPARTY" +def test_the_message_carries_the_deals_client_booking_reference() -> None: + # Arrange: an amend on a deal that already carries a Job Number; the + # consumer reads the reference off the message to decide the job exists. + old_deal = make_old_deal( + project_code=ABRI_PROJECT_CODE, + confirmed_survey_date=datetime(2026, 6, 18, tzinfo=timezone.utc), + third_party_surveyor_identifier="THIRDPARTY", + client_booking_reference="AD0226519", + ) + new_deal = make_new_deal( + confirmed_survey_date="2026-06-24", + confirmed_survey_time="14:30", + third_party_surveyor_identifier="THIRDPARTY", + client_booking_reference="AD0226519", + ) + + # Act + message = HubspotDealDiffer.check_abri_triggers_and_construct_message( + hubspot_deal_id=DEAL_ID, + new_deal=new_deal, + new_project=None, + new_listing=LISTING, + old_deal=old_deal, + ) + + # Assert + assert message is not None + assert message["flows"] == ["amend_job"] + assert message["client_booking_reference"] == "AD0226519" + + +def test_the_message_omits_the_client_booking_reference_when_the_deal_has_none() -> None: + # Arrange: a pair-completing log on a deal with no Job Number yet. + old_deal = make_old_deal( + project_code=ABRI_PROJECT_CODE, + confirmed_survey_date=None, + third_party_surveyor_identifier=None, + ) + new_deal = make_new_deal( + confirmed_survey_date="2026-06-24", + confirmed_survey_time="14:30", + third_party_surveyor_identifier="THIRDPARTY", + ) + + # Act + message = HubspotDealDiffer.check_abri_triggers_and_construct_message( + hubspot_deal_id=DEAL_ID, + new_deal=new_deal, + new_project=None, + new_listing=LISTING, + old_deal=old_deal, + ) + + # Assert + assert message is not None + assert message["client_booking_reference"] is None + + def test_a_changed_survey_date_on_a_complete_booking_builds_an_amend_job_message() -> None: # Arrange: a complete booking (date + surveyor) whose date moves. old_deal = make_old_deal(