fix(douyu): 拆分账号资格活动窗口与库存语义
This commit is contained in:
@@ -34,10 +34,12 @@ def test_classify_goods_item_keeps_unknown_when_status_missing():
|
||||
limited, reason, raw = service.classify_goods_item({"status": "1"})
|
||||
assert (limited, reason, raw) == ("limited", "该账号已达此商品兑换上限", "1")
|
||||
|
||||
no_stock, reason, _ = service.classify_goods_item(
|
||||
{"status": 0, "storeStatus": 0}
|
||||
sold_out = service.classify_goods_item_assessment(
|
||||
{"status": 0, "storeStatus": 0, "count": 0}
|
||||
)
|
||||
assert (no_stock, reason) == ("no_stock", "官方商城当前无库存")
|
||||
assert sold_out.account_eligibility == "eligible"
|
||||
assert sold_out.stock_state == "out_of_stock"
|
||||
assert sold_out.availability == "no_stock"
|
||||
|
||||
unknown, reason, raw = service.classify_goods_item({})
|
||||
assert unknown == "unknown"
|
||||
@@ -62,13 +64,22 @@ def test_time_limited_goods_use_schedule_before_account_limit():
|
||||
assert availability == "limited"
|
||||
assert "上限" in reason
|
||||
|
||||
future = {
|
||||
future_limited = {
|
||||
"status": "1",
|
||||
"timeLimited": 1,
|
||||
"startTime": str(int((NOW + timedelta(hours=2)).timestamp())),
|
||||
"endTime": str(int((NOW + timedelta(hours=3)).timestamp())),
|
||||
}
|
||||
availability, reason, _ = service.classify_goods_item(future, now=NOW)
|
||||
availability, reason, _ = service.classify_goods_item(future_limited, now=NOW)
|
||||
assert availability == "limited"
|
||||
assert "上限" in reason
|
||||
|
||||
future_eligible = {**future_limited, "status": "0"}
|
||||
assessment = service.classify_goods_item_assessment(future_eligible, now=NOW)
|
||||
availability = assessment.availability
|
||||
reason = assessment.blocking_reason
|
||||
assert assessment.account_eligibility == "eligible"
|
||||
assert assessment.offer_state == "before"
|
||||
assert availability == "not_open"
|
||||
assert "未开始" in reason
|
||||
|
||||
@@ -83,6 +94,38 @@ def test_time_limited_goods_use_schedule_before_account_limit():
|
||||
assert "已结束" in reason
|
||||
|
||||
|
||||
def test_har_account_limit_is_independent_of_positive_global_stock():
|
||||
rabbit = {
|
||||
"commodityId": "20260120QYOOB_bag10",
|
||||
"status": 1,
|
||||
"storeStatus": 1,
|
||||
"openStatus": 1,
|
||||
"count": 76968,
|
||||
}
|
||||
|
||||
assessment = service.classify_goods_item_assessment(rabbit, now=NOW)
|
||||
|
||||
assert assessment.account_eligibility == "limited"
|
||||
assert assessment.stock_state == "in_stock"
|
||||
assert assessment.availability == "limited"
|
||||
|
||||
|
||||
def test_har_zero_global_stock_does_not_change_account_eligibility():
|
||||
red_bear = {
|
||||
"commodityId": "20260120QYOOB_bag395",
|
||||
"status": 0,
|
||||
"storeStatus": 0,
|
||||
"openStatus": 1,
|
||||
"count": 0,
|
||||
}
|
||||
|
||||
assessment = service.classify_goods_item_assessment(red_bear, now=NOW)
|
||||
|
||||
assert assessment.account_eligibility == "eligible"
|
||||
assert assessment.stock_state == "out_of_stock"
|
||||
assert assessment.availability == "no_stock"
|
||||
|
||||
|
||||
def test_sync_stores_time_window_and_next_boundary(db):
|
||||
account = _account(db, "cap-window")
|
||||
end_at = NOW + timedelta(minutes=5)
|
||||
@@ -163,6 +206,8 @@ def test_sync_account_goods_states_writes_capabilities_and_exchange_stats(db):
|
||||
assert states["A"].last_exchange_at == NOW - timedelta(days=10)
|
||||
assert states["B"].availability == "limited"
|
||||
assert states["C"].availability == "no_stock"
|
||||
assert states["C"].account_eligibility == "eligible"
|
||||
assert states["C"].stock_state == "out_of_stock"
|
||||
assert states["D"].availability == "unknown"
|
||||
assert states["A"].valid_until == NOW + timedelta(
|
||||
seconds=service.capability_ttl_seconds("available")
|
||||
@@ -295,6 +340,7 @@ def test_account_commodities_api_returns_summary_and_freshness(db):
|
||||
account.id,
|
||||
scope="",
|
||||
availability="",
|
||||
eligibility="",
|
||||
limit=500,
|
||||
db=db,
|
||||
current=user,
|
||||
|
||||
Reference in New Issue
Block a user