test: add tests for merchant dashboard metrics and fix invoice template location
Move invoice PDF template from app/templates/invoices/ to app/modules/orders/templates/invoices/ where InvoicePDFService expects it. Expand invoice PDF tests to validate template path and existence. Add unit tests for get_merchant_metrics() in tenancy, billing, and customer metrics providers. Add unit tests for StatsAggregatorService merchant methods. Add integration tests for the merchant dashboard stats endpoint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
"""Unit tests for InvoicePDFService."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.orders.services.invoice_pdf_service import InvoicePDFService
|
||||
from app.modules.orders.services.invoice_pdf_service import (
|
||||
TEMPLATE_DIR,
|
||||
InvoicePDFService,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -16,3 +21,25 @@ class TestInvoicePDFService:
|
||||
def test_service_instantiation(self):
|
||||
"""Service can be instantiated."""
|
||||
assert self.service is not None
|
||||
|
||||
def test_template_directory_exists(self):
|
||||
"""Template directory must exist at the expected path."""
|
||||
assert TEMPLATE_DIR.exists(), f"Template directory missing: {TEMPLATE_DIR}"
|
||||
assert TEMPLATE_DIR.is_dir()
|
||||
|
||||
def test_invoice_template_exists(self):
|
||||
"""invoice.html template must exist in the template directory."""
|
||||
template_path = TEMPLATE_DIR / "invoice.html"
|
||||
assert template_path.exists(), f"Invoice template missing: {template_path}"
|
||||
|
||||
def test_template_can_be_loaded(self):
|
||||
"""Jinja2 environment can load the invoice template."""
|
||||
template = self.service.env.get_template("invoice.html")
|
||||
assert template is not None
|
||||
|
||||
def test_template_dir_is_inside_orders_module(self):
|
||||
"""Template directory should be inside the orders module, not the global templates."""
|
||||
orders_module_dir = Path(__file__).parent.parent.parent
|
||||
assert str(TEMPLATE_DIR).startswith(str(orders_module_dir)), (
|
||||
f"TEMPLATE_DIR ({TEMPLATE_DIR}) should be inside orders module ({orders_module_dir})"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user