"""资金门 fail-closed 测试。"""

from __future__ import annotations

from app.strategy.open_capacity import funds_gate_blocks


def test_funds_gate_blocks_none() -> None:
    blocked, msg = funds_gate_blocks(
        {
            "perp_can_open": True,
            "option_can_open": None,
            "perp_label": "a",
            "option_label": "b",
        }
    )
    assert blocked is True
    assert "未知" in msg or "拒绝" in msg


def test_funds_gate_blocks_false() -> None:
    blocked, msg = funds_gate_blocks(
        {
            "perp_can_open": True,
            "option_can_open": False,
            "perp_label": "永续可开",
            "option_label": "期权不可开",
            "perp_need_usdt": 1,
            "perp_have_usdt": 10,
            "option_need_usdc": 100,
            "option_have_usdc": 1,
        }
    )
    assert blocked is True
    assert "不可开" in msg or "不足" in msg


def test_funds_gate_ok_only_when_both_true() -> None:
    blocked, _ = funds_gate_blocks(
        {
            "perp_can_open": True,
            "option_can_open": True,
            "perp_label": "永续可开",
            "option_label": "期权可开",
        }
    )
    assert blocked is False
