From b435814826fd65ea39b2a37b0d1f63169393e765 Mon Sep 17 00:00:00 2001 From: majdyz Date: Wed, 15 Apr 2026 13:09:47 +0700 Subject: [PATCH] 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. --- .../api/features/subscription_routes_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/autogpt_platform/backend/backend/api/features/subscription_routes_test.py b/autogpt_platform/backend/backend/api/features/subscription_routes_test.py index 2a25482002..b0e20a5e19 100644 --- a/autogpt_platform/backend/backend/api/features/subscription_routes_test.py +++ b/autogpt_platform/backend/backend/api/features/subscription_routes_test.py @@ -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")