Added subscription lifecycle e2e tests for Stripe webhooks#26810
Added subscription lifecycle e2e tests for Stripe webhooks#26810
Conversation
- Added cancel, delete, and invoice payment event builders - Enhanced fake Stripe server to support expand[] on subscriptions - Added cancelSubscription, deleteSubscription, sendInvoicePaymentSucceeded service methods - Extended MembersService with getByEmailWithSubscriptions - Added 3 new tests: cancel at period end, delete subscription, invoice payment
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds subscription-aware member types and a new MembersService.getByEmailWithSubscriptions method. Extends Stripe builders with customer.subscription.updated, customer.subscription.deleted, and invoice.payment_succeeded events (including optional previous_attributes and invoice construction). Exposes CreatedPaidMember type and exports new builder functions. Fake Stripe server GET /v1/subscriptions/:id now supports expand[] and expands default_payment_method. Stripe service gains createPaidMemberViaWebhooks return type and new methods to cancel, delete subscriptions and send invoice payment succeeded webhooks. Adds e2e tests for Stripe subscription lifecycle (cancel, delete, payment succeeded). 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
e2e/tests/admin/members/stripe-webhooks.test.ts (1)
29-31: Consider adding a guard for empty subscriptions array.Accessing
member.subscriptions[0]at line 31 without checking array length could cause a confusing test failure if the webhook didn't properly create the subscription. A more defensive assertion would provide clearer failure messages.💡 Suggested improvement
const member = await membersService.getByEmailWithSubscriptions(email); expect(member.status).toBe('paid'); + expect(member.subscriptions).toHaveLength(1); expect(member.subscriptions[0].cancel_at_period_end).toBe(true);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@e2e/tests/admin/members/stripe-webhooks.test.ts` around lines 29 - 31, The test directly accesses member.subscriptions[0] which can throw or cause confusing failures if the subscriptions array is empty; update the assertion sequence in the stripe-webhooks.test to first assert that member.subscriptions is defined and has length > 0 (e.g., expect(member.subscriptions).toBeDefined(); expect(member.subscriptions.length).toBeGreaterThan(0)) before asserting on cancel_at_period_end, and keep the existing call to membersService.getByEmailWithSubscriptions(email) and subsequent assertions (member.status and the subscription field) so the failure message clearly indicates a missing subscription rather than an undefined index.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@e2e/tests/admin/members/stripe-webhooks.test.ts`:
- Around line 29-31: The test directly accesses member.subscriptions[0] which
can throw or cause confusing failures if the subscriptions array is empty;
update the assertion sequence in the stripe-webhooks.test to first assert that
member.subscriptions is defined and has length > 0 (e.g.,
expect(member.subscriptions).toBeDefined();
expect(member.subscriptions.length).toBeGreaterThan(0)) before asserting on
cancel_at_period_end, and keep the existing call to
membersService.getByEmailWithSubscriptions(email) and subsequent assertions
(member.status and the subscription field) so the failure message clearly
indicates a missing subscription rather than an undefined index.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 91ae3b4d-5d65-4f62-9e28-99f91490251c
📒 Files selected for processing (6)
e2e/helpers/services/members/members-service.tse2e/helpers/services/stripe/builders.tse2e/helpers/services/stripe/fake-stripe-server.tse2e/helpers/services/stripe/index.tse2e/helpers/services/stripe/stripe-service.tse2e/tests/admin/members/stripe-webhooks.test.ts
|
Picked up the test nit and folded in two follow-ups while I was there:
|
ref #26810 Aligned fake Stripe expand parsing with stripe-node and verified invoice payments via member activity events.
ref #26810 This moves the admin-generated default, sign-in, and sign-up Portal link coverage into e2e so the browser suite can be trimmed incrementally.
ref #26810 This replaces the low-dependency site settings portal script browser coverage with top-level e2e tests so the old suite can be trimmed incrementally.
ref #26810 - added linter rules around expect and locators This replaces the low-dependency site settings portal script browser coverage with top-level e2e tests so the old suite can be trimmed incrementally.
ref #26810 The fake Stripe helper was binding port 40000 in the Linux ephemeral range, so CI could intermittently hit EADDRINUSE before the server started. Letting the OS assign a free port keeps the helper isolated while still wiring the chosen port back into Ghost.
ref #26810 This moves the admin-generated default, sign-in, and sign-up Portal link coverage into e2e so the browser suite can be trimmed incrementally.
ref #26810 This adds the fake Stripe product, price, customer, and checkout-session surface needed to start migrating paid signup browser coverage into e2e.
…26810) no ref - Added e2e tests for subscription cancellation, deletion, and invoice payment webhook flows - Extended the fake Stripe server to support `expand[]` query params on subscription lookups - Added `cancelSubscription`, `deleteSubscription`, and `sendInvoicePaymentSucceeded` methods to the Stripe test service - Extended `MembersService` with `getByEmailWithSubscriptions` for asserting subscription state
ref TryGhost#26810 - added linter rules around expect and locators This replaces the low-dependency site settings portal script browser coverage with top-level e2e tests so the old suite can be trimmed incrementally.
ref TryGhost#26810 This moves the admin-generated default, sign-in, and sign-up Portal link coverage into e2e so the browser suite can be trimmed incrementally.
Summary
expand[]query params on subscription lookupscancelSubscription,deleteSubscription, andsendInvoicePaymentSucceededmethods to the Stripe test serviceMembersServicewithgetByEmailWithSubscriptionsfor asserting subscription stateTest plan
yarn test tests/admin/members/stripe-webhooks.test.ts)yarn test:types)yarn lint)