diff --git a/lago_python_client/models/fixed_charge.py b/lago_python_client/models/fixed_charge.py index 72955d7..d1dfa37 100644 --- a/lago_python_client/models/fixed_charge.py +++ b/lago_python_client/models/fixed_charge.py @@ -52,7 +52,7 @@ class FixedChargePropertiesResponse(BaseResponseModel): class FixedChargeResponse(BaseResponseModel): lago_id: str lago_add_on_id: str - invoice_display_name: str + invoice_display_name: Optional[str] add_on_code: str created_at: str code: Optional[str] diff --git a/tests/test_plan_client.py b/tests/test_plan_client.py index 3425dad..4de9a62 100644 --- a/tests/test_plan_client.py +++ b/tests/test_plan_client.py @@ -1,3 +1,4 @@ +import json import os import pytest @@ -290,6 +291,26 @@ def test_valid_find_plan_request(httpx_mock: HTTPXMock): assert response.minimum_commitment.amount_cents == 1000 +def test_valid_find_plan_request_with_fixed_charge_without_invoice_display_name(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + code = "plan_code" + plan_body = json.loads(mock_response()) + fixed_charge = json.loads(mock_plan_fixed_charge_response())["fixed_charge"] + fixed_charge["invoice_display_name"] = None + plan_body["plan"]["fixed_charges"] = [fixed_charge] + + httpx_mock.add_response( + method="GET", + url="https://api.getlago.com/api/v1/plans/" + code, + json=plan_body, + ) + response = client.plans.find(code) + + assert response.invoice_display_name == "test plan 1" + assert response.fixed_charges.__root__[0].lago_id == "fc901a90-1a90-1a90-1a90-1a901a901a90" + assert response.fixed_charges.__root__[0].invoice_display_name is None + + def test_invalid_find_plan_request(httpx_mock: HTTPXMock): client = Client(api_key="invalid") code = "invalid" @@ -643,6 +664,24 @@ def test_valid_find_fixed_charge_request(httpx_mock: HTTPXMock): assert response.properties.amount == "500" +def test_valid_find_fixed_charge_request_without_invoice_display_name(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + plan_code = "plan_code" + fixed_charge_code = "fixed_setup" + body = json.loads(mock_plan_fixed_charge_response()) + body["fixed_charge"]["invoice_display_name"] = None + + httpx_mock.add_response( + method="GET", + url="https://api.getlago.com/api/v1/plans/" + plan_code + "/fixed_charges/" + fixed_charge_code, + json=body, + ) + response = client.plan_fixed_charges.find(plan_code, fixed_charge_code) + + assert response.lago_id == "fc901a90-1a90-1a90-1a90-1a901a901a90" + assert response.invoice_display_name is None + + def test_valid_create_fixed_charge_request(httpx_mock: HTTPXMock): client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") plan_code = "plan_code" diff --git a/tests/test_subscription_client.py b/tests/test_subscription_client.py index 5755174..429769a 100644 --- a/tests/test_subscription_client.py +++ b/tests/test_subscription_client.py @@ -1,3 +1,4 @@ +import json import os import httpx @@ -460,6 +461,25 @@ def test_valid_find_all_fixed_charges_request(httpx_mock: HTTPXMock): assert response["meta"]["current_page"] == 1 +def test_valid_find_all_fixed_charges_request_without_invoice_display_name(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + external_id = "sub_external_123" + body = json.loads(mock_fixed_charges_response()) + body["fixed_charges"][0]["invoice_display_name"] = None + + httpx_mock.add_response( + method="GET", + url="https://api.getlago.com/api/v1/subscriptions/" + external_id + "/fixed_charges", + json=body, + ) + response = client.subscription_fixed_charges.find_all(external_id) + + assert len(response["fixed_charges"]) == 2 + assert response["fixed_charges"][0].lago_id == "1a901a90-1a90-1a90-1a90-1a901a901a90" + assert response["fixed_charges"][0].invoice_display_name is None + assert response["meta"]["current_page"] == 1 + + def test_invalid_find_all_fixed_charges_request(httpx_mock: HTTPXMock): client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") external_id = "invalid_sub" @@ -741,6 +761,25 @@ def test_valid_update_fixed_charge_request(httpx_mock: HTTPXMock): assert response.lago_id == "fc901a90-1a90-1a90-1a90-1a901a901a90" +def test_valid_update_fixed_charge_request_without_invoice_display_name(httpx_mock: HTTPXMock): + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") + external_id = "sub_external_123" + fixed_charge_code = "fixed_setup" + response_body = json.loads(mock_subscription_fixed_charge_response()) + response_body["fixed_charge"]["invoice_display_name"] = None + + httpx_mock.add_response( + method="PUT", + url="https://api.getlago.com/api/v1/subscriptions/" + external_id + "/fixed_charges/" + fixed_charge_code, + json=response_body, + ) + fixed_charge = FixedCharge(units=20, apply_units_immediately=True) + response = client.subscription_fixed_charges.update(external_id, fixed_charge_code, fixed_charge) + + assert response.lago_id == "fc901a90-1a90-1a90-1a90-1a901a901a90" + assert response.invoice_display_name is None + + # --- Charge Filters ---