feat(tenancy): add merchant-level domain with store override
Merchants can now register domains (e.g., myloyaltyprogram.lu) that all their stores inherit. Individual stores can override with their own custom domain. Resolution priority: StoreDomain > MerchantDomain > subdomain. - Add MerchantDomain model, schema, service, and admin API endpoints - Add merchant domain fallback in platform and store context middleware - Add Merchant.primary_domain and Store.effective_domain properties - Add Alembic migration for merchant_domains table - Update loyalty user journey docs with subscription & domain setup flow - Add unit tests (50 passing) and integration tests (15 passing) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
97
tests/fixtures/merchant_domain_fixtures.py
vendored
Normal file
97
tests/fixtures/merchant_domain_fixtures.py
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
# tests/fixtures/merchant_domain_fixtures.py
|
||||
"""
|
||||
Merchant domain test fixtures.
|
||||
|
||||
Provides fixtures for:
|
||||
- Merchants with verified merchant domains
|
||||
- Stores with merchant domain overrides (StoreDomain)
|
||||
- MerchantDomain objects for testing
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.tenancy.models.merchant_domain import MerchantDomain
|
||||
from app.modules.tenancy.models.store_domain import StoreDomain
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_merchant_domain(db, test_merchant):
|
||||
"""Create an unverified merchant domain."""
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
domain = MerchantDomain(
|
||||
merchant_id=test_merchant.id,
|
||||
domain=f"merchant{unique_id}.example.com",
|
||||
is_primary=True,
|
||||
is_active=False,
|
||||
is_verified=False,
|
||||
verification_token=f"mtoken_{unique_id}",
|
||||
ssl_status="pending",
|
||||
)
|
||||
db.add(domain)
|
||||
db.commit()
|
||||
db.refresh(domain)
|
||||
return domain
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def verified_merchant_domain(db, test_merchant):
|
||||
"""Create a verified and active merchant domain."""
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
domain = MerchantDomain(
|
||||
merchant_id=test_merchant.id,
|
||||
domain=f"verified-merchant{unique_id}.example.com",
|
||||
is_primary=True,
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
verified_at=datetime.now(UTC),
|
||||
verification_token=f"vmtoken_{unique_id}",
|
||||
ssl_status="active",
|
||||
)
|
||||
db.add(domain)
|
||||
db.commit()
|
||||
db.refresh(domain)
|
||||
return domain
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def merchant_with_domain(db, test_merchant, test_platform):
|
||||
"""Create a merchant with a verified merchant domain linked to a platform."""
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
domain = MerchantDomain(
|
||||
merchant_id=test_merchant.id,
|
||||
platform_id=test_platform.id,
|
||||
domain=f"testmerchant{unique_id}.example.com",
|
||||
is_primary=True,
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
verified_at=datetime.now(UTC),
|
||||
verification_token=f"mwd_{unique_id}",
|
||||
ssl_status="active",
|
||||
)
|
||||
db.add(domain)
|
||||
db.commit()
|
||||
db.refresh(domain)
|
||||
return test_merchant, domain
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store_with_merchant_domain_override(db, test_store):
|
||||
"""Store that overrides the merchant domain with its own StoreDomain."""
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
store_domain = StoreDomain(
|
||||
store_id=test_store.id,
|
||||
domain=f"storeoverride{unique_id}.example.com",
|
||||
is_primary=True,
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
verified_at=datetime.now(UTC),
|
||||
verification_token=f"sod_{unique_id}",
|
||||
ssl_status="active",
|
||||
)
|
||||
db.add(store_domain)
|
||||
db.commit()
|
||||
db.refresh(store_domain)
|
||||
return test_store, store_domain
|
||||
Reference in New Issue
Block a user