fix(platform): 支持保留账号刷新绑定二维码
This commit is contained in:
@@ -2000,6 +2000,84 @@ class TestBindingAndCompletion(_Base):
|
||||
assert detail["task"]["bindTask"]["roleName"] == "测试角色"
|
||||
assert notified == [task.id]
|
||||
|
||||
def test_refresh_qr_reuses_unexpired_qr_and_keeps_account(self):
|
||||
task = self._allocated()
|
||||
account_id = int(task.account_id or 0)
|
||||
bind_task = DouyuTask(
|
||||
batch_id="bind-valid-qr",
|
||||
account_id=account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
result={
|
||||
"url": "https://example.com/current-qr",
|
||||
"qr_expires_at": (NOW + timedelta(minutes=5)).isoformat(),
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(bind_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = bind_task.id
|
||||
task.binding_status = "qr_pending"
|
||||
task.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
detail = asyncio.run(
|
||||
service.start_binding(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
force_refresh=True,
|
||||
)
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert task.bind_task_id == bind_task.id
|
||||
assert task.account_id == account_id
|
||||
assert detail["task"]["bindTask"]["id"] == bind_task.id
|
||||
|
||||
def test_refresh_expired_qr_reuses_same_account(self, monkeypatch):
|
||||
task = self._allocated()
|
||||
account_id = int(task.account_id or 0)
|
||||
old_bind_task = DouyuTask(
|
||||
batch_id="bind-expired-qr",
|
||||
account_id=account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
result={
|
||||
"url": "https://example.com/expired-qr",
|
||||
"qr_expires_at": (NOW - timedelta(minutes=1)).isoformat(),
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(old_bind_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = old_bind_task.id
|
||||
task.binding_status = "qr_pending"
|
||||
task.execution_status = "waiting_bind"
|
||||
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.account_id == account_id
|
||||
assert task.bind_task_id != old_bind_task.id
|
||||
refreshed_task = self.session.get(DouyuTask, task.bind_task_id)
|
||||
assert refreshed_task is not None
|
||||
assert refreshed_task.account_id == account_id
|
||||
assert refreshed_task.task_type == "get_bind_qr"
|
||||
|
||||
def test_refresh_binding_ignores_legacy_same_role_pending(self):
|
||||
task = self._allocated()
|
||||
bind_task = DouyuTask(
|
||||
|
||||
Reference in New Issue
Block a user