feat: multi-module improvements across merchant, store, i18n, and customer systems
All checks were successful
All checks were successful
- Fix platform-grouped merchant sidebar menu with core items at root level - Add merchant store management (detail page, create store, team page) - Fix store settings 500 error by removing dead stripe/API tab - Move onboarding translations to module-owned locale files - Fix onboarding banner i18n with server-side rendering + context inheritance - Refactor login language selectors to use languageSelector() function (LANG-002) - Move HTTPException handling to global exception handler in merchant routes (API-003) - Add language selector to all login pages and portal headers - Fix customer module: drop order stats from customer model, add to orders module - Fix admin menu config visibility for super admin platform context - Fix storefront auth and layout issues - Add missing i18n translations for onboarding steps (en/fr/de/lb) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
Unit tests for AdminCustomerService.
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.customers.exceptions import CustomerNotFoundException
|
||||
@@ -18,16 +16,6 @@ def admin_customer_service():
|
||||
return AdminCustomerService()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def customer_with_orders(db, test_store, test_customer):
|
||||
"""Create a customer with order data."""
|
||||
test_customer.total_orders = 5
|
||||
test_customer.total_spent = Decimal("250.00")
|
||||
db.commit()
|
||||
db.refresh(test_customer)
|
||||
return test_customer
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def multiple_customers(db, test_store):
|
||||
"""Create multiple customers for testing."""
|
||||
@@ -41,8 +29,6 @@ def multiple_customers(db, test_store):
|
||||
last_name=f"Last{i}",
|
||||
customer_number=f"CUST-00{i}",
|
||||
is_active=(i % 2 == 0), # Alternate active/inactive
|
||||
total_orders=i,
|
||||
total_spent=Decimal(str(i * 100)),
|
||||
)
|
||||
db.add(customer) # noqa: PERF006
|
||||
customers.append(customer)
|
||||
@@ -165,10 +151,6 @@ class TestAdminCustomerServiceStats:
|
||||
assert stats["total"] == 0
|
||||
assert stats["active"] == 0
|
||||
assert stats["inactive"] == 0
|
||||
assert stats["with_orders"] == 0
|
||||
assert stats["total_spent"] == 0
|
||||
assert stats["total_orders"] == 0
|
||||
assert stats["avg_order_value"] == 0
|
||||
|
||||
def test_get_customer_stats_with_data(
|
||||
self, db, admin_customer_service, multiple_customers
|
||||
@@ -179,12 +161,6 @@ class TestAdminCustomerServiceStats:
|
||||
assert stats["total"] == 5
|
||||
assert stats["active"] == 3 # 0, 2, 4
|
||||
assert stats["inactive"] == 2 # 1, 3
|
||||
# with_orders = customers with total_orders > 0 (1, 2, 3, 4 = 4 customers)
|
||||
assert stats["with_orders"] == 4
|
||||
# total_spent = 0 + 100 + 200 + 300 + 400 = 1000
|
||||
assert stats["total_spent"] == 1000.0
|
||||
# total_orders = 0 + 1 + 2 + 3 + 4 = 10
|
||||
assert stats["total_orders"] == 10
|
||||
|
||||
def test_get_customer_stats_by_store(
|
||||
self, db, admin_customer_service, test_customer, test_store
|
||||
@@ -194,16 +170,6 @@ class TestAdminCustomerServiceStats:
|
||||
|
||||
assert stats["total"] == 1
|
||||
|
||||
def test_get_customer_stats_avg_order_value(
|
||||
self, db, admin_customer_service, customer_with_orders
|
||||
):
|
||||
"""Test average order value calculation."""
|
||||
stats = admin_customer_service.get_customer_stats(db)
|
||||
|
||||
# total_spent = 250, total_orders = 5
|
||||
# avg = 250 / 5 = 50
|
||||
assert stats["avg_order_value"] == 50.0
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestAdminCustomerServiceGetCustomer:
|
||||
|
||||
@@ -49,8 +49,6 @@ class TestCustomerModel:
|
||||
|
||||
assert customer.is_active is True # Default
|
||||
assert customer.marketing_consent is False # Default
|
||||
assert customer.total_orders == 0 # Default
|
||||
assert customer.total_spent == 0 # Default
|
||||
|
||||
def test_customer_full_name_property(self, db, test_store):
|
||||
"""Test Customer full_name computed property."""
|
||||
|
||||
@@ -149,7 +149,6 @@ class TestCustomerResponseSchema:
|
||||
def test_from_dict(self):
|
||||
"""Test creating response from dict."""
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
data = {
|
||||
"id": 1,
|
||||
@@ -161,9 +160,6 @@ class TestCustomerResponseSchema:
|
||||
"customer_number": "CUST001",
|
||||
"marketing_consent": False,
|
||||
"preferred_language": "fr",
|
||||
"last_order_date": None,
|
||||
"total_orders": 5,
|
||||
"total_spent": Decimal("500.00"),
|
||||
"is_active": True,
|
||||
"created_at": datetime.now(),
|
||||
"updated_at": datetime.now(),
|
||||
@@ -171,7 +167,7 @@ class TestCustomerResponseSchema:
|
||||
response = CustomerResponse(**data)
|
||||
assert response.id == 1
|
||||
assert response.customer_number == "CUST001"
|
||||
assert response.total_orders == 5
|
||||
assert response.preferred_language == "fr"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
Reference in New Issue
Block a user