feat(huya): 开通充值支持数量与记住上次选择,精英宝典单独一块
- 支持「其他开通商品」按份数下单(payload.count → createOrder 的 item_count),数量上限取商品 buy_limit - 商品选择/数量写入 localStorage,下次进来还是上次那套 - 精英宝典(限购主商品)从其他开通商品里拆出来单独一块,避免混在一个下拉里选错 - 测试:payload.count=3 进入 run_open_flow 且结果/文案带 x3
This commit is contained in:
@@ -421,6 +421,100 @@ def test_create_recharge_order_confirms_elite_open_after_payment(db, monkeypatch
|
||||
assert account.status == "recharge_paid"
|
||||
|
||||
|
||||
def test_create_recharge_order_uses_requested_count(db, monkeypatch):
|
||||
"""开通数量:payload.count 按份数下单(前端「数量」输入框),结果与文案都带 xN。"""
|
||||
|
||||
captured: dict = {}
|
||||
outcome = SimpleNamespace(
|
||||
ok=True,
|
||||
message="",
|
||||
detail={"spu_id": "hy-5872824", "sku_id": 7756812, "name": "精英徽章"},
|
||||
sku_id=7756812,
|
||||
product_name="精英徽章",
|
||||
unit_price=100,
|
||||
order_raw={"order_id": 11399998},
|
||||
pay_raw={"pay_order_id": "pay-2"},
|
||||
amount=300,
|
||||
order_id=11399998,
|
||||
app_order_id="app-2",
|
||||
pay_order_id="pay-2",
|
||||
pay_url="https://example.com/pay",
|
||||
supplier_name="和平精英官方小店",
|
||||
promotion={},
|
||||
promotion_info="",
|
||||
reused_order={},
|
||||
)
|
||||
|
||||
def fake_open_flow(_client, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return outcome
|
||||
|
||||
shop_client = _StubClient(redeem=_redeem(REDEEM_OPENED_HEX))
|
||||
runner = HuyaBatchRunner(
|
||||
db=None,
|
||||
batch_id="t",
|
||||
task_type="create_recharge_order",
|
||||
payload={
|
||||
"spu_id": "hy-5872824",
|
||||
"sku_id": 7756812,
|
||||
"product_name": "精英徽章",
|
||||
"count": 3,
|
||||
},
|
||||
)
|
||||
marks: list[tuple[str, str, dict | None]] = []
|
||||
monkeypatch.setattr(
|
||||
runner, "_shop_client", lambda uid, cookie: shop_client, raising=False
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
runner,
|
||||
"_mark_task",
|
||||
lambda _db, _task, status, message, result=None: marks.append(
|
||||
(status, message, result)
|
||||
),
|
||||
raising=False,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
runner, "_update_task_progress", lambda *args, **kwargs: None, raising=False
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
runner, "_push_log", lambda *args, **kwargs: None, raising=False
|
||||
)
|
||||
# 不真等支付:这一步只验证数量有没有进下单请求
|
||||
monkeypatch.setattr(
|
||||
runner,
|
||||
"_wait_recharge_payment",
|
||||
lambda **kwargs: ("timeout", None),
|
||||
raising=False,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"web.backend.services.huya_runner_recharge.run_open_flow", fake_open_flow
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"web.backend.services.huya_runner_recharge.resolve_pay_targets",
|
||||
lambda _pay_url, **_kwargs: PayTargets(
|
||||
cashier_url="", qr_code="https://qr.alipay.com/upx03110ghym9vm37sx7255c"
|
||||
),
|
||||
)
|
||||
account = HuyaAccount(uid=str(UID), cookie=COOKIE)
|
||||
db.add(account)
|
||||
db.commit()
|
||||
|
||||
runner._execute_create_recharge_order(
|
||||
db,
|
||||
SimpleNamespace(id=588),
|
||||
account,
|
||||
{"uid": UID, "cookie": COOKIE},
|
||||
{"room_pid": "1199650619883", "pay_channel": "Zfb", "sid": "2203"},
|
||||
)
|
||||
|
||||
assert captured["count"] == 3
|
||||
_status, message, result = marks[-1]
|
||||
assert result["count"] == 3
|
||||
assert result["amount"] == 300
|
||||
assert "x3" in message
|
||||
assert account.status == "recharge_order_created"
|
||||
|
||||
|
||||
def test_query_all_combines_points_elite_and_role(monkeypatch):
|
||||
shop_client = _StubClient(
|
||||
redeem=_redeem(REDEEM_OPENED_HEX), order_pages=[[PAID_ELITE_ORDER]]
|
||||
|
||||
Reference in New Issue
Block a user