feat(avatar): route token recharge through Huihui org orders
This commit is contained in:
@@ -100,6 +100,37 @@ def test_charge_creates_huihui_order_without_early_points(authorization_context)
|
||||
assert "test-callback-secret-123456" not in callback_url
|
||||
|
||||
|
||||
def test_org_recharge_only_credits_after_verified_provider_order(authorization_context):
|
||||
seed()
|
||||
context = authorization_context
|
||||
_enable_huihui_payment_login(context)
|
||||
provider_no = "261016111200090123456"
|
||||
created_data = {"orderNo": provider_no, "chargeType": 9,
|
||||
"chargeAmount": 10, "payStatus": 1}
|
||||
with patch("routers.tokens.HuihuiOrgPaymentClient") as client_factory:
|
||||
provider = client_factory.return_value
|
||||
provider.create_order.return_value = created_data
|
||||
created = client.post(
|
||||
"/api/token/charge/org", headers=context["owner_headers"],
|
||||
json={"planId": "1", "paymentMethod": "wechat", "payScene": "APP"},
|
||||
).json()["data"]
|
||||
assert created["providerOrderNo"] == provider_no
|
||||
assert created["status"] == "pending"
|
||||
assert created["balance"] == DEFAULT_TOKEN_GRANT
|
||||
assert provider.create_order.call_args.kwargs["pay_type"] == 1
|
||||
|
||||
details = {**created_data, "payStatus": 2,
|
||||
"userId": context["owner"].huihui_user_id}
|
||||
provider.get_order.return_value = {**details, "chargeAmount": 9}
|
||||
assert client.get(f"/api/token/payment/{created['id']}", headers=context["owner_headers"]).json()["data"]["status"] == "pending"
|
||||
provider.get_order.return_value = details
|
||||
paid = client.get(f"/api/token/payment/{created['id']}", headers=context["owner_headers"]).json()["data"]
|
||||
assert paid["status"] == "paid"
|
||||
assert paid["balance"] == DEFAULT_TOKEN_GRANT + 2_000_000
|
||||
duplicate = client.get(f"/api/token/payment/{created['id']}", headers=context["owner_headers"]).json()["data"]
|
||||
assert duplicate["balance"] == paid["balance"]
|
||||
|
||||
|
||||
def test_success_callback_credits_once_and_status_is_user_scoped(authorization_context):
|
||||
context = authorization_context
|
||||
_enable_huihui_payment_login(context)
|
||||
|
||||
Reference in New Issue
Block a user