ordinarthur
4dcd85f912
Build & Deploy Web / build-and-deploy (push) Successful in 26s
Build & Deploy API / build-and-deploy (push) Successful in 1m14s
test(billing): unit tests backend (17) + frontend (7)
Backend (`apps/api/tests/unit/billing.spec.ts`) — 17 tests :
- PLAN_CAPS sanity : Free 5 invoices/1 user, Pro illimité, Business 5 sièges
- countActiveInvoices :
• compte les 4 statuts actifs (pending, awaiting, in_relance, litigation)
• exclut paid + cancelled
• isolation par org (ne fuit pas entre orgs)
- canCreateInvoices :
• Free + grace period → autorisé même à 50+ actives
• Free post-grace + 4 actives + delta=1 → autorisé (≤ limite)
• Free post-grace + 5 actives + delta=1 → BLOQUÉ + bonne raison/limit/current
• Free post-grace + 3 actives + delta=3 → BLOQUÉ (over par batch)
• Pro + Business → toujours autorisé
• paid n'occupe pas de slot (5 paid + delta=5 → autorisé)
- getOrgSubscriptionState :
• inGracePeriod=true quand date future
• inGracePeriod=false quand date passée
• Pro reflète subscription_status / billing_cycle / current_period_end
• activeInvoicesCount inclut bien les 4 statuts
Frontend (`apps/web/src/lib/billing.test.tsx`) — 7 tests :
- useSubscription : appelle /billing/subscription, retourne le state
- useIsAtFreeLimit :
• false en loading
• false sur Pro avec 200 factures
• false en grace period même si activeCount > limit (12)
• true sur Free post-grace + activeCount = limit (5/5)
• true sur Free post-grace + activeCount > limit (8/5)
• false sur Free post-grace + activeCount < limit (4/5)
Setup :
- vitest.config.ts : ajout de `env: {VITE_API_URL, ...}` pour stub
les variables exigées par src/lib/env.ts au chargement (sinon plante
au boot des tests).
- Mock vi.spyOn(api, "get") pour éviter les vraies requêtes HTTP.
- QueryClient avec retry:false pour fail-fast.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-07 16:43:40 +02:00
..
2026-05-07 15:03:28 +02:00
2026-05-06 10:10:48 +02:00
2026-05-07 15:03:28 +02:00
2026-05-07 12:37:20 +02:00
2026-05-07 15:03:28 +02:00
2026-05-06 10:10:48 +02:00
2026-05-07 15:03:28 +02:00
2026-05-07 16:43:40 +02:00
2026-05-06 10:10:48 +02:00
2026-05-06 10:10:48 +02:00
2026-05-07 09:38:38 +02:00
2026-05-06 15:45:11 +02:00
2026-05-07 12:37:20 +02:00
2026-05-06 10:10:48 +02:00
2026-05-06 10:10:48 +02:00
2026-05-07 09:24:27 +02:00
2026-05-06 10:10:48 +02:00
2026-05-07 15:03:28 +02:00
2026-05-06 10:10:48 +02:00