Files
orion/app/modules/tenancy/tests/unit/test_team_model.py
Samir Boulahtit d1fe3584ff fix(billing): complete billing module — fix tier change, platform support, merchant portal
- Fix admin tier change: resolve tier_code→tier_id in update_subscription(),
  delegate to billing_service.change_tier() for Stripe-connected subs
- Add platform support to admin tiers page: platform column, filter dropdown,
  platform selector in create/edit modal, platform_name in tier API response
- Filter used platforms in create subscription modal on merchant detail page
- Enrich merchant portal API responses with tier code, tier_name, platform_name
- Add eager-load of platform relationship in get_merchant_subscription()
- Remove stale store_name/store_code references from merchant templates
- Add merchant tier change endpoint (POST /change-tier) and tier selector UI
  replacing broken requestUpgrade() button
- Fix subscription detail link to use platform_id instead of sub.id

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 20:49:48 +01:00

139 lines
3.8 KiB
Python

# tests/unit/models/database/test_team.py
"""Unit tests for StoreUser and Role database models."""
import pytest
from app.modules.tenancy.models import Role, Store, StoreUser
@pytest.mark.unit
@pytest.mark.database
class TestRoleModel:
"""Test Role model."""
def test_role_creation(self, db, test_store):
"""Test Role model creation."""
role = Role(
store_id=test_store.id,
name="Manager",
permissions=["products.create", "orders.view"],
)
db.add(role)
db.commit()
db.refresh(role)
assert role.id is not None
assert role.store_id == test_store.id
assert role.name == "Manager"
assert "products.create" in role.permissions
assert "orders.view" in role.permissions
def test_role_default_permissions(self, db, test_store):
"""Test Role model with default empty permissions."""
role = Role(
store_id=test_store.id,
name="Viewer",
)
db.add(role)
db.commit()
db.refresh(role)
assert role.permissions == [] or role.permissions is None
def test_role_store_relationship(self, db, test_store):
"""Test Role-Store relationship."""
role = Role(
store_id=test_store.id,
name="Admin",
permissions=["*"],
)
db.add(role)
db.commit()
db.refresh(role)
assert role.store is not None
assert role.store.id == test_store.id
@pytest.mark.unit
@pytest.mark.database
class TestStoreUserModel:
"""Test StoreUser model."""
def test_store_user_creation(self, db, test_store, test_user):
"""Test StoreUser model for team management."""
# Create a role
role = Role(
store_id=test_store.id,
name="Manager",
permissions=["products.create", "orders.view"],
)
db.add(role)
db.commit()
# Create store user
store_user = StoreUser(
store_id=test_store.id,
user_id=test_user.id,
role_id=role.id,
is_active=True,
)
db.add(store_user)
db.commit()
db.refresh(store_user)
assert store_user.id is not None
assert store_user.store_id == test_store.id
assert store_user.user_id == test_user.id
assert store_user.role.name == "Manager"
assert "products.create" in store_user.role.permissions
def test_store_user_relationships(self, db, test_store, test_user):
"""Test StoreUser relationships."""
role = Role(
store_id=test_store.id,
name="Staff",
permissions=["orders.view"],
)
db.add(role)
db.commit()
store_user = StoreUser(
store_id=test_store.id,
user_id=test_user.id,
role_id=role.id,
is_active=True,
)
db.add(store_user)
db.commit()
db.refresh(store_user)
assert store_user.store is not None
assert store_user.user is not None
assert store_user.role is not None
assert store_user.store.store_code == test_store.store_code
assert store_user.user.email == test_user.email
def test_store_user_with_active_flag(self, db, test_store, test_user):
"""Test StoreUser is_active field."""
role = Role(
store_id=test_store.id,
name="Default",
permissions=[],
)
db.add(role)
db.commit()
# Create with explicit is_active=True
store_user = StoreUser(
store_id=test_store.id,
user_id=test_user.id,
role_id=role.id,
is_active=True,
)
db.add(store_user)
db.commit()
db.refresh(store_user)
assert store_user.is_active is True