feat(fulfillment): 增加工作台状态事件同步
This commit is contained in:
@@ -464,8 +464,15 @@ class TestBindingAndCompletion(_Base):
|
||||
assert task.issue_code == ""
|
||||
assert task.last_error == ""
|
||||
|
||||
def test_refresh_binding_maps_role_ready(self):
|
||||
def test_refresh_binding_maps_role_ready(self, monkeypatch):
|
||||
notified: list[int] = []
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
"notify_order_site_binding_state_async",
|
||||
lambda task_id: notified.append(task_id),
|
||||
)
|
||||
task = self._allocated()
|
||||
notified.clear()
|
||||
bind_task = DouyuTask(
|
||||
batch_id="bind-1",
|
||||
account_id=task.account_id,
|
||||
@@ -487,6 +494,7 @@ class TestBindingAndCompletion(_Base):
|
||||
|
||||
assert detail["task"]["bindingStatus"] == "role_ready"
|
||||
assert detail["task"]["bindTask"]["roleName"] == "测试角色"
|
||||
assert notified == [task.id]
|
||||
|
||||
def test_refresh_binding_clears_stale_failure_when_qr_is_pending(self):
|
||||
task = self._allocated()
|
||||
|
||||
@@ -97,6 +97,10 @@ def test_customer_binding_out_hides_internal_account_data(db):
|
||||
assert "points" not in payload
|
||||
assert "lease" not in payload
|
||||
|
||||
batch = service.customer_refresh_bindings(db, task_ids=[task.id, 999999])
|
||||
assert [item["sessionId"] for item in batch["items"]] == [task.id]
|
||||
assert batch["items"][0]["qrUrl"] == "https://livenlink.example/private-qr-token"
|
||||
|
||||
|
||||
def test_binding_qr_expiry_uses_customer_ttl():
|
||||
now = datetime.now(UTC)
|
||||
@@ -116,3 +120,22 @@ def test_binding_qr_expiry_uses_customer_ttl():
|
||||
task.created_at = now - timedelta(minutes=5)
|
||||
|
||||
assert service._binding_qr_expired(task, now=now) is True
|
||||
|
||||
|
||||
def test_auto_order_sync_is_throttled(monkeypatch):
|
||||
calls: list[int] = []
|
||||
monkeypatch.setattr(service, "_AUTO_SYNC_LAST_ATTEMPT", float("-inf"))
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
"sync_pending_tasks",
|
||||
lambda _db, *, limit: calls.append(limit) or {"fetched": 1},
|
||||
)
|
||||
|
||||
assert service.sync_pending_tasks_if_due(object(), limit=100, now=100.0) == {
|
||||
"fetched": 1
|
||||
}
|
||||
assert service.sync_pending_tasks_if_due(object(), limit=100, now=110.0) is None
|
||||
assert service.sync_pending_tasks_if_due(object(), limit=100, now=161.0) == {
|
||||
"fetched": 1
|
||||
}
|
||||
assert calls == [100, 100]
|
||||
|
||||
Reference in New Issue
Block a user