fix(fulfillment): 清理重新绑定后的旧失败状态
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -425,6 +426,44 @@ class TestBindingAndCompletion(_Base):
|
||||
self.session.refresh(task)
|
||||
return task
|
||||
|
||||
def test_start_binding_clears_stale_binding_failure(self, monkeypatch):
|
||||
task = self._allocated()
|
||||
failed_bind_task = DouyuTask(
|
||||
batch_id="bind-failed",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="failed",
|
||||
message="绑定任务失败",
|
||||
result={},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(failed_bind_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = failed_bind_task.id
|
||||
task.binding_status = "failed"
|
||||
task.execution_status = "manual_required"
|
||||
task.issue_code = "binding_failed"
|
||||
task.last_error = "绑定失败,请刷新二维码后重试"
|
||||
self.session.commit()
|
||||
monkeypatch.setattr(service, "start_douyu_batch", lambda **_kwargs: None)
|
||||
|
||||
asyncio.run(
|
||||
service.start_binding(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
force_refresh=True,
|
||||
)
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert task.binding_status == "preparing"
|
||||
assert task.execution_status == "waiting_bind"
|
||||
assert task.issue_code == ""
|
||||
assert task.last_error == ""
|
||||
|
||||
def test_refresh_binding_maps_role_ready(self):
|
||||
task = self._allocated()
|
||||
bind_task = DouyuTask(
|
||||
@@ -449,6 +488,34 @@ class TestBindingAndCompletion(_Base):
|
||||
assert detail["task"]["bindingStatus"] == "role_ready"
|
||||
assert detail["task"]["bindTask"]["roleName"] == "测试角色"
|
||||
|
||||
def test_refresh_binding_clears_stale_failure_when_qr_is_pending(self):
|
||||
task = self._allocated()
|
||||
bind_task = DouyuTask(
|
||||
batch_id="bind-qr-after-failure",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="running",
|
||||
result={"url": "https://example.com/new-qr"},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(bind_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = bind_task.id
|
||||
task.binding_status = "failed"
|
||||
task.execution_status = "manual_required"
|
||||
task.issue_code = "binding_failed"
|
||||
task.last_error = "绑定失败,请刷新二维码后重试"
|
||||
self.session.commit()
|
||||
|
||||
detail = service.refresh_binding(self.session, task_id=task.id)
|
||||
|
||||
assert detail["task"]["bindingStatus"] == "qr_pending"
|
||||
assert detail["task"]["executionStatus"] == "waiting_bind"
|
||||
assert detail["task"]["issueCode"] == ""
|
||||
assert detail["task"]["lastError"] == ""
|
||||
|
||||
def test_list_hides_qr_but_detail_returns_it(self):
|
||||
task = self._allocated()
|
||||
bind_task = DouyuTask(
|
||||
|
||||
Reference in New Issue
Block a user