feat(douyu): 拆分鱼翅积分与兑换记录查询

This commit is contained in:
yml2213
2026-10-23 10:42:42 +08:00
parent 2c87deed78
commit 2de5d374df
5 changed files with 359 additions and 105 deletions
+98
View File
@@ -19,6 +19,8 @@ class FakeClient:
self.points = points
self.fish = fish
self.records = records if records is not None else []
self.records_calls = 0
self.orders_calls = 0
def elite_user_info(self, **_):
return {
@@ -55,9 +57,11 @@ class FakeClient:
}
def exchange_records(self, **_):
self.records_calls += 1
return {"records": self.records}
def exchange_orders(self, **_):
self.orders_calls += 1
return {"orders": []}
@@ -215,6 +219,96 @@ class TestDouyuCollabOrders:
assert result["points_reason"] == "shortage"
assert result["order"].status == collab.STATUS_POINTS_ERROR
def test_balance_query_skips_records_and_never_changes_status(self):
order = collab.create_order(
self.session,
self.admin,
order_no="DY-106",
shop="店铺A",
account_username="douyu-account-a",
gift_name="礼包A",
required_points=100,
home_images=["collab/home-5.png"],
client=FakeClient(),
)
collab.set_status(
self.session,
self.admin,
order,
status=collab.STATUS_RECHARGED,
reason="鱼翅已充值",
)
order.points_threshold = 10
self.session.commit()
client = FakeClient(points=50, records=[{"commodityName": "礼包A"}])
result = collab.query_activity(
self.session,
self.admin,
order,
client=client,
source="balance_batch",
include_records=False,
)
assert client.records_calls == 0
assert client.orders_calls == 0
assert result["scope"] == "balances"
assert result["verdict"] == collab.VERDICT_UNKNOWN
assert result["points_reason"] == "shortage"
assert result["order"].status == collab.STATUS_RECHARGED
assert result["metric"].source == "balance_batch"
assert result["metric"].records_total == 0
def test_balance_query_keeps_last_exchange_verdict_visible(self):
order = collab.create_order(
self.session,
self.admin,
order_no="DY-107",
shop="店铺A",
account_username="douyu-account-a",
gift_name="礼包A",
required_points=100,
home_images=["collab/home-6.png"],
client=FakeClient(),
)
collab.set_status(
self.session,
self.admin,
order,
status=collab.STATUS_RECHARGED,
reason="鱼翅已充值",
)
collab.set_status(
self.session,
self.admin,
order,
status=collab.STATUS_SCRIPTED,
reason="脚本已上",
)
record_result = collab.query_activity(
self.session,
self.admin,
order,
client=FakeClient(records=[{"commodityName": "礼包A"}]),
)
assert record_result["order"].status == collab.STATUS_DONE
collab.query_activity(
self.session,
self.admin,
order,
client=FakeClient(),
source="balance_batch",
include_records=False,
)
payload = collab.serialize_one(self.session, order)
assert payload["status"] == collab.STATUS_DONE
assert payload["last_verdict"] == collab.VERDICT_SUCCESS
assert payload["last_records_matched"] == 1
assert payload["last_metric_message"] == "仅查询鱼翅与积分,未查询兑换记录"
def test_draft_can_be_created_before_account_resolution(self):
order = collab.create_order(
self.session,
@@ -579,6 +673,10 @@ class TestDouyuCollabOrders:
assert "/api/douyu/external-orders/ck/export" in paths
assert "/api/douyu/external-orders/{order_id}/ck/copy" in paths
assert "/api/douyu/external-orders/usernames/export" in paths
assert "/api/douyu/external-orders/balances/query" in paths
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/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}"]