diff --git a/e2e_config.test.json b/e2e_config.test.json index 4cfb67b0..6c7cb797 100644 --- a/e2e_config.test.json +++ b/e2e_config.test.json @@ -15,8 +15,9 @@ "billing.custom_ledger.attachment.id": "CLA-1777-7485", "billing.custom_ledger.charge.id": "CHG-2665-3524-0000-0000-0020", "billing.custom_ledger.id": "CLE-2665-3524", - "billing.journal.attachment.id": "JOA-6425-9776", - "billing.journal.id": "BJO-6562-0928", + "billing.journal.attachment.id": "JOA-2849-3620", + "billing.journal.charge.id": "CHG-2589-1434-0000-0000-0200", + "billing.journal.id": "BJO-2589-1434", "billing.ledger.attachment.id": "LEA-4971-4321", "billing.ledger.charge.id": "CHG-2589-1434-0000-0000-0200", "billing.ledger.id": "BLE-2589-1434-7310-3075", diff --git a/tests/data/test_billing_journal.jsonl b/tests/data/test_billing_journal.jsonl index a4906804..02103936 100644 --- a/tests/data/test_billing_journal.jsonl +++ b/tests/data/test_billing_journal.jsonl @@ -1 +1 @@ -{"externalIds": {"vendor": "ext-seeded-billing-sub-vendor-id", "invoice": "INV12345", "reference": "ORD-7924-7691-0805"}, "search": {"source": {"type": "Subscription", "criteria": "id", "value": "SUB-5839-4140-9574"},"order":{"criteria":"order.id","value":"ORD-7924-7691-0805"}, "item": {"criteria": "item.id", "value": "ITM-1767-7355-0001"}}, "period": {"start": "2025-12-22", "end": "2026-12-21"}, "price": {"unitPP": 10, "PPx1": 8.33}, "quantity": 10, "segment": "COM", "description": {"value1": "desc-1", "value2": "desc-2"}} +{"externalIds": {"vendor": "ext-seeded-billing-sub-vendor-id", "invoice": "INV12345", "reference": "ORD-2413-8980-9419"}, "search": {"source": {"type": "Subscription", "criteria": "id", "value": "SUB-0356-5642-8669"},"order":{"criteria":"order.id","value":"ORD-2413-8980-9419"}, "item": {"criteria": "item.id", "value": "ITM-1767-7355-0001"}}, "period": {"start": "2025-12-22", "end": "2026-12-21"}, "price": {"unitPP": 10, "PPx1": 8.33}, "quantity": 10, "segment": "COM", "description": {"value1": "desc-1", "value2": "desc-2"}} diff --git a/tests/data/test_billing_journal.xlsx b/tests/data/test_billing_journal.xlsx index 81203ebd..81e4affd 100644 Binary files a/tests/data/test_billing_journal.xlsx and b/tests/data/test_billing_journal.xlsx differ diff --git a/tests/e2e/billing/journal/charge/conftest.py b/tests/e2e/billing/journal/charge/conftest.py new file mode 100644 index 00000000..accc1c8b --- /dev/null +++ b/tests/e2e/billing/journal/charge/conftest.py @@ -0,0 +1,11 @@ +import pytest + + +@pytest.fixture +def journal_charge_id(e2e_config): + return e2e_config["billing.journal.charge.id"] + + +@pytest.fixture +def invalid_journal_charge_id(): + return "CHG-0000-0000-0000-0000-0000" diff --git a/tests/e2e/billing/journal/charge/test_async_journal_charge.py b/tests/e2e/billing/journal/charge/test_async_journal_charge.py new file mode 100644 index 00000000..f52ac0e3 --- /dev/null +++ b/tests/e2e/billing/journal/charge/test_async_journal_charge.py @@ -0,0 +1,43 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.rql.query_builder import RQLQuery + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +def journal_charges(async_mpt_vendor, billing_journal_id): + return async_mpt_vendor.billing.journals.charges(billing_journal_id) + + +async def test_get_journal_charge_by_id(journal_charges, journal_charge_id): + result = await journal_charges.get(journal_charge_id) + + assert result is not None + + +async def test_get_journal_charge_by_id_not_found(journal_charges, invalid_journal_charge_id): + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + await journal_charges.get(invalid_journal_charge_id) + + +async def test_list_journal_charges(journal_charges): + limit = 10 + + result = await journal_charges.fetch_page(limit=limit) + + assert len(result) > 0 + + +async def test_filter_journal_charges(journal_charges, journal_charge_id): + select_fields = ["-period"] + filtered_charges = ( + journal_charges.filter(RQLQuery(id=journal_charge_id)) + .filter(RQLQuery(externalIds__invoice="INV12345")) + .select(*select_fields) + ) + + result = [charges async for charges in filtered_charges.iterate()] + + assert len(result) == 1 diff --git a/tests/e2e/billing/journal/charge/test_sync_journal_charge.py b/tests/e2e/billing/journal/charge/test_sync_journal_charge.py new file mode 100644 index 00000000..f24b4223 --- /dev/null +++ b/tests/e2e/billing/journal/charge/test_sync_journal_charge.py @@ -0,0 +1,43 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.rql.query_builder import RQLQuery + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +def journal_charges(mpt_vendor, billing_journal_id): + return mpt_vendor.billing.journals.charges(billing_journal_id) + + +def test_get_journal_charge_by_id(journal_charges, journal_charge_id): + result = journal_charges.get(journal_charge_id) + + assert result is not None + + +def test_get_journal_charge_by_id_not_found(journal_charges, invalid_journal_charge_id): + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + journal_charges.get(invalid_journal_charge_id) + + +def test_list_journal_charges(journal_charges): + limit = 10 + + result = journal_charges.fetch_page(limit=limit) + + assert len(result) > 0 + + +def test_filter_journal_charges(journal_charges, journal_charge_id): + select_fields = ["-period"] + filtered_charges = ( + journal_charges.filter(RQLQuery(id=journal_charge_id)) + .filter(RQLQuery(externalIds__invoice="INV12345")) + .select(*select_fields) + ) + + result = list(filtered_charges.iterate()) + + assert len(result) == 1