fix(admin): 按任务白名单聚合常规金币
This commit is contained in:
@@ -455,3 +455,62 @@ def test_period_coupon_reward_excludes_reward_video(
|
||||
coins = r.json()["period"]["coins"]
|
||||
assert coins["coupon_reward_coin_total"] == 0 # 激励视频不计入领券奖励
|
||||
assert coins["reward_video_coin_total"] == 50 # 仍计入激励视频卡
|
||||
|
||||
|
||||
def test_period_regular_task_coin_uses_explicit_allowlist(
|
||||
admin_client: TestClient, admin_token: str
|
||||
) -> None:
|
||||
"""常规任务金币只加明确任务来源,领券/比价及未知新类型不得自动混入。"""
|
||||
from datetime import datetime
|
||||
|
||||
from app.models.wallet import CoinTransaction
|
||||
|
||||
d = "2021-06-18"
|
||||
included = {
|
||||
"signin": 100,
|
||||
"signin_boost": 200,
|
||||
"task_enable_notification": 300,
|
||||
"task_other": 400,
|
||||
"price_report_reward": 500,
|
||||
"feedback_reward": 600,
|
||||
}
|
||||
excluded = {
|
||||
"feed_ad_reward_coupon": 700,
|
||||
"feed_ad_reward_comparison": 800,
|
||||
"feed_ad_reward": 900,
|
||||
"reward_video": 1000,
|
||||
"admin_grant": 1100,
|
||||
"invite_inviter": 1200,
|
||||
"future_unknown_reward": 1300,
|
||||
}
|
||||
db = SessionLocal()
|
||||
try:
|
||||
uid = user_repo.upsert_user_for_login(
|
||||
db, phone="13800008804", register_channel="sms"
|
||||
).id
|
||||
balance = 0
|
||||
rows = []
|
||||
for index, (biz_type, amount) in enumerate((included | excluded).items(), start=1):
|
||||
balance += amount
|
||||
rows.append(CoinTransaction(
|
||||
user_id=uid,
|
||||
amount=amount,
|
||||
balance_after=balance,
|
||||
biz_type=biz_type,
|
||||
ref_id=f"regular-task-{index}",
|
||||
created_at=datetime(2021, 6, 18, 12, 0, index),
|
||||
))
|
||||
db.add_all(rows)
|
||||
db.commit()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
response = admin_client.get(
|
||||
"/admin/api/stats/overview",
|
||||
params={"date_from": d, "date_to": d},
|
||||
headers=_auth(admin_token),
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
coins = response.json()["period"]["coins"]
|
||||
assert coins["regular_task_coin_total"] == sum(included.values())
|
||||
assert coins["task_coin_total"] == 700
|
||||
|
||||
Reference in New Issue
Block a user