fix(marquee): 首页轮播脱敏名改为按 user_id 恒定 + 去 Faker 依赖 (#49)
Co-authored-by: OuYingJun1024 <1034284404@qq.com> Reviewed-on: #49 Co-authored-by: ouzhou <ouzhou@wonderable.ai> Co-committed-by: ouzhou <ouzhou@wonderable.ai>
This commit was merged in pull request #49.
This commit is contained in:
@@ -136,6 +136,102 @@ def test_grant_zero_rejected(admin_client: TestClient, finance_token: str) -> No
|
||||
assert r.status_code == 400
|
||||
|
||||
|
||||
def test_set_coins_writes_delta_txn(admin_client: TestClient, finance_token: str) -> None:
|
||||
"""set 模式:先有余额,再设为目标值,只写一笔差值流水,审计带 mode/target/before。"""
|
||||
uid = _seed_user("13900000009")
|
||||
# 先增到 300
|
||||
admin_client.post(
|
||||
f"/admin/api/users/{uid}/coins", json={"amount": 300, "reason": "底"},
|
||||
headers=_auth(finance_token),
|
||||
)
|
||||
# 设为 100 → 差值 -200(扣减)
|
||||
r = admin_client.post(
|
||||
f"/admin/api/users/{uid}/coins", json={"mode": "set", "amount": 100, "reason": "设值"},
|
||||
headers=_auth(finance_token),
|
||||
)
|
||||
assert r.status_code == 200, r.text
|
||||
db = SessionLocal()
|
||||
try:
|
||||
assert db.get(CoinAccount, uid).coin_balance == 100
|
||||
txns = db.execute(
|
||||
select(CoinTransaction).where(CoinTransaction.user_id == uid)
|
||||
.order_by(CoinTransaction.id.desc())
|
||||
).scalars().all()
|
||||
# 两笔:+300(admin_grant)、-200(admin_deduct)
|
||||
assert txns[0].amount == -200 and txns[0].biz_type == "admin_deduct"
|
||||
logs = db.execute(
|
||||
select(AdminAuditLog).where(
|
||||
AdminAuditLog.action == "user.coins.grant", AdminAuditLog.target_id == str(uid)
|
||||
).order_by(AdminAuditLog.id.desc())
|
||||
).scalars().all()
|
||||
assert logs[0].detail["mode"] == "set"
|
||||
assert logs[0].detail["target"] == 100
|
||||
assert logs[0].detail["before"] == 300
|
||||
assert logs[0].detail["amount"] == -200
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_set_coins_equal_balance_rejected(admin_client: TestClient, finance_token: str) -> None:
|
||||
"""set 为当前余额(差值 0)→ 拒绝,不写流水。"""
|
||||
uid = _seed_user("13900000010")
|
||||
admin_client.post(
|
||||
f"/admin/api/users/{uid}/coins", json={"amount": 50, "reason": "底"},
|
||||
headers=_auth(finance_token),
|
||||
)
|
||||
r = admin_client.post(
|
||||
f"/admin/api/users/{uid}/coins", json={"mode": "set", "amount": 50, "reason": "x"},
|
||||
headers=_auth(finance_token),
|
||||
)
|
||||
assert r.status_code == 400
|
||||
db = SessionLocal()
|
||||
try:
|
||||
txns = db.execute(
|
||||
select(CoinTransaction).where(CoinTransaction.user_id == uid)
|
||||
).scalars().all()
|
||||
assert len(txns) == 1 # 仅初始那笔,设值被拒后无新流水
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_set_coins_negative_target_rejected(admin_client: TestClient, finance_token: str) -> None:
|
||||
uid = _seed_user("13900000011")
|
||||
r = admin_client.post(
|
||||
f"/admin/api/users/{uid}/coins", json={"mode": "set", "amount": -1, "reason": "x"},
|
||||
headers=_auth(finance_token),
|
||||
)
|
||||
assert r.status_code == 400
|
||||
|
||||
|
||||
def test_set_cash_writes_delta_txn(admin_client: TestClient, finance_token: str) -> None:
|
||||
"""现金 set 模式:设为目标分值,写一笔差值流水。"""
|
||||
uid = _seed_user("13900000012")
|
||||
admin_client.post(
|
||||
f"/admin/api/users/{uid}/cash", json={"amount_cents": 500, "reason": "底"},
|
||||
headers=_auth(finance_token),
|
||||
)
|
||||
r = admin_client.post(
|
||||
f"/admin/api/users/{uid}/cash",
|
||||
json={"mode": "set", "amount_cents": 200, "reason": "设值"},
|
||||
headers=_auth(finance_token),
|
||||
)
|
||||
assert r.status_code == 200, r.text
|
||||
db = SessionLocal()
|
||||
try:
|
||||
assert db.get(CoinAccount, uid).cash_balance_cents == 200
|
||||
logs = db.execute(
|
||||
select(AdminAuditLog).where(
|
||||
AdminAuditLog.action == "user.cash.grant", AdminAuditLog.target_id == str(uid)
|
||||
).order_by(AdminAuditLog.id.desc())
|
||||
).scalars().all()
|
||||
assert logs[0].detail["mode"] == "set"
|
||||
assert logs[0].detail["target_cents"] == 200
|
||||
assert logs[0].detail["before_cents"] == 500
|
||||
assert logs[0].detail["amount_cents"] == -300
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
# ===== 封号 =====
|
||||
|
||||
def test_set_user_status_and_audit(admin_client: TestClient, operator_token: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user