implemented
This commit is contained in:
parent
a31bd8246c
commit
d3638e2e69
18 changed files with 1643 additions and 120 deletions
48
backend/validate_constants.py
Normal file
48
backend/validate_constants.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
"""Validate shared constants match backend definitions."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from models import ROLE_ADMIN, ROLE_REGULAR, InviteStatus
|
||||
|
||||
|
||||
def validate_shared_constants() -> None:
|
||||
"""
|
||||
Validate that shared/constants.json matches backend definitions.
|
||||
Raises ValueError if there's a mismatch.
|
||||
"""
|
||||
constants_path = Path(__file__).parent.parent / "shared" / "constants.json"
|
||||
|
||||
if not constants_path.exists():
|
||||
raise ValueError(f"Shared constants file not found: {constants_path}")
|
||||
|
||||
with open(constants_path) as f:
|
||||
constants = json.load(f)
|
||||
|
||||
# Validate roles
|
||||
expected_roles = {"ADMIN": ROLE_ADMIN, "REGULAR": ROLE_REGULAR}
|
||||
if constants.get("roles") != expected_roles:
|
||||
raise ValueError(
|
||||
f"Role mismatch in shared/constants.json. "
|
||||
f"Expected: {expected_roles}, Got: {constants.get('roles')}"
|
||||
)
|
||||
|
||||
# Validate invite statuses
|
||||
expected_statuses = {s.name: s.value for s in InviteStatus}
|
||||
if constants.get("inviteStatuses") != expected_statuses:
|
||||
raise ValueError(
|
||||
f"Invite status mismatch in shared/constants.json. "
|
||||
f"Expected: {expected_statuses}, Got: {constants.get('inviteStatuses')}"
|
||||
)
|
||||
|
||||
# Validate validation rules exist (structure check only)
|
||||
validation = constants.get("validation", {})
|
||||
required_fields = ["telegram", "signal", "nostrNpub"]
|
||||
for field in required_fields:
|
||||
if field not in validation:
|
||||
raise ValueError(f"Missing validation rules for '{field}' in shared/constants.json")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
validate_shared_constants()
|
||||
print("✓ Shared constants are valid")
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue