fix(billing): address code review - remove duplicate mode logic, accessibility improvements, robust test assertions
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -306,8 +306,6 @@ async def stripe_status(request: Request, db: Session = Depends(get_db)) -> dict
|
|||||||
connection_status = "ok"
|
connection_status = "ok"
|
||||||
try:
|
try:
|
||||||
account = client.accounts.retrieve("me") # type: ignore[arg-type]
|
account = client.accounts.retrieve("me") # type: ignore[arg-type]
|
||||||
mode = "live" if getattr(account, "livemode", True) is not False else "test"
|
|
||||||
# stripe returns livemode=False in test mode
|
|
||||||
livemode = getattr(account, "livemode", None)
|
livemode = getattr(account, "livemode", None)
|
||||||
if livemode is True:
|
if livemode is True:
|
||||||
mode = "live"
|
mode = "live"
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
@click="currentStep = i"
|
@click="currentStep = i"
|
||||||
class="flex items-center focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-indigo-400 rounded"
|
class="flex items-center focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-indigo-400 rounded"
|
||||||
:aria-current="currentStep === i ? 'step' : null"
|
:aria-current="currentStep === i ? 'step' : null"
|
||||||
|
:aria-label="'Step ' + (i + 1) + ': ' + step.title"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="w-8 h-8 rounded-full flex items-center justify-center text-sm font-semibold border-2 transition"
|
class="w-8 h-8 rounded-full flex items-center justify-center text-sm font-semibold border-2 transition"
|
||||||
@@ -139,7 +140,8 @@
|
|||||||
|
|
||||||
<!-- Plan grid -->
|
<!-- Plan grid -->
|
||||||
<div x-show="status && status.plans && status.plans.length > 0">
|
<div x-show="status && status.plans && status.plans.length > 0">
|
||||||
<table class="min-w-full text-sm divide-y divide-gray-200" aria-label="Plan sync status">
|
<table class="min-w-full text-sm divide-y divide-gray-200">
|
||||||
|
<caption class="sr-only">Plan sync status</caption>
|
||||||
<thead class="bg-gray-50">
|
<thead class="bg-gray-50">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Plan</th>
|
<th scope="col" class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Plan</th>
|
||||||
@@ -300,7 +302,7 @@
|
|||||||
|
|
||||||
<!-- Local testing -->
|
<!-- Local testing -->
|
||||||
<details class="border border-gray-200 rounded-md">
|
<details class="border border-gray-200 rounded-md">
|
||||||
<summary class="px-4 py-3 text-sm font-medium text-gray-700 cursor-pointer hover:bg-gray-50">
|
<summary class="px-4 py-3 text-sm font-medium text-gray-700 cursor-pointer hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-indigo-400 rounded-md">
|
||||||
<i class="fas fa-terminal mr-1" aria-hidden="true"></i> Local testing with Stripe CLI
|
<i class="fas fa-terminal mr-1" aria-hidden="true"></i> Local testing with Stripe CLI
|
||||||
</summary>
|
</summary>
|
||||||
<div class="px-4 pb-4 pt-2 bg-gray-50 rounded-b-md">
|
<div class="px-4 pb-4 pt-2 bg-gray-50 rounded-b-md">
|
||||||
|
|||||||
@@ -664,12 +664,11 @@ def test_stripe_sync_plans_creates_prices(bill_client, bill_session):
|
|||||||
assert db_plan.stripe_price_id_monthly == "price_monthly_pro_new"
|
assert db_plan.stripe_price_id_monthly == "price_monthly_pro_new"
|
||||||
assert db_plan.stripe_price_id_yearly == "price_yearly_pro_new"
|
assert db_plan.stripe_price_id_yearly == "price_yearly_pro_new"
|
||||||
|
|
||||||
# Verify correct amounts were passed to Stripe
|
# Verify correct amounts were passed to Stripe, matching by interval (order-independent)
|
||||||
price_calls = mock_client.prices.create.call_args_list
|
price_calls = mock_client.prices.create.call_args_list
|
||||||
assert price_calls[0][1]["params"]["unit_amount"] == 1900 # $19.00 → 1900 cents
|
by_interval = {call[1]["params"]["recurring"]["interval"]: call[1]["params"] for call in price_calls}
|
||||||
assert price_calls[1][1]["params"]["unit_amount"] == 19000 # $190.00 → 19000 cents
|
assert by_interval["month"]["unit_amount"] == 1900 # $19.00 → 1900 cents
|
||||||
assert price_calls[0][1]["params"]["recurring"]["interval"] == "month"
|
assert by_interval["year"]["unit_amount"] == 19000 # $190.00 → 19000 cents
|
||||||
assert price_calls[1][1]["params"]["recurring"]["interval"] == "year"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
|
|||||||
Reference in New Issue
Block a user