fix(billing): use tier_id instead of tier_code for feature limit endpoints
Some checks failed
CI / ruff (push) Successful in 10s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has been cancelled

Tier codes are not unique across platforms (e.g., "essential" exists for
OMS, marketplace, and loyalty). Using tier_code caused feature limits to
be saved to the wrong tier. Switched to tier_id (unique PK) in routes,
service, and frontend JS. Added comprehensive unit and integration tests
including cross-platform isolation regression tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 13:06:18 +01:00
parent f47c680cb8
commit 2833ff1476
5 changed files with 661 additions and 21 deletions

View File

@@ -86,11 +86,11 @@ def get_feature_catalog(
@admin_features_router.get(
"/tiers/{tier_code}/limits",
"/tiers/{tier_id}/limits",
response_model=list[TierFeatureLimitEntry],
)
def get_tier_feature_limits(
tier_code: str = Path(..., description="Tier code"),
tier_id: int = Path(..., description="Tier ID"),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
@@ -100,7 +100,7 @@ def get_tier_feature_limits(
Returns all TierFeatureLimit rows associated with the tier,
each containing a feature_code and its optional limit_value.
"""
rows = feature_service.get_tier_feature_limits(db, tier_code)
rows = feature_service.get_tier_feature_limits(db, tier_id)
return [
TierFeatureLimitEntry(
@@ -113,12 +113,12 @@ def get_tier_feature_limits(
@admin_features_router.put(
"/tiers/{tier_code}/limits",
"/tiers/{tier_id}/limits",
response_model=list[TierFeatureLimitEntry],
)
def upsert_tier_feature_limits(
entries: list[TierFeatureLimitEntry],
tier_code: str = Path(..., description="Tier code"),
tier_id: int = Path(..., description="Tier ID"),
current_user: UserContext = Depends(get_current_admin_api),
db: Session = Depends(get_db),
):
@@ -136,15 +136,15 @@ def upsert_tier_feature_limits(
raise InvalidFeatureCodesError(invalid_codes)
new_rows = feature_service.upsert_tier_feature_limits(
db, tier_code, [e.model_dump() for e in entries]
db, tier_id, [e.model_dump() for e in entries]
)
db.commit()
logger.info(
"Admin %s replaced tier '%s' feature limits (%d entries)",
"Admin %s replaced tier %d feature limits (%d entries)",
current_user.id,
tier_code,
tier_id,
len(new_rows),
)