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(