test(backend): mock get_proration_credit_cents in route tests and assert response field

Adds the missing get_proration_credit_cents mock to the three
GET /credits/subscription route tests so they don't attempt a live
Stripe/DB call in unit-test context, and extends assertions to cover
the proration_credit_cents field in the response.
This commit is contained in:
majdyz
2026-04-15 13:09:47 +07:00
parent 10bf830b59
commit b435814826

View File

@@ -111,6 +111,11 @@ def test_get_subscription_status_pro(
"backend.api.features.v1._get_stripe_price_amount",
side_effect=mock_stripe_price_amount,
)
mocker.patch(
"backend.api.features.v1.get_proration_credit_cents",
new_callable=AsyncMock,
return_value=500,
)
response = client.get("/credits/subscription")
@@ -121,6 +126,7 @@ def test_get_subscription_status_pro(
assert data["tier_costs"]["PRO"] == 1999
assert data["tier_costs"]["BUSINESS"] == 0
assert data["tier_costs"]["FREE"] == 0
assert data["proration_credit_cents"] == 500
def test_get_subscription_status_defaults_to_free(
@@ -141,6 +147,11 @@ def test_get_subscription_status_defaults_to_free(
new_callable=AsyncMock,
return_value=None,
)
mocker.patch(
"backend.api.features.v1.get_proration_credit_cents",
new_callable=AsyncMock,
return_value=0,
)
response = client.get("/credits/subscription")
@@ -154,6 +165,7 @@ def test_get_subscription_status_defaults_to_free(
"BUSINESS": 0,
"ENTERPRISE": 0,
}
assert data["proration_credit_cents"] == 0
def test_get_subscription_status_stripe_error_falls_back_to_zero(
@@ -187,6 +199,11 @@ def test_get_subscription_status_stripe_error_falls_back_to_zero(
"backend.api.features.v1._get_stripe_price_amount",
side_effect=mock_stripe_price_amount_none,
)
mocker.patch(
"backend.api.features.v1.get_proration_credit_cents",
new_callable=AsyncMock,
return_value=0,
)
response = client.get("/credits/subscription")