Added e2e tests covering gift subscription purchase flow#27226
Conversation
WalkthroughA new end-to-end test suite was added at 🚥 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 docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
ghost/core/test/e2e-api/members/__snapshots__/gift-subscriptions.test.js.snapis excluded by!**/*.snap
📒 Files selected for processing (1)
ghost/core/test/e2e-api/members/gift-subscriptions.test.js
352fa86 to
1d59c32
Compare
ref https://linear.app/ghost/issue/BER-3484 Added additional e2e tests covering gift subscription purchase flow
1d59c32 to
b211503
Compare
|
There was a problem hiding this comment.
🧹 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
⛔ Files ignored due to path filters (1)
ghost/core/test/e2e-api/members/__snapshots__/gift-subscriptions.test.js.snapis excluded by!**/*.snap
📒 Files selected for processing (1)
ghost/core/test/e2e-api/members/gift-subscriptions.test.js
) ref https://linear.app/ghost/issue/BER-3484 Added additional e2e tests covering gift subscription purchase flow



ref https://linear.app/ghost/issue/BER-3484
Added additional e2e tests covering gift subscription purchase flow