Files
karaoke-gen/frontend/e2e/local-stack/payments.spec.ts
T
Andrew Beveridge ☄️andClaude Opus 5.5 c277bc8ee3 feat: local E2E stack (fake workers + test API) + email-code sign-in (v0.275.0) (#1165)
## Summary
- **Local stack:** `scripts/local-stack.sh up --frontend` runs the
**real** backend on the Firestore + GCS emulators with `FAKE_WORKERS=1`.
In-process fake workers move jobs through their real states in seconds,
using tiny real media, so web Playwright and mobile Maestro full-journey
tests can run offline against the same endpoints.
- **Email-code sign-in** (nomad-mobile spec §4.1): `POST
/api/users/auth/send-code` + `verify-code`. The code logic is shared
with kjbox via `LoginCodeStore`, and sends are throttled per email and
per IP.
- **Bug fix found by the new suite:** `confirm-duration` moved jobs to
`separating_stage1`, from which they can never reach review. It now
resumes at `downloading`. No prod job had taken this path yet.

## Changes
- `backend/services/fake_workers/`: dispatch seam in
`WorkerService.trigger_*`, plus fake search, download, checkout and
outbox, scenarios, and per-user config. The real stem upload, transcode,
backing-vocals analysis and preview render are reused. Every check is
strict (`is True`), so a MagicMock settings object never enables the
fakes, and startup **refuses FAKE_WORKERS in production**.
- `/api/test/*` router (mounted only in that mode): `status`,
`scenario`, `fake-config`, `emails`, `reset`, plus the fake Stripe
checkout page. Paying it runs the real webhook handler.
- `frontend/e2e/local-stack/` (9 specs, ~50s):
  - sign-up → make → review → instrumental → download
  - buy and cancel credits
  - duration confirm, failed, complete and review states
  - code sign-in and lockout
- New required CI job `local-stack-e2e`.
- Docs: TESTING.md § Local stack, DEVELOPMENT.md, API.md, README,
LESSONS-LEARNED.
- `MAX_SIGNUPS_PER_IP` can now be set by env. Only the local stack
raises it; production keeps the default of 2.

## Testing
- [x] Backend unit: 6175 passed
- [x] Emulator: 152 passed
- [x] Frontend Jest: 1706 passed
- [x] Local-stack Playwright: 9/9 passed (CI mode)

## Review
- [x] CodeRabbit CLI review completed locally. 1 minor finding declined:
it suggested swallowing infrastructure errors in send-code as fake
"sent" responses, which would hide real outages from users.

@coderabbitai ignore

---
🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01AGuxtgoscF6RJGtpjHPg3W

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 16:00:24 -04:00

47 lines
2.1 KiB
TypeScript

/**
* Buying credits through the (fake) Stripe Checkout. The checkout page is served
* by the local stack, and paying it runs the same completion handler as the real
* Stripe webhook before redirecting to /payment/success.
*/
import { test, expect } from '@playwright/test';
import { scenario, signInAs, waitForEmail } from './stack';
test('user with no credits buys a pack and sees the new balance', async ({ page, request }) => {
const user = await scenario(request, 'user', { credits: 0 });
await signInAs(page, user);
await page.goto('/en/app?buy=1');
const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible();
await dialog.getByRole('button', { name: /^3\s*credits/i }).click();
await dialog.getByRole('button', { name: /continue to payment/i }).click();
await page.waitForURL(/\/api\/test\/fake-checkout\//);
await expect(page.getByTestId('fake-checkout-product')).toHaveText(/3 Karaoke Credits/);
await page.getByTestId('fake-checkout-pay').click();
await page.waitForURL(/\/payment\/success/);
await expect(page.getByRole('heading', { name: /payment successful/i })).toBeVisible();
await expect(page.getByText(/credits available/i)).toBeVisible();
await expect(page.getByText('3', { exact: true })).toBeVisible();
await waitForEmail(request, user.email, /credits added/i);
});
test('cancelling checkout leaves the balance unchanged', async ({ page, request }) => {
const user = await scenario(request, 'user', { credits: 0 });
await signInAs(page, user);
await page.goto('/en/app?buy=1');
const dialog = page.getByRole('dialog');
await dialog.getByRole('button', { name: /^1\s*credit/i }).click();
await dialog.getByRole('button', { name: /continue to payment/i }).click();
await page.waitForURL(/\/api\/test\/fake-checkout\//);
await page.getByTestId('fake-checkout-cancel').click();
await page.waitForURL(/cancelled=true/);
const me = await request.get('/api/users/me', { headers: { Authorization: `Bearer ${user.session_token}` } });
const body = await me.json();
expect((body.user ?? body).credits).toBe(0);
});