Abri survey creation trigger recognises deals by their associated Abri project id 🟥

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-02 16:27:05 +00:00
parent 592173e1e5
commit cc682e3e74
2 changed files with 45 additions and 3 deletions

View file

@ -1,6 +1,7 @@
from typing import Dict, List, Optional
from backend.app.db.models.hubspot_deal_data import HubspotDealData
from etl.hubspot.project_data import ProjectData
from etl.hubspot.utils import parse_hs_bool, parse_hs_date
@ -12,6 +13,7 @@ class HubspotDealDiffer:
]
RETROFIT_DESIGN_COMPLETE = "uploaded"
LODGEMENT_COMPLETE: List[str] = ["lodgement complete", "measures lodged"]
ABRI_CONDITION_ASSOCIATED_PROJECT_ID = "123456"
ABRI_CONDITION_PROJECT_CODE = "Abri Condition"
@staticmethod
@ -173,9 +175,11 @@ class HubspotDealDiffer:
@staticmethod
def check_for_abri_survey_creation(
new_deal: Dict[str, str], old_deal: HubspotDealData
new_deal: Dict[str, str],
new_project: Optional[ProjectData],
old_deal: HubspotDealData,
) -> bool:
if not HubspotDealDiffer._is_abri_condition_deal(new_deal):
if not HubspotDealDiffer._is_abri_condition_deal(new_deal, new_project):
return False
if old_deal.confirmed_survey_date is not None:
@ -184,7 +188,9 @@ class HubspotDealDiffer:
return parse_hs_date(new_deal.get("confirmed_survey_date")) is not None
@staticmethod
def _is_abri_condition_deal(new_deal: Dict[str, str]) -> bool:
def _is_abri_condition_deal(
new_deal: Dict[str, str], new_project: Optional[ProjectData]
) -> bool:
new_project_code = (new_deal.get("project_code") or "").lower()
return new_project_code == HubspotDealDiffer.ABRI_CONDITION_PROJECT_CODE.lower()

View file

@ -6,6 +6,7 @@ import pytest
from backend.app.db.models.hubspot_deal_data import HubspotDealData
from etl.hubspot.hubspot_deal_differ import HubspotDealDiffer
from etl.hubspot.project_data import ProjectData
BASE_TIME = datetime(2025, 12, 1, 12, 0, 0)
@ -366,6 +367,7 @@ def test_abri_survey_creation__date_first_set_on_abri_deal__returns_true() -> No
# Act
result = HubspotDealDiffer.check_for_abri_survey_creation(
new_deal=new_deal,
new_project=None,
old_deal=old_deal,
)
@ -391,6 +393,7 @@ def test_abri_survey_creation__date_already_set__returns_false() -> None:
# Act
result = HubspotDealDiffer.check_for_abri_survey_creation(
new_deal=new_deal,
new_project=None,
old_deal=old_deal,
)
@ -416,6 +419,7 @@ def test_abri_survey_creation__non_abri_project_code__returns_false() -> None:
# Act
result = HubspotDealDiffer.check_for_abri_survey_creation(
new_deal=new_deal,
new_project=None,
old_deal=old_deal,
)
@ -441,6 +445,7 @@ def test_abri_survey_creation__project_code_cased_differently__returns_true() ->
# Act
result = HubspotDealDiffer.check_for_abri_survey_creation(
new_deal=new_deal,
new_project=None,
old_deal=old_deal,
)
@ -476,6 +481,7 @@ def test_abri_survey_creation__no_parseable_new_date__returns_false(
# Act
result = HubspotDealDiffer.check_for_abri_survey_creation(
new_deal=new_deal,
new_project=None,
old_deal=old_deal,
)
@ -483,6 +489,36 @@ def test_abri_survey_creation__no_parseable_new_date__returns_false(
assert result is False
def test_abri_survey_creation__associated_abri_project_id__returns_true() -> None:
deal_id = uuid.uuid4()
# Arrange
old_deal = make_old_deal(
id=deal_id,
project_code="Southern Retrofit",
confirmed_survey_date=None,
)
new_deal = make_new_deal(
deal_id,
project_code="Southern Retrofit",
confirmed_survey_date="2026-07-15",
)
new_project = ProjectData(
project_id=HubspotDealDiffer.ABRI_CONDITION_ASSOCIATED_PROJECT_ID,
name="Abri Condition",
)
# Act
result = HubspotDealDiffer.check_for_abri_survey_creation(
new_deal=new_deal,
new_project=new_project,
old_deal=old_deal,
)
# Assert
assert result is True
# =======================
# DB UPDATE TRIGGER TESTS
# =======================