发布(0.4.5): 修复重选号台账同步并移除强制确认
This commit is contained in:
@@ -751,6 +751,93 @@ class TestFulfillmentCollabSync(_Base):
|
||||
lease = self.session.query(AccountLease).one()
|
||||
assert lease.purpose == "douyu_collab"
|
||||
|
||||
def test_platform_sync_replaces_account_and_role_after_reallocation(self):
|
||||
"""履约单释放后重选账号,台账必须清掉首单角色并投影新账号。"""
|
||||
task = self._task_with_account()
|
||||
old_account = self.session.get(Account, task.account_id)
|
||||
old_bind = DouyuTask(
|
||||
batch_id="collab-old-account-bind",
|
||||
account_id=old_account.id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
result={
|
||||
"role_name": "旧角色",
|
||||
"bind_confirmed": True,
|
||||
"area_name": "微信",
|
||||
"plat_name": "苹果(iOS)",
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(old_bind)
|
||||
self.session.flush()
|
||||
task.bind_task_id = old_bind.id
|
||||
task.binding_status = "bound"
|
||||
task.execution_status = "bound"
|
||||
self.session.commit()
|
||||
|
||||
order, _ = collab.sync_platform_fulfillment_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
task,
|
||||
)
|
||||
assert order.account_id == old_account.id
|
||||
assert order.bind_game_role == "旧角色"
|
||||
|
||||
replacement = self.account("collab-replacement-account")
|
||||
replacement.role_bind_status = "bound"
|
||||
replacement.game_name = "新角色"
|
||||
replacement.game_channel = "手Q · 安卓(android)"
|
||||
task.account_id = replacement.id
|
||||
task.bind_task_id = None
|
||||
task.binding_status = "not_started"
|
||||
task.execution_status = "allocated"
|
||||
self.session.commit()
|
||||
|
||||
reallocated, _ = collab.sync_platform_fulfillment_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
task,
|
||||
)
|
||||
|
||||
assert reallocated.account_id == replacement.id
|
||||
assert reallocated.account_username == replacement.username
|
||||
assert reallocated.bind_game_role == ""
|
||||
assert reallocated.bind_game_channel == ""
|
||||
assert reallocated.bind_snapshot_at is None
|
||||
|
||||
new_bind = DouyuTask(
|
||||
batch_id="collab-new-account-bind",
|
||||
account_id=replacement.id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
result={
|
||||
"role_name": "新角色",
|
||||
"bind_confirmed": True,
|
||||
"area_name": "手Q",
|
||||
"plat_name": "安卓(android)",
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(new_bind)
|
||||
self.session.flush()
|
||||
task.bind_task_id = new_bind.id
|
||||
task.binding_status = "bound"
|
||||
task.execution_status = "bound"
|
||||
self.session.commit()
|
||||
|
||||
rebound, _ = collab.sync_platform_fulfillment_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
task,
|
||||
)
|
||||
|
||||
assert rebound.account_id == replacement.id
|
||||
assert rebound.bind_game_role == "新角色"
|
||||
assert rebound.bind_game_channel == "手Q / 安卓(android)"
|
||||
assert rebound.bind_snapshot_at is not None
|
||||
|
||||
def test_manual_sync_does_not_clear_account_added_in_collab(self):
|
||||
task = self.task()
|
||||
order, _ = collab.sync_platform_fulfillment_order(
|
||||
@@ -3418,75 +3505,6 @@ class TestBindingAndCompletion(_Base):
|
||||
assert evidence["actionCurrent"]["roleName"] == "兔稚儿"
|
||||
assert evidence["decisionReason"] == "no_role"
|
||||
|
||||
def test_manual_confirm_binding_marks_bound_without_scan(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "兔稚儿"
|
||||
account.role_bind_status = "bound"
|
||||
qr_task = DouyuTask(
|
||||
batch_id="manual-confirm-qr",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="running",
|
||||
platform_task_id=task.id,
|
||||
result={"bind_phase": "waiting_scan", "bind_polling": True},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(qr_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = qr_task.id
|
||||
task.binding_status = "qr_pending"
|
||||
task.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
detail = service.manual_confirm_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
role_name="兔稚儿",
|
||||
note="客户已在精英宝典完成绑定",
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
self.session.refresh(qr_task)
|
||||
assert detail["task"]["bindingStatus"] == "bound"
|
||||
assert detail["task"]["executionStatus"] == "bound"
|
||||
assert task.binding_status == "bound"
|
||||
assert task.execution_status == "bound"
|
||||
assert qr_task.status == "success"
|
||||
assert "人工确认绑定" in qr_task.message
|
||||
assert detail["task"]["bindTask"]["roleName"] == "兔稚儿"
|
||||
assert detail["task"]["bindTask"]["bindConfirmed"] is True
|
||||
assert qr_task.result["manual_confirmed"] is True
|
||||
assert qr_task.result["manual_confirmed_role"] == "兔稚儿"
|
||||
assert qr_task.result["role_name"] == "兔稚儿"
|
||||
assert qr_task.result["bind_ready_for_confirm"] is False
|
||||
event = (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_manually_confirmed")
|
||||
.one()
|
||||
)
|
||||
assert event.detail_json["roleName"] == "兔稚儿"
|
||||
assert event.detail_json["note"] == "客户已在精英宝典完成绑定"
|
||||
assert event.detail_json["operatorId"] == self.admin_id
|
||||
|
||||
# 幂等:重复确认不再重复写事件。
|
||||
service.manual_confirm_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
role_name="兔稚儿",
|
||||
note="重复确认",
|
||||
)
|
||||
assert (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_manually_confirmed")
|
||||
.count()
|
||||
== 1
|
||||
)
|
||||
|
||||
def test_operator_confirm_uses_scanned_role_without_form(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
@@ -3657,50 +3675,6 @@ class TestBindingAndCompletion(_Base):
|
||||
assert exc_info.value.status_code == 409
|
||||
assert "主页截图" in str(exc_info.value.detail)
|
||||
|
||||
def test_manual_confirm_rejects_role_not_currently_bound(self):
|
||||
task = self._allocated()
|
||||
account = self.session.get(Account, task.account_id)
|
||||
account.game_name = "小乖悄"
|
||||
account.role_bind_status = "bound"
|
||||
qr_task = DouyuTask(
|
||||
batch_id="manual-mismatch-qr",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=task.id,
|
||||
result={"bind_phase": "waiting_scan", "role_name": "等清晰"},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(qr_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = qr_task.id
|
||||
task.binding_status = "qr_pending"
|
||||
task.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
service.manual_confirm_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
role_name="等清晰",
|
||||
note="客户说角色是等清晰",
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert exc_info.value.status_code == 409
|
||||
assert "不一致" in str(exc_info.value.detail)
|
||||
assert task.binding_status == "qr_pending"
|
||||
assert task.execution_status == "waiting_bind"
|
||||
assert (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_manually_confirmed")
|
||||
.count()
|
||||
== 0
|
||||
)
|
||||
|
||||
def test_cjm_only_transient_role_waits_for_action_alias_sync(self):
|
||||
task = self._allocated()
|
||||
qr_task = DouyuTask(
|
||||
|
||||
Reference in New Issue
Block a user