mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
handle all plans having null cost 🟩
This commit is contained in:
parent
0e279b15ce
commit
cb55338f39
1 changed files with 27 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from datetime import datetime
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
import pytest
|
||||
|
||||
from backend.app.domain.classes.plan import Plan
|
||||
|
|
@ -16,7 +16,7 @@ def created_at_datetime() -> datetime:
|
|||
|
||||
|
||||
def make_plan_record(
|
||||
created_at: datetime, default: bool, cost_of_works: float = 500.0
|
||||
created_at: datetime, default: bool, cost_of_works: Optional[float] = 500.0
|
||||
) -> PlanRecord:
|
||||
return PlanRecord(
|
||||
property_id=1,
|
||||
|
|
@ -43,7 +43,10 @@ def make_scenario(name: str, created_at: datetime, is_default: bool) -> Scenario
|
|||
|
||||
|
||||
def make_plan(
|
||||
created_at: datetime, default: bool, cost_of_works: float = 500.0, name: str = ""
|
||||
created_at: datetime,
|
||||
default: bool,
|
||||
cost_of_works: Optional[float] = 500.0,
|
||||
name: str = "",
|
||||
) -> Plan:
|
||||
scenario = make_scenario(name, created_at, default)
|
||||
plan_id = 1 if default else 2
|
||||
|
|
@ -113,3 +116,24 @@ def test_all_plans_zero_cost__highest_priority_returned(
|
|||
|
||||
# assert
|
||||
assert actual_default_plan.id == expected_default_plan_id
|
||||
|
||||
|
||||
def test_all_plans_null_cost__highest_priority_returned(
|
||||
created_at_datetime: datetime,
|
||||
) -> None:
|
||||
# arrange
|
||||
epc_c_plan = make_plan(created_at_datetime, True, cost_of_works=None, name="EPC C")
|
||||
minor_works_plan = make_plan(
|
||||
created_at_datetime, False, cost_of_works=None, name="EPC C - Minor Works"
|
||||
)
|
||||
scenario_priority_order: List[int] = [4, 3]
|
||||
expected_default_plan_id = 2
|
||||
|
||||
# act
|
||||
actual_default_plan = choose_cheapest_relevant_plan(
|
||||
plans=[epc_c_plan, minor_works_plan],
|
||||
scenario_priority_order=scenario_priority_order,
|
||||
)
|
||||
|
||||
# assert
|
||||
assert actual_default_plan.id == expected_default_plan_id
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue