发布(0.4.6): 修复预售兑换记录判定与详情展示并新增工作台强制发放
This commit is contained in:
@@ -1830,7 +1830,7 @@ class TestDouyuCollabOrders:
|
||||
old_record = exchange_record(occurred_at=datetime.now(UTC) - timedelta(days=1))
|
||||
wrong_commodity = exchange_record(
|
||||
commodity_id="gift-other",
|
||||
name="礼包A",
|
||||
name="礼包B",
|
||||
)
|
||||
|
||||
result = collab.query_activity(
|
||||
@@ -2465,6 +2465,8 @@ class TestDouyuCollabOrders:
|
||||
assert "/api/douyu/external-orders/{order_id}/balances/query" in paths
|
||||
assert "/api/douyu/external-orders/activity/query" in paths
|
||||
assert "/api/douyu/external-orders/{order_id}/activity/query" in paths
|
||||
assert "/api/douyu/external-orders/{order_id}/exchange-records" in paths
|
||||
assert "/api/douyu/external-orders/{order_id}/exchange-records/query" in paths
|
||||
assert "/api/douyu/collab-shops/{shop_id}" in paths
|
||||
assert "put" in paths["/api/douyu/collab-shops/{shop_id}"]
|
||||
assert "delete" in paths["/api/douyu/collab-shops/{shop_id}"]
|
||||
@@ -2640,3 +2642,94 @@ class TestDouyuCollabOrders:
|
||||
reason="角色不一致时也不能强行完成",
|
||||
)
|
||||
assert rollback_exc.value.code == "role_mismatch"
|
||||
|
||||
def test_record_query_matches_rotated_commodity_id_by_name_and_lists_records(self):
|
||||
"""活动商品改过 ID(如 bag346 -> bag413)时,同名且同角色/时间命中仍应判成功并可在详情展示。"""
|
||||
from web.backend.models import DouyuGoodsSnapshot
|
||||
|
||||
now = datetime.now(UTC)
|
||||
self.session.add_all(
|
||||
[
|
||||
DouyuGoodsSnapshot(
|
||||
commodity_id="20260120QYOOB_bag346",
|
||||
name="冥河战士大礼包",
|
||||
score=8000,
|
||||
updated_at=now - timedelta(days=10),
|
||||
),
|
||||
DouyuGoodsSnapshot(
|
||||
commodity_id="20260120QYOOB_bag413",
|
||||
name="冥河战士大礼包",
|
||||
score=8000,
|
||||
updated_at=now - timedelta(hours=1),
|
||||
),
|
||||
]
|
||||
)
|
||||
self.session.commit()
|
||||
|
||||
# 解析礼包名应优先选用最新快照 bag413
|
||||
_, resolved_cid, resolved_points = collab._resolve_gift(
|
||||
self.session,
|
||||
gift_name="冥河战士大礼包",
|
||||
commodity_id="",
|
||||
required_points=None,
|
||||
)
|
||||
assert resolved_cid == "20260120QYOOB_bag413"
|
||||
assert resolved_points == 8000
|
||||
|
||||
# 模拟历史已保存旧 ID bag346 的订单,遇上官方返回的 bag413 兑换记录
|
||||
order = collab.create_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
order_no="2631901603397968",
|
||||
shop="店铺A",
|
||||
account_username="douyu-account-a",
|
||||
gift_name="冥河战士大礼包",
|
||||
commodity_id="20260120QYOOB_bag346",
|
||||
required_points=8000,
|
||||
home_images=["collab/home-rotated-cid.png"],
|
||||
client=FakeClient(),
|
||||
)
|
||||
for status in (collab.STATUS_RECHARGED, collab.STATUS_SCRIPTED):
|
||||
collab.set_status(
|
||||
self.session,
|
||||
self.admin,
|
||||
order,
|
||||
status=status,
|
||||
reason="准备测试改 ID 判定",
|
||||
)
|
||||
|
||||
wrong_role_record = {
|
||||
**exchange_record(name="冥河战士大礼包", commodity_id="20260120QYOOB_bag413"),
|
||||
"showName": "其他角色(安卓(android)-微信)",
|
||||
}
|
||||
matched_record = {
|
||||
**exchange_record(name="冥河战士大礼包", commodity_id="20260120QYOOB_bag413"),
|
||||
"showName": "角色A(苹果(iOS)-微信)",
|
||||
"score": "8000",
|
||||
}
|
||||
|
||||
detail_records = collab.list_order_exchange_records(
|
||||
self.session,
|
||||
self.admin,
|
||||
order,
|
||||
refresh=True,
|
||||
client=FakeClient(records=[wrong_role_record, matched_record]),
|
||||
)
|
||||
assert detail_records["total"] == 2
|
||||
assert detail_records["matched_count"] == 1
|
||||
assert [item["match_reason"] for item in detail_records["records"]] == [
|
||||
"角色不一致",
|
||||
"命中本单",
|
||||
]
|
||||
# 详情只读查询不应改动订单状态
|
||||
assert order.status == collab.STATUS_SCRIPTED
|
||||
|
||||
# 正式自动判定应命中 rotated_cid 记录并转为 done
|
||||
result = collab.query_activity(
|
||||
self.session,
|
||||
self.admin,
|
||||
order,
|
||||
client=FakeClient(records=[matched_record]),
|
||||
)
|
||||
assert result["verdict"] == collab.VERDICT_SUCCESS
|
||||
assert result["order"].status == collab.STATUS_DONE
|
||||
|
||||
Reference in New Issue
Block a user