|
|
@@ -4,7 +4,7 @@ from types import SimpleNamespace
|
|
|
from zoneinfo import ZoneInfo
|
|
|
|
|
|
from room_cal.discount import DiscountData, DiscountType
|
|
|
-from room_cal.rules.discount.same_day import RULE_NAME, _same_day_dates, run
|
|
|
+from room_cal.rules.discount.same_day import RULE_NAME, SURCHARGE_PERCENT, _same_day_dates, run
|
|
|
|
|
|
_TZ = ZoneInfo('America/Los_Angeles')
|
|
|
|
|
|
@@ -49,11 +49,18 @@ class TestSameDayDates:
|
|
|
class TestRun:
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
- async def test_empty_input_returns_empty(self, monkeypatch):
|
|
|
- assert await run(date(2026, 1, 1), date(2026, 1, 1), {}) == {}
|
|
|
+ async def test_empty_input_adds_surcharge_dates(self, monkeypatch):
|
|
|
+ today = date(2026, 1, 1)
|
|
|
+ now = datetime(2026, 1, 1, 10, 0, tzinfo=_TZ) # before checkin_hour -> same_day = {today}
|
|
|
+ _stub_config(monkeypatch)
|
|
|
+ _stub_now(monkeypatch, now)
|
|
|
+
|
|
|
+ result = await run(today, today, {})
|
|
|
+
|
|
|
+ assert result == {today: DiscountData(type=DiscountType.PERCENT, value=SURCHARGE_PERCENT)}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
- async def test_strips_same_day_dates_morning(self, monkeypatch):
|
|
|
+ async def test_overrides_same_day_dates_morning(self, monkeypatch):
|
|
|
today = date(2026, 7, 10)
|
|
|
now = datetime(2026, 7, 10, 10, 0, tzinfo=_TZ) # before checkin_hour -> same_day = {today}
|
|
|
_stub_config(monkeypatch)
|
|
|
@@ -66,12 +73,12 @@ class TestRun:
|
|
|
|
|
|
result = await run(today, today + timedelta(days=2), data)
|
|
|
|
|
|
- assert today not in result
|
|
|
- assert today + timedelta(days=1) in result # tomorrow is NOT same-day in the morning window
|
|
|
- assert today + timedelta(days=2) in result
|
|
|
+ assert result[today] == DiscountData(type=DiscountType.PERCENT, value=SURCHARGE_PERCENT)
|
|
|
+ assert result[today + timedelta(days=1)].value == 30 # tomorrow is NOT same-day in the morning window
|
|
|
+ assert result[today + timedelta(days=2)].value == 20
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
- async def test_strips_same_day_dates_afternoon(self, monkeypatch):
|
|
|
+ async def test_overrides_same_day_dates_afternoon(self, monkeypatch):
|
|
|
today = date(2026, 7, 10)
|
|
|
now = datetime(2026, 7, 10, 16, 0, tzinfo=_TZ) # after checkin_hour -> same_day = {today, +1}
|
|
|
_stub_config(monkeypatch)
|
|
|
@@ -84,11 +91,22 @@ class TestRun:
|
|
|
|
|
|
result = await run(today, today + timedelta(days=2), data)
|
|
|
|
|
|
- assert today not in result
|
|
|
- assert today + timedelta(days=1) not in result
|
|
|
- assert today + timedelta(days=2) in result
|
|
|
+ assert result[today] == DiscountData(type=DiscountType.PERCENT, value=SURCHARGE_PERCENT)
|
|
|
+ assert result[today + timedelta(days=1)] == DiscountData(type=DiscountType.PERCENT, value=SURCHARGE_PERCENT)
|
|
|
assert result[today + timedelta(days=2)].value == 20
|
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
+ async def test_same_day_outside_range_not_added(self, monkeypatch):
|
|
|
+ # start_date/end_date excludes today -> the surcharge must not be written outside the window
|
|
|
+ today = date(2026, 7, 10)
|
|
|
+ now = datetime(2026, 7, 10, 10, 0, tzinfo=_TZ)
|
|
|
+ _stub_config(monkeypatch)
|
|
|
+ _stub_now(monkeypatch, now)
|
|
|
+
|
|
|
+ result = await run(today + timedelta(days=1), today + timedelta(days=5), {})
|
|
|
+
|
|
|
+ assert today not in result
|
|
|
+
|
|
|
@pytest.mark.asyncio
|
|
|
async def test_untouched_dates_pass_through_unchanged(self, monkeypatch):
|
|
|
today = date(2026, 7, 10)
|