Skip to content

Added e2e tests covering gift subscription purchase flow#27226

Merged
mike182uk merged 1 commit into
mainfrom
BER-3484-add-gift-checkout-e2e-tests
Apr 8, 2026
Merged

Added e2e tests covering gift subscription purchase flow#27226
mike182uk merged 1 commit into
mainfrom
BER-3484-add-gift-checkout-e2e-tests

Conversation

@mike182uk
Copy link
Copy Markdown
Member

ref https://linear.app/ghost/issue/BER-3484

Added additional e2e tests covering gift subscription purchase flow

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

Walkthrough

A new end-to-end test suite was added at ghost/core/test/e2e-api/members/gift-subscriptions.test.js. It provisions member and admin agents, initializes members fixtures, configures Stripe and mail mocks, and enables the giftSubscriptions labs flag. Tests exercise /api/create-stripe-checkout-session/ for anonymous and authenticated gift flows, validate Stripe checkout metadata and the persisted models.Gift records after checkout.session.completed webhooks, assert webhook idempotency, capture negative 400 responses for disabled labs or invalid input, and verify the checkout success_url contains the gift_token.

🚥 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 directly and specifically summarizes the main change: adding e2e tests for the gift subscription purchase flow, which matches the changeset content.
Description check ✅ Passed The description is related to the changeset, clearly stating that it adds e2e tests for the gift subscription purchase flow with a reference to the Linear issue.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BER-3484-add-gift-checkout-e2e-tests

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

@mike182uk mike182uk enabled auto-merge (squash) April 8, 2026 12:43
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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
ghost/core/test/e2e-api/members/gift-subscriptions.test.js (2)

233-248: Strengthen negative-path checks beyond status code.

These tests currently assert only 400. Consider also asserting the response body (or snapshot) so they fail if the endpoint rejects for an unintended reason.

Example tightening
         await membersAgent.post('/api/create-stripe-checkout-session/')
             .body({
                 type: 'gift',
                 tierId: paidTier.id,
                 cadence: 'month',
                 customerEmail: 'rejected-buyer@example.com',
                 metadata: {}
             })
-            .expectStatus(400);
+            .expectStatus(400)
+            .matchBodySnapshot();

Also applies to: 250-264, 266-279

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ghost/core/test/e2e-api/members/gift-subscriptions.test.js` around lines 233
- 248, The test "Rejects purchase when labs flag is disabled" currently only
asserts expectStatus(400); strengthen the negative-path by also asserting the
response body contains the expected error code/message (e.g. that the failure is
due to the 'giftSubscriptions' lab being disabled) or by snapshotting the
response body; update the
membersAgent.post('/api/create-stripe-checkout-session/') assertion to capture
the response (const {body} = await ...) and assert body.errors[0].message or
body.code matches the expected labs-disabled error, and apply the same pattern
to the other similar tests that use mockManager.mockLabsDisabled and
expectStatus(400).

31-33: Extract shared paid-tier lookup to a helper.

The same tier-fetch/select logic is repeated across almost every test. A small helper will reduce duplication and make future fixture changes easier to maintain.

Refactor sketch
+    async function getPaidTier() {
+        const {body: {tiers}} = await adminAgent.get('/tiers/?include=monthly_price&yearly_price');
+        const paidTier = tiers.find(tier => tier.type === 'paid');
+        assert.ok(paidTier, 'Expected at least one paid tier in fixtures');
+        return paidTier;
+    }

-        const {body: {tiers}} = await adminAgent.get('/tiers/?include=monthly_price&yearly_price');
-        const paidTier = tiers.find(tier => tier.type === 'paid');
+        const paidTier = await getPaidTier();

Also applies to: 116-118, 182-184, 236-238, 251-253, 267-269, 282-284

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ghost/core/test/e2e-api/members/gift-subscriptions.test.js` around lines 31 -
33, Extract the repeated tier-fetch/select into a shared helper (e.g., a
function named fetchPaidTier or getPaidTier) that accepts the test HTTP client
(adminAgent) and returns the paid tier object; replace each occurrence of the
pattern "const {body: {tiers}} = await
adminAgent.get('/tiers/?include=monthly_price&yearly_price'); const paidTier =
tiers.find(tier => tier.type === 'paid');" with a single call to this helper
from the tests in gift-subscriptions.test.js (references: adminAgent, tiers,
paidTier) so all tests use the centralized helper and avoid duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ghost/core/test/e2e-api/members/gift-subscriptions.test.js`:
- Line 48: The test is using a fixed session stripeMocker.checkoutSessions[0]
which couples assertions to order; change it to use the latest captured session
(e.g., read the last element of stripeMocker.checkoutSessions) so it mirrors
other tests that use the most recent session and avoids brittle ordering
issues—update any occurrence of stripeMocker.checkoutSessions[0] in the gift
subscriptions test to retrieve the last session instead.

---

Nitpick comments:
In `@ghost/core/test/e2e-api/members/gift-subscriptions.test.js`:
- Around line 233-248: The test "Rejects purchase when labs flag is disabled"
currently only asserts expectStatus(400); strengthen the negative-path by also
asserting the response body contains the expected error code/message (e.g. that
the failure is due to the 'giftSubscriptions' lab being disabled) or by
snapshotting the response body; update the
membersAgent.post('/api/create-stripe-checkout-session/') assertion to capture
the response (const {body} = await ...) and assert body.errors[0].message or
body.code matches the expected labs-disabled error, and apply the same pattern
to the other similar tests that use mockManager.mockLabsDisabled and
expectStatus(400).
- Around line 31-33: Extract the repeated tier-fetch/select into a shared helper
(e.g., a function named fetchPaidTier or getPaidTier) that accepts the test HTTP
client (adminAgent) and returns the paid tier object; replace each occurrence of
the pattern "const {body: {tiers}} = await
adminAgent.get('/tiers/?include=monthly_price&yearly_price'); const paidTier =
tiers.find(tier => tier.type === 'paid');" with a single call to this helper
from the tests in gift-subscriptions.test.js (references: adminAgent, tiers,
paidTier) so all tests use the centralized helper and avoid duplication.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ce06b975-6f0a-4bf5-a1e0-cad2ba402c36

📥 Commits

Reviewing files that changed from the base of the PR and between afcabc6 and 352fa86.

⛔ Files ignored due to path filters (1)
  • ghost/core/test/e2e-api/members/__snapshots__/gift-subscriptions.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • ghost/core/test/e2e-api/members/gift-subscriptions.test.js

Comment thread ghost/core/test/e2e-api/members/gift-subscriptions.test.js Outdated
@mike182uk mike182uk force-pushed the BER-3484-add-gift-checkout-e2e-tests branch from 352fa86 to 1d59c32 Compare April 8, 2026 13:03
ref https://linear.app/ghost/issue/BER-3484

Added additional e2e tests covering gift subscription purchase flow
@mike182uk mike182uk force-pushed the BER-3484-add-gift-checkout-e2e-tests branch from 1d59c32 to b211503 Compare April 8, 2026 13:11
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 8, 2026

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)
ghost/core/test/e2e-api/members/gift-subscriptions.test.js (1)

125-180: Consider adding email assertions for consistency.

The anonymous visitor test (lines 113-122) verifies that staff and buyer emails are sent, but this test omits those assertions. While the core email logic is already covered, adding assertions here would ensure the authenticated flow also triggers expected notifications.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ghost/core/test/e2e-api/members/gift-subscriptions.test.js` around lines 125
- 180, Add assertions to this authenticated-member gift purchase test to verify
the expected emails are sent (same as the anonymous visitor test): after
awaiting DomainEvents.allSettled() and after the gift is fetched (use the test's
member.email / gift.get('buyer_email') and site/staff address), assert that the
mailer mock recorded a buyer notification and a staff notification. Locate the
authenticated test named "Can purchase a gift as an authenticated member" and
add checks against the project's email capture (the same mail capture helper
used by the anonymous visitor test) to confirm messages to the buyer email and
the staff email were enqueued/sent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ghost/core/test/e2e-api/members/gift-subscriptions.test.js`:
- Around line 125-180: Add assertions to this authenticated-member gift purchase
test to verify the expected emails are sent (same as the anonymous visitor
test): after awaiting DomainEvents.allSettled() and after the gift is fetched
(use the test's member.email / gift.get('buyer_email') and site/staff address),
assert that the mailer mock recorded a buyer notification and a staff
notification. Locate the authenticated test named "Can purchase a gift as an
authenticated member" and add checks against the project's email capture (the
same mail capture helper used by the anonymous visitor test) to confirm messages
to the buyer email and the staff email were enqueued/sent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6b8b2a4-7346-44e2-ae72-691152d7672f

📥 Commits

Reviewing files that changed from the base of the PR and between 1d59c32 and b211503.

⛔ Files ignored due to path filters (1)
  • ghost/core/test/e2e-api/members/__snapshots__/gift-subscriptions.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • ghost/core/test/e2e-api/members/gift-subscriptions.test.js

@mike182uk mike182uk merged commit 0f75743 into main Apr 8, 2026
39 checks passed
@mike182uk mike182uk deleted the BER-3484-add-gift-checkout-e2e-tests branch April 8, 2026 13:53
franky19 pushed a commit to franky19/Ghost that referenced this pull request Apr 18, 2026
)

ref https://linear.app/ghost/issue/BER-3484

Added additional e2e tests covering gift subscription purchase flow
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