Ajoute une couche end-to-end où un Chromium drive la SPA + API ensemble
contre une DB Postgres séparée, avec Stripe entièrement mocké au niveau
API. 6 scénarios couverts (signup + onboarding + 4 sur le billing trial).
Architecture :
- DB `rubis_test_e2e` séparée, TRUNCATE entre tests (~50 ms reset)
- Routes test-only `/__test__/*` gated par NODE_ENV=test_e2e
(reset, install Stripe mock, fire webhook, lire org state, last-org)
- Stripe mocké via __setStripeForTests — pas d'appel réseau
- Playwright spawn API + SPA automatiquement (webServer config)
- CORS étendu à test_e2e pour le cross-origin localhost:5173 → :3333
Scénarios :
- signup.spec.ts : signup → onboarding 3 étapes → dashboard (assert rubis hero)
- billing-trial.spec.ts :
• démarrer essai 14j → redirect Stripe Checkout (mock)
• fallback Free 2 factures continue l'onboarding
• webhook checkout.completed → org en trialing + trial_ends_at
• retour ?trial=cancel après abandon
• inspection DB : stripeCustomerId posé après start-trial
Scripts :
- pnpm e2e (headless)
- pnpm e2e:headed (Chromium visible)
- pnpm e2e:ui (mode interactif Playwright)
- pnpm e2e:setup (crée + migre rubis_test_e2e via docker exec)
Documentation : docs/tech/e2e-tests.md — architecture, scénarios,
extensions, CI, troubleshooting.
Limites assumées :
- L'UI Stripe Checkout (3DS, formulaire CB) n'est pas testée — externe.
Pour ça : playbook manuel docs/tech/stripe-trial-e2e-playbook.md.
- Le rendu du banner "Essai Pro" n'est pas asserté en E2E à cause de
TanStack Query staleTime — couvert par les tests vitest à la place.
État global du chantier billing : 127 tests japa + 6 Playwright + 11
vitest = couverture multi-niveaux.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
import { resetDb } from './helpers/api'
|
|
|
|
/**
|
|
* Scénario : un user lambda découvre l'app, crée son compte, complète
|
|
* l'onboarding, atterrit sur le dashboard.
|
|
*
|
|
* Ce test ne touche pas à Stripe — il vérifie que la chaîne
|
|
* signup → onboarding → dashboard fonctionne de bout en bout (auth,
|
|
* persistence DB, redirections Tanstack Router, rendu SPA).
|
|
*/
|
|
|
|
test.describe('Signup + onboarding', () => {
|
|
test.beforeEach(async () => {
|
|
await resetDb()
|
|
})
|
|
|
|
test('un user lambda peut créer son compte et arriver sur le dashboard', async ({
|
|
page,
|
|
}) => {
|
|
const email = `alice+${Date.now()}@rubis.test`
|
|
|
|
// 1. Landing → /signup
|
|
await page.goto('/signup')
|
|
await expect(page.getByRole('heading', { name: /créer votre compte/i })).toBeVisible()
|
|
|
|
// 2. Remplir le formulaire signup. Le label est "Prénom / Nom" + email + mdp.
|
|
await page.getByLabel(/Prénom \/ Nom/i).fill('Alice Dupont')
|
|
await page.getByLabel(/Email professionnel/i).fill(email)
|
|
await page.getByLabel(/Mot de passe/i).fill('motdepasse-fort-123')
|
|
await page.getByRole('button', { name: /créer mon compte/i }).click()
|
|
|
|
// 3. Redirige vers onboarding compte
|
|
await expect(page).toHaveURL(/\/onboarding\/compte/)
|
|
await expect(
|
|
page.getByRole('heading', { name: /bienvenue/i }),
|
|
).toBeVisible()
|
|
|
|
// 4. Étape compte : fullName + email déjà préremplis, on continue
|
|
await page.getByRole('button', { name: /continuer/i }).click()
|
|
await expect(page).toHaveURL(/\/onboarding\/entreprise/)
|
|
|
|
// 5. Étape entreprise : nom obligatoire
|
|
await page.getByLabel(/nom de l'entreprise/i).fill('Atelier Alice')
|
|
await page.getByRole('button', { name: /continuer/i }).click()
|
|
await expect(page).toHaveURL(/\/onboarding\/signature/)
|
|
|
|
// 6. Étape signature : on accepte le default
|
|
await page.getByRole('button', { name: /terminer/i }).click()
|
|
|
|
// 7. Arrivée sur le dashboard — pas de H1 strict, on assert sur des
|
|
// signaux stables du dashboard : la phrase "rubis gagnés" du RubisHero
|
|
// + la sidebar (lien Tableau de bord).
|
|
await expect(page).toHaveURL('/')
|
|
await expect(page.getByText(/rubis.*gagnés/i)).toBeVisible({ timeout: 10_000 })
|
|
await expect(page.getByRole('link', { name: /tableau de bord/i })).toBeVisible()
|
|
})
|
|
})
|