mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
- 新增钱包余额管理、充值、扣费、退款完整流程 - 新增支付网关抽象层(支持手动/支付宝/微信) - 用量计费从配额系统迁移到钱包余额扣费 - 新增管理员钱包管理与支付订单管理页面 - 新增用户钱包中心页面 - 移除独立 Key 锁定机制,统一由钱包余额控制 - 新增相关 API 路由、序列化器与数据库迁移 - 新增钱包、支付、退款相关测试
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
from decimal import Decimal
|
|
from types import SimpleNamespace
|
|
|
|
from src.api.serializers.wallet_payment import serialize_admin_wallet, serialize_wallet_transaction
|
|
|
|
|
|
def test_serialize_wallet_transaction_emits_split_balance_numbers() -> None:
|
|
tx = SimpleNamespace(
|
|
id="tx-1",
|
|
category="adjust",
|
|
reason_code="adjust_admin",
|
|
amount=Decimal("1.25"),
|
|
balance_before=Decimal("5.00"),
|
|
balance_after=Decimal("6.25"),
|
|
recharge_balance_before=Decimal("2.00"),
|
|
recharge_balance_after=Decimal("3.25"),
|
|
gift_balance_before=Decimal("3.00"),
|
|
gift_balance_after=Decimal("3.00"),
|
|
link_type="admin_action",
|
|
link_id="wallet-1",
|
|
operator_id="admin-1",
|
|
description="test",
|
|
created_at="2026-03-07T00:00:00Z",
|
|
)
|
|
|
|
payload = serialize_wallet_transaction(tx)
|
|
|
|
assert payload["recharge_balance_before"] == 2.0
|
|
assert payload["recharge_balance_after"] == 3.25
|
|
assert payload["gift_balance_before"] == 3.0
|
|
assert payload["gift_balance_after"] == 3.0
|
|
|
|
|
|
def test_serialize_admin_wallet_omits_version(monkeypatch) -> None:
|
|
wallet = SimpleNamespace(
|
|
id="wallet-1",
|
|
user_id="user-1",
|
|
api_key_id=None,
|
|
user=SimpleNamespace(username="alice"),
|
|
api_key=None,
|
|
created_at="2026-03-07T00:00:00Z",
|
|
)
|
|
|
|
monkeypatch.setattr(
|
|
"src.api.serializers.wallet_payment.WalletService.serialize_wallet_summary",
|
|
lambda _wallet: {
|
|
"balance": 10.0,
|
|
"recharge_balance": 7.0,
|
|
"gift_balance": 3.0,
|
|
"refundable_balance": 7.0,
|
|
"currency": "USD",
|
|
"status": "active",
|
|
"limit_mode": "finite",
|
|
"unlimited": False,
|
|
"total_recharged": 10.0,
|
|
"total_consumed": 0.0,
|
|
"total_refunded": 0.0,
|
|
"total_adjusted": 0.0,
|
|
"updated_at": "2026-03-07T00:00:00Z",
|
|
},
|
|
)
|
|
|
|
payload = serialize_admin_wallet(wallet)
|
|
|
|
assert "version" not in payload
|
|
assert payload["owner_name"] == "alice"
|