mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
fix(e2e): fill Stripe Checkout name + ZIP fields (daily E2E false alarm) (#945)
## Problem The daily **E2E Daily Test — Stage 1: Credit Purchase** (run #146) fired the Discord alert *"🚨 Payment flow is broken. Customers may not be receiving credits."* on all 3 retries. This was **test drift, not a production outage.** Stripe's hosted Checkout now renders **required** *Name on card* and *ZIP code* fields, but the test helper's fill locators no longer matched their current accessible names, so both were left blank. Stripe blocked the "Pay" click (`Please provide the name on your card` / `Your ZIP code is invalid`), the page never redirected, and the 60s `waitForURL` timed out. Root cause confirmed from the failed run's `error-context.md` + `test-failed-1.png` (both validation errors visible on the stuck Checkout page). Prod `/api/health` was healthy throughout, and real customers fill these fields themselves — so checkout is unaffected. ## Fix (`frontend/e2e/helpers/stripe-checkout.ts`, test-only) - **Name** locator now matches `/name on card|cardholder name/i`, placeholder `First and last name`, and `[data-elements-stable-field-name="billingName"]`. - **ZIP** locator drops the broken `^zip$` anchor (the accessible name is "ZIP code") → `/zip|postal code/i`. - Bumped the too-short 2s field-search timeouts to 8s; added WARNING logs when a field isn't found. - Defaulted the cardholder name so a missing/empty secret can't silently reblank it. ## Verification Ran `credit-purchase-real.spec.ts` against **production with a real $3 charge**: checkout completed, redirected to **"Payment Successful · 2 credits available"**, and the *"1 credits added"* confirmation email arrived. Old locator regexes tested `false` against the real snapshot strings; new ones test `true`. Typecheck clean. CodeRabbit local review: no findings. > Note: a ~600s "Test timeout exceeded" seen locally *after* the body passes is an environmental macOS teardown quirk (production config uses `trace:'on'`+`video:'on'`), reproducible with a bare navigate-and-close test — it does not occur on CI's Ubuntu runners. @coderabbitai ignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
714f3d2ae6
commit
79b7c80264
1 file changed
+28
-9
@@ -48,7 +48,9 @@ function getCardDetailsFromEnv(): CardDetails {
|
||||
);
|
||||
}
|
||||
|
||||
return { number, expiry, cvc, name };
|
||||
// Default the name so a missing/empty secret can't leave the (now required)
|
||||
// "Name on card" field blank and get the Pay click rejected.
|
||||
return { number, expiry, cvc, name: name || 'E2E Test' };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,34 +157,51 @@ export async function completeStripeCheckout(page: Page): Promise<void> {
|
||||
console.log(' Filling CVC...');
|
||||
await fillCardField(page, 'cardCvc', card.cvc);
|
||||
|
||||
// Step 6: Fill cardholder name if the field exists (any frame)
|
||||
// Step 6: Fill cardholder name if the field exists (any frame).
|
||||
// Stripe renames/relabels this field across layouts — we've seen the
|
||||
// accessible name be "Cardholder name", "Name on card", or "Full name on
|
||||
// card", and the placeholder be "Full name on card" or "First and last
|
||||
// name". Match all known variants so an empty name field can't silently
|
||||
// block the Pay button (which produced a false "payment broken" alarm — the
|
||||
// Pay click was rejected with "Please provide the name on your card").
|
||||
if (card.name) {
|
||||
const nameInput = await locateVisibleInFrames(
|
||||
page,
|
||||
(f) =>
|
||||
f
|
||||
.locator('#billingName, input[name="billingName"], input[placeholder="Full name on card"]')
|
||||
.or(f.getByRole('textbox', { name: /cardholder name/i })),
|
||||
2_000
|
||||
.locator(
|
||||
'[data-elements-stable-field-name="billingName"], #billingName, input[name="billingName"], input[placeholder="Full name on card"], input[placeholder="First and last name"]'
|
||||
)
|
||||
.or(f.getByRole('textbox', { name: /name on card|cardholder name/i })),
|
||||
8_000
|
||||
);
|
||||
if (nameInput) {
|
||||
console.log(' Filling cardholder name...');
|
||||
await nameInput.fill(card.name);
|
||||
} else {
|
||||
console.log(' WARNING: cardholder name field not found — Pay may be rejected');
|
||||
}
|
||||
}
|
||||
|
||||
// Step 6b: Fill ZIP code (required for US cards) — search any frame
|
||||
// Step 6b: Fill ZIP code (required for US cards) — search any frame.
|
||||
// The accessible name is "ZIP code" (not exactly "ZIP"), so the regex must
|
||||
// not anchor to ^zip$. Placeholder is often absent, so rely on the stable
|
||||
// field name / accessible name too.
|
||||
const zipInput = await locateVisibleInFrames(
|
||||
page,
|
||||
(f) =>
|
||||
f
|
||||
.locator('#billingPostalCode, input[name="billingPostalCode"], input[placeholder="ZIP"]')
|
||||
.or(f.getByRole('textbox', { name: /^zip$|postal code/i })),
|
||||
2_000
|
||||
.locator(
|
||||
'[data-elements-stable-field-name="billingPostalCode"], #billingPostalCode, input[name="billingPostalCode"], input[placeholder="ZIP"]'
|
||||
)
|
||||
.or(f.getByRole('textbox', { name: /zip|postal code/i })),
|
||||
8_000
|
||||
);
|
||||
if (zipInput) {
|
||||
console.log(' Filling ZIP code...');
|
||||
await zipInput.fill(process.env.E2E_STRIPE_ZIP || '10001');
|
||||
} else {
|
||||
console.log(' WARNING: ZIP code field not found — Pay may be rejected');
|
||||
}
|
||||
|
||||
// Step 6c: Uncheck "Save my information" to avoid a phone-number requirement
|
||||
|
||||
Reference in new issue
Block a user