mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 01:17:46 +08:00
fix(admin): floor batch deductions at zero
This commit is contained in:
@@ -226,7 +226,11 @@ impl AppState {
|
||||
let before_gift = wallet.gift_balance;
|
||||
let before_total = before_recharge + before_gift;
|
||||
let amount_usd = if clamp_deduction_to_available_balance && amount_usd < 0.0 {
|
||||
-(-amount_usd).min(before_total.max(0.0))
|
||||
if before_total < 0.0 {
|
||||
-before_total
|
||||
} else {
|
||||
-(-amount_usd).min(before_total)
|
||||
}
|
||||
} else {
|
||||
amount_usd
|
||||
};
|
||||
|
||||
@@ -581,7 +581,7 @@ async fn gateway_reports_wallet_limit_lookup_failure_as_unprocessed() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn gateway_reports_missing_wallet_and_skips_zero_delta_for_non_positive_balance() {
|
||||
async fn gateway_reports_missing_wallet_and_floors_negative_balance_on_deduction() {
|
||||
let state = AppState::new()
|
||||
.expect("gateway should build")
|
||||
.with_auth_users_for_tests([sample_user("user-negative"), sample_user("user-no-wallet")])
|
||||
@@ -607,8 +607,8 @@ async fn gateway_reports_missing_wallet_and_skips_zero_delta_for_non_positive_ba
|
||||
assert_eq!(result["failures"][0]["reason"], "用户钱包不可用");
|
||||
|
||||
let wallet = wallet_detail(&client, &gateway_url, "user-negative").await;
|
||||
assert_eq!(wallet["balance"], -1.0);
|
||||
assert_eq!(wallet["total_adjusted"], 0.0);
|
||||
assert_eq!(wallet["balance"], 0.0);
|
||||
assert_eq!(wallet["total_adjusted"], 1.0);
|
||||
|
||||
gateway_handle.abort();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user