- Add exchange constants to shared/constants.json: - eurTradeMin: 100, eurTradeMax: 3000, eurTradeIncrement: 20 - premiumPercentage: 5 - priceRefreshSeconds: 60, priceStalenessSeconds: 300 - Add exchangeStatuses and tradeDirections to shared constants - Add ExchangeStatus and TradeDirection enums to models.py - Update shared_constants.py to export new exchange constants - Update validate_constants.py to validate new enums and fields
110 lines
3.7 KiB
Python
110 lines
3.7 KiB
Python
"""Validate shared constants match backend definitions."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from models import (
|
|
ROLE_ADMIN,
|
|
ROLE_REGULAR,
|
|
AppointmentStatus,
|
|
ExchangeStatus,
|
|
InviteStatus,
|
|
TradeDirection,
|
|
)
|
|
|
|
|
|
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_invite_statuses = {s.name: s.value for s in InviteStatus}
|
|
if constants.get("inviteStatuses") != expected_invite_statuses:
|
|
got = constants.get("inviteStatuses")
|
|
raise ValueError(
|
|
f"Invite status mismatch. Expected: {expected_invite_statuses}, Got: {got}"
|
|
)
|
|
|
|
# Validate appointment statuses
|
|
expected_appointment_statuses = {s.name: s.value for s in AppointmentStatus}
|
|
if constants.get("appointmentStatuses") != expected_appointment_statuses:
|
|
got = constants.get("appointmentStatuses")
|
|
raise ValueError(
|
|
f"Appointment status mismatch. "
|
|
f"Expected: {expected_appointment_statuses}, Got: {got}"
|
|
)
|
|
|
|
# Validate exchange statuses
|
|
expected_exchange_statuses = {s.name: s.value for s in ExchangeStatus}
|
|
if constants.get("exchangeStatuses") != expected_exchange_statuses:
|
|
got = constants.get("exchangeStatuses")
|
|
raise ValueError(
|
|
f"Exchange status mismatch. "
|
|
f"Expected: {expected_exchange_statuses}, Got: {got}"
|
|
)
|
|
|
|
# Validate trade directions
|
|
expected_trade_directions = {d.name: d.value for d in TradeDirection}
|
|
if constants.get("tradeDirections") != expected_trade_directions:
|
|
got = constants.get("tradeDirections")
|
|
raise ValueError(
|
|
f"Trade direction mismatch. "
|
|
f"Expected: {expected_trade_directions}, Got: {got}"
|
|
)
|
|
|
|
# Validate booking constants exist with required fields
|
|
booking = constants.get("booking", {})
|
|
required_booking_fields = [
|
|
"slotDurationMinutes",
|
|
"maxAdvanceDays",
|
|
"minAdvanceDays",
|
|
"noteMaxLength",
|
|
]
|
|
for field in required_booking_fields:
|
|
if field not in booking:
|
|
raise ValueError(f"Missing booking constant '{field}' in constants.json")
|
|
|
|
# Validate exchange constants exist with required fields
|
|
exchange = constants.get("exchange", {})
|
|
required_exchange_fields = [
|
|
"eurTradeMin",
|
|
"eurTradeMax",
|
|
"eurTradeIncrement",
|
|
"premiumPercentage",
|
|
"priceRefreshSeconds",
|
|
"priceStalenessSeconds",
|
|
]
|
|
for field in required_exchange_fields:
|
|
if field not in exchange:
|
|
raise ValueError(f"Missing exchange constant '{field}' in constants.json")
|
|
|
|
# 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 constants.json"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
validate_shared_constants()
|
|
print("✓ Shared constants are valid")
|