from etl.hubspot.hubspotDataTodB import HubspotDataToDb
from backend.app.db.models.hubspot_deal_data import HubspotDealData


def _make_instance() -> HubspotDataToDb:
    return HubspotDataToDb.__new__(HubspotDataToDb)


def test_update_existing_deal__designer_cleared_to_none__overwrites_existing() -> None:
    existing = HubspotDealData(deal_id="MOCK_DEAL_ID", designer="Old Designer")
    deal_data = {"designer_user": None}

    _make_instance()._update_existing_deal(
        existing=existing,
        deal_data=deal_data,
        listing=None,
        company=None,
    )

    assert existing.designer is None


def test_update_existing_deal__designer_set__overwrites_existing() -> None:
    existing = HubspotDealData(deal_id="MOCK_DEAL_ID", designer="Old Designer")
    deal_data = {"designer_user": "New Designer"}

    _make_instance()._update_existing_deal(
        existing=existing,
        deal_data=deal_data,
        listing=None,
        company=None,
    )

    assert existing.designer == "New Designer"
