修复虎牙宝典开通中状态与支付监听异常
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
from types import SimpleNamespace
|
||||
|
||||
from core.huya.frame_decoder import decode_struct_bytes
|
||||
@@ -396,6 +397,7 @@ def test_refresh_elite_open_after_payment_retries_until_opened():
|
||||
|
||||
|
||||
def test_refresh_elite_open_after_payment_gives_up_after_attempts():
|
||||
"""支付已确认但权益未到账:不能再写死「未开通」,必须标成「开通中」。"""
|
||||
client = _StubClient(redeem=_redeem(REDEEM_NOT_OPENED_HEX))
|
||||
runner = HuyaBatchRunner(db=None, batch_id="t", task_type="create_recharge_order")
|
||||
account = HuyaAccount(uid=str(UID), cookie=COOKIE)
|
||||
@@ -412,11 +414,66 @@ def test_refresh_elite_open_after_payment_gives_up_after_attempts():
|
||||
)
|
||||
|
||||
assert client.redeem_calls == 2 # 重试到上限
|
||||
assert state["elite_opened"] is False
|
||||
assert account.elite_opened is False
|
||||
assert state["elite_opened"] is None
|
||||
assert state["elite_opening"] is True
|
||||
assert state["elite_status_label"] == "开通中"
|
||||
assert account.elite_opened is None
|
||||
assert account.elite_open_time is None
|
||||
|
||||
|
||||
def test_query_all_marks_recent_paid_elite_order_as_opening(monkeypatch):
|
||||
"""已支付但 redeem 还是 0:订单列表证明已付款,应显示「开通中」。"""
|
||||
now_ms = int(time.time() * 1000)
|
||||
opening_order = {
|
||||
**PAID_ELITE_ORDER,
|
||||
"order_id": "12001621",
|
||||
"pay_time": now_ms - 60_000,
|
||||
"create_time": now_ms - 120_000,
|
||||
}
|
||||
shop_client = _StubClient(
|
||||
redeem=_redeem(REDEEM_NOT_OPENED_HEX),
|
||||
order_pages=[[opening_order]],
|
||||
season=True,
|
||||
)
|
||||
runner, marks, _logs = _runner(monkeypatch, shop_client, activity_client=object())
|
||||
monkeypatch.setattr(
|
||||
runner,
|
||||
"_probe_bind_status",
|
||||
lambda **kwargs: (_FakeBindStatus(status=601, msg="活动已下线"), {}),
|
||||
raising=False,
|
||||
)
|
||||
account = HuyaAccount(uid=str(UID), cookie=COOKIE)
|
||||
|
||||
runner._execute_query_all(
|
||||
None, None, account, {"uid": UID, "cookie": COOKIE}, {"bind_act_id": "9271"}
|
||||
)
|
||||
|
||||
status, message, result = marks[-1]
|
||||
assert status == "success"
|
||||
assert result["elite_opening"] is True
|
||||
assert result["elite_status"] == "opening"
|
||||
assert result["elite_status_label"] == "开通中"
|
||||
assert result["elite_order"]["order_id"] == "12001621"
|
||||
assert account.elite_opened is None
|
||||
assert "开通中宝典" in message
|
||||
|
||||
|
||||
def test_elite_order_state_labels_pending_and_cancelled_orders():
|
||||
runner = HuyaBatchRunner(db=None, batch_id="t", task_type="query_all")
|
||||
assert (
|
||||
runner._elite_order_state(
|
||||
{**UNPAID_ELITE_ORDER, "order_id": "1"}, opened=False
|
||||
)["status"]
|
||||
== "pending_payment"
|
||||
)
|
||||
assert (
|
||||
runner._elite_order_state(
|
||||
{**PAID_ELITE_ORDER, "order_status": 90, "pay_time": 0}, opened=False
|
||||
)["status"]
|
||||
== "cancelled"
|
||||
)
|
||||
|
||||
|
||||
def test_create_recharge_order_confirms_elite_open_after_payment(db, monkeypatch):
|
||||
"""支付成功后自动确认开通状态:任务结果与账号字段都带上宝典状态。"""
|
||||
|
||||
@@ -676,7 +733,7 @@ def test_query_all_combines_points_elite_and_role(monkeypatch):
|
||||
)
|
||||
|
||||
|
||||
def test_query_all_reports_not_opened_without_order_lookup(monkeypatch):
|
||||
def test_query_all_reports_not_opened_and_checks_order_state(monkeypatch):
|
||||
shop_client = _StubClient(redeem=_redeem(REDEEM_NOT_OPENED_HEX))
|
||||
runner, marks, _logs = _runner(monkeypatch, shop_client, activity_client=object())
|
||||
monkeypatch.setattr(
|
||||
@@ -699,8 +756,11 @@ def test_query_all_reports_not_opened_without_order_lookup(monkeypatch):
|
||||
assert account.elite_open_time is None
|
||||
assert "未开通宝典" in message
|
||||
assert "活动已下线" in message
|
||||
# 未开通不查订单(省一次请求)
|
||||
assert [name for name, _kwargs in shop_client.calls] == ["get_redeem_need_goods"]
|
||||
# 未开通也要查最近订单:否则无法区分「待支付 / 开通中 / 已取消」
|
||||
assert [name for name, _kwargs in shop_client.calls] == [
|
||||
"get_redeem_need_goods",
|
||||
"query_user_order_list",
|
||||
]
|
||||
|
||||
|
||||
def test_query_all_fails_when_points_center_unreachable(monkeypatch):
|
||||
|
||||
@@ -253,6 +253,47 @@ def test_pay_order_submit_v5_callback_points_page():
|
||||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_order_poll_rpcs_accept_timeout_keyword():
|
||||
"""支付监听统一传 timeout;WSS 方法缺这个参数会在生成二维码后立刻崩。"""
|
||||
|
||||
async def run():
|
||||
client = _points_client()
|
||||
|
||||
await client.query_user_order_list(
|
||||
uid=UID,
|
||||
guid=GUID,
|
||||
cookie=COOKIE,
|
||||
offset=0,
|
||||
page_size=20,
|
||||
order_type=1,
|
||||
status=0,
|
||||
timeout=10.0,
|
||||
)
|
||||
decoded = client.ws.last_request()
|
||||
assert (decoded["servant"], decoded["func"]) == (
|
||||
"revenueWebUI",
|
||||
"queryUserOrderList",
|
||||
)
|
||||
assert decoded["tReq"]["tag2"] == 1
|
||||
assert decoded["tReq"]["tag3"] == 20
|
||||
|
||||
await client.order_detail(
|
||||
uid=UID,
|
||||
guid=GUID,
|
||||
cookie=COOKIE,
|
||||
order_id=12001621,
|
||||
timeout=10.0,
|
||||
)
|
||||
decoded = client.ws.last_request()
|
||||
assert (decoded["servant"], decoded["func"]) == (
|
||||
"shopMiddleUI",
|
||||
"orderDetailV5",
|
||||
)
|
||||
assert decoded["tReq"]["tag2"] == 12001621
|
||||
|
||||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_new_points_rpcs_match_capture():
|
||||
async def run():
|
||||
client = _points_client()
|
||||
|
||||
Reference in New Issue
Block a user