fix(platform-fulfillment): 允许预售单提前绑定账号

This commit is contained in:
yml
2026-11-22 00:45:53 +08:00
parent 0ac6c7e82e
commit 5f5a9a0bbe
4 changed files with 245 additions and 13 deletions
+161
View File
@@ -1252,6 +1252,113 @@ class TestAccountSelection(_Base):
assert detail["task"]["exchangeStatus"] == "not_opened"
assert detail["task"]["issueCode"] == "elite_not_opened"
def test_presale_not_open_allows_allocation_and_advance_binding(self):
account = self.account("presale-future")
task = self.task()
task.sale_mode = "presale"
self.session.commit()
self.refresh_mock.side_effect = lambda _db, row, **_kwargs: (
DouyuLiveAccountState(
account_id=row.id,
account_name=row.username,
checked_at=NOW,
ck_verdict="valid",
ck_message="有效",
elite_opened=True,
points=2000,
limited_ids=frozenset(),
role_change_available_at=None,
commodity_availability={COMMODITY: "not_open"},
commodity_blocking_reasons={
COMMODITY: "限时兑换未开始,开始于 2026-11-26T10:00:00+00:00"
},
)
)
detail = service.allocate_task(
self.session,
task_id=task.id,
current=self.admin,
)
assert detail["task"]["account"]["id"] == account.id
assert detail["task"]["executionStatus"] == "allocated"
assert detail["task"]["exchangeStatus"] == "waiting_release"
assert detail["task"]["issueCode"] == "commodity_not_open"
def test_direct_sale_still_blocks_when_commodity_not_open(self):
self.account("direct-future")
task = self.task()
task.sale_mode = "direct"
self.session.commit()
self.refresh_mock.side_effect = lambda _db, row, **_kwargs: (
DouyuLiveAccountState(
account_id=row.id,
account_name=row.username,
checked_at=NOW,
ck_verdict="valid",
ck_message="有效",
elite_opened=True,
points=2000,
limited_ids=frozenset(),
role_change_available_at=None,
commodity_availability={COMMODITY: "not_open"},
commodity_blocking_reasons={
COMMODITY: "限时兑换未开始,开始于 2026-11-26T10:00:00+00:00"
},
)
)
detail = service.allocate_task(
self.session,
task_id=task.id,
current=self.admin,
)
assert detail["task"]["account"] is None
assert detail["task"]["executionStatus"] == "ready"
assert detail["task"]["issueCode"] == "no_eligible_account"
def test_capability_pool_includes_future_not_open_for_presale_only(self):
account = self.account("capability-future")
self.session.add(
AccountCommodityState(
account_id=account.id,
platform="douyu",
scope="elite",
commodity_id=COMMODITY,
commodity_name=INTERNAL_SKU,
availability="not_open",
blocking_reason="限时兑换未开始",
observed_at=NOW,
valid_until=NOW + timedelta(minutes=15),
available_from=NOW + timedelta(days=4),
available_until=NOW + timedelta(days=10),
source="storehome_sync",
)
)
self.session.commit()
assert (
account_selector.capability_candidate_accounts(
self.session,
commodity_id=COMMODITY,
required_points=1280,
now=NOW,
)
== []
)
assert [
row.id
for row in account_selector.capability_candidate_accounts(
self.session,
commodity_id=COMMODITY,
required_points=1280,
now=NOW,
allow_not_open=True,
)
] == [account.id]
def test_eligible_account_excludes_cooldown_and_uses_least_points(self):
self.account("small", points=1300)
self.account("large", points=9000)
@@ -2486,6 +2593,60 @@ class TestBindingAndCompletion(_Base):
assert detail["task"]["exchangeStatus"] == "points_short"
assert detail["task"]["account"]["id"] == account.id
def test_presale_refresh_after_binding_shows_waiting_release(
self, monkeypatch
):
task = self._allocated()
task.binding_status = "bound"
task.execution_status = "bound"
task.sale_mode = "presale"
self.session.commit()
start_at = NOW + timedelta(days=4)
end_at = NOW + timedelta(days=10)
monkeypatch.setattr(
service,
"probe_account",
lambda *_args, **_kwargs: {
"probe_id": "presale-waiting",
"session": {"status": "valid", "message": "有效"},
"elite": {
"status": "ok",
"raw": {"manual_type": 1},
"manual_type": 1,
"manual_score": 2000,
"opened": True,
},
"eligibility": {
"points": 2000,
"points_response": {"points": 2000},
"limited_ids": [],
"limited_goods": [],
"storehome_goods": [
{
"commodityId": COMMODITY,
"commodityName": INTERNAL_SKU,
"status": "0",
"timeLimited": 1,
"startTime": str(int(start_at.timestamp())),
"endTime": str(int(end_at.timestamp())),
}
],
},
"roles": {},
"errors": {},
},
)
detail = service.refresh_exchange_eligibility(
self.session,
task_id=task.id,
current=self.admin,
)
assert detail["task"]["executionStatus"] == "bound"
assert detail["task"]["exchangeStatus"] == "waiting_release"
assert detail["task"]["issueCode"] == "commodity_not_open"
def test_expired_elite_is_not_currently_opened(self, monkeypatch):
task = self._allocated()
account = (