Model/tests/domain/abri/test_abandonment.py
Daniel Roth 84d0e1e0d5 Date an abandonment to the deal's own dates, not now() 🟩
date_abandoned now resolves to the third failed attempt's confirmed
survey date, falling back to its last submission date, rather than the
processing date. This dates the OpenHousing cancellation to when the
job actually lapsed even if the trigger message lags or redelivers.

- domain: abandonment_date() encodes the confirmed-survey -> last-
  submission fallback
- DealAbandonment carries both dates; abandon_job raises
  AbandonmentDateUnknownError when a deal has neither
- last_submission_date now flows through the trigger message and request
- the injected clock is dropped: nothing reads now() any more

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 08:51:39 +00:00

36 lines
990 B
Python

from datetime import date
from typing import Optional
import pytest
from domain.abri.abandonment import abandon_reason_for_outcome, abandonment_date
from domain.abri.models import AbandonReason
CONFIRMED = date(2026, 6, 24)
SUBMITTED = date(2026, 7, 1)
def test_the_confirmed_survey_date_dates_the_abandonment() -> None:
assert abandonment_date(CONFIRMED, SUBMITTED) == CONFIRMED
def test_the_last_submission_date_stands_in_without_a_confirmed_survey_date() -> None:
assert abandonment_date(None, SUBMITTED) == SUBMITTED
def test_neither_date_leaves_the_abandonment_undated() -> None:
assert abandonment_date(None, None) is None
@pytest.mark.parametrize(
"outcome",
["no answer", "cancelled", "no show", "tenant refusal", "not viable", None],
)
def test_every_outcome_currently_maps_to_the_carded_reason(
outcome: Optional[str],
) -> None:
# Act
reason = abandon_reason_for_outcome(outcome)
# Assert
assert reason == AbandonReason.CARDED