Skip to content

Added subscription lifecycle e2e tests for Stripe webhooks#26810

Merged
9larsons merged 2 commits intomainfrom
add-stripe-subscription-lifecycle-e2e
Mar 17, 2026
Merged

Added subscription lifecycle e2e tests for Stripe webhooks#26810
9larsons merged 2 commits intomainfrom
add-stripe-subscription-lifecycle-e2e

Conversation

@9larsons
Copy link
Copy Markdown
Contributor

Summary

  • 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

Test plan

  • All 4 Stripe webhook tests pass locally (yarn test tests/admin/members/stripe-webhooks.test.ts)
  • TypeScript types check (yarn test:types)
  • Linting passes (yarn lint)

- 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
@9larsons 9larsons marked this pull request as draft March 12, 2026 18:49
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8f0d58d4-5b42-4e94-a6f9-97d9ef190ae7

📥 Commits

Reviewing files that changed from the base of the PR and between 46d6043 and e0745f7.

📒 Files selected for processing (2)
  • e2e/helpers/services/stripe/fake-stripe-server.ts
  • e2e/tests/admin/members/stripe-webhooks.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/tests/admin/members/stripe-webhooks.test.ts

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main focus of the changeset: adding e2e tests for Stripe webhook subscription lifecycle flows.
Description check ✅ Passed The description is directly related to the changeset, outlining the tests added, service extensions, and test plan with verification steps.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-stripe-subscription-lifecycle-e2e
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9955ebb and 46d6043.

📒 Files selected for processing (6)
  • e2e/helpers/services/members/members-service.ts
  • e2e/helpers/services/stripe/builders.ts
  • e2e/helpers/services/stripe/fake-stripe-server.ts
  • e2e/helpers/services/stripe/index.ts
  • e2e/helpers/services/stripe/stripe-service.ts
  • e2e/tests/admin/members/stripe-webhooks.test.ts

@9larsons
Copy link
Copy Markdown
Contributor Author

9larsons commented Mar 17, 2026

Picked up the test nit and folded in two follow-ups while I was there:

  • added a subscription length assertion before dereferencing member.subscriptions[0] in the cancel-at-period-end test
  • fixed the fake Stripe subscription route to read Stripe's indexed expand query encoding (expand[0]=...), not just expand[]
  • tightened the invoice webhook test so it waits for the resulting payment_event instead of only re-checking the already-paid member status

ref #26810

Aligned fake Stripe expand parsing with stripe-node and verified invoice payments via member activity events.
@9larsons 9larsons marked this pull request as ready for review March 17, 2026 13:04
@9larsons 9larsons merged commit 541449f into main Mar 17, 2026
28 checks passed
@9larsons 9larsons deleted the add-stripe-subscription-lifecycle-e2e branch March 17, 2026 14:05
9larsons added a commit that referenced this pull request Mar 17, 2026
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.
9larsons added a commit that referenced this pull request Mar 17, 2026
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.
9larsons added a commit that referenced this pull request Mar 17, 2026
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.
9larsons added a commit that referenced this pull request Mar 17, 2026
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.
9larsons added a commit that referenced this pull request Mar 17, 2026
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.
9larsons added a commit that referenced this pull request Mar 18, 2026
ref #26810

This adds the fake Stripe product, price, customer, and checkout-session surface needed to start migrating paid signup browser coverage into e2e.
franky19 pushed a commit to franky19/Ghost that referenced this pull request Apr 18, 2026
…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
franky19 pushed a commit to franky19/Ghost that referenced this pull request Apr 18, 2026
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.
franky19 pushed a commit to franky19/Ghost that referenced this pull request Apr 18, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant