Amend an Abri booking only on a change to a complete booking, never when logging 🟥

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-24 15:50:55 +00:00
parent 6e9f52a540
commit a39c008f36

View file

@ -227,14 +227,17 @@ def test_the_message_carries_the_deals_third_party_surveyor_identifier() -> None
assert message["third_party_surveyor_identifier"] == "THIRDPARTY"
def test_a_changed_confirmed_survey_date_builds_an_amend_job_message() -> None:
# Arrange
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(
project_code=ABRI_PROJECT_CODE,
confirmed_survey_date=datetime(2026, 6, 18, tzinfo=timezone.utc),
third_party_surveyor_identifier="THIRDPARTY",
)
new_deal = make_new_deal(
confirmed_survey_date="2026-06-24", confirmed_survey_time="14:30"
confirmed_survey_date="2026-06-24",
confirmed_survey_time="14:30",
third_party_surveyor_identifier="THIRDPARTY",
)
# Act
@ -252,6 +255,62 @@ def test_a_changed_confirmed_survey_date_builds_an_amend_job_message() -> None:
assert message["confirmed_survey_date"] == "2026-06-24"
def test_log_takes_precedence_over_amend_on_the_pair_completing_scrape() -> None:
# Arrange: the surveyor lands to complete the pair on a deal with no Job
# Number. The surveyor change would otherwise read as an amend, but the
# pair-completing scrape must log, not amend.
old_deal = make_old_deal(
project_code=ABRI_PROJECT_CODE,
confirmed_survey_date=datetime(2026, 6, 24, tzinfo=timezone.utc),
confirmed_survey_time="14:30",
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["flows"] == ["log_job"]
def test_a_date_change_on_an_incomplete_pair_does_not_amend() -> None:
# Arrange: the date moves while no surveyor is set — there is no complete
# booking to amend, so nothing fires until the pair completes.
old_deal = make_old_deal(
project_code=ABRI_PROJECT_CODE,
confirmed_survey_date=datetime(2026, 6, 18, tzinfo=timezone.utc),
third_party_surveyor_identifier=None,
)
new_deal = make_new_deal(
confirmed_survey_date="2026-06-24",
third_party_surveyor_identifier="",
)
# 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 None
def test_a_changed_surveyor_on_a_booked_deal_builds_an_amend_job_message() -> None:
# Arrange: booking exists; only the surveyor changes.
old_deal = make_old_deal(