Skip to content

feat(skeleton): display store credit balance in cart + e2e tests#3608

Closed
itsjustriley wants to merge 14 commits intomainfrom
test/e2e-store-credit
Closed

feat(skeleton): display store credit balance in cart + e2e tests#3608
itsjustriley wants to merge 14 commits intomainfrom
test/e2e-store-credit

Conversation

@itsjustriley
Copy link
Contributor

Summary

  • Query Customer Account API for store credit balance in the cart route loader (with graceful fallback for unauthenticated users)
  • Display aggregated store credit balance in CartSummary using a new CartStoreCredit component, following the same pattern as CartDiscounts and CartGiftCard
  • Add MSW store-credit scenario that mocks the StoreCreditBalance CAAPI query
  • Add StoreCreditUtil e2e fixture and storeCredit.spec.ts with 3 test cases

Design Notes

Store credit is a Customer Account API concept while the cart uses the Storefront API. The cart route loader now runs both queries in parallel via Promise.all, with the CAAPI query wrapped in .catch(() => null) for unauthenticated users.

The store credit section only renders on the cart page (not the aside drawer), since only the cart route loader fetches the CAAPI data.

Dependencies

Depends on MSW infrastructure from PR #3537 (fb-msw branch).

Test plan

  • storeCredit.spec.ts — 3 tests pass (balance visibility, currency format, empty state)
  • cart.spec.ts — 18 tests pass (no regressions)
  • Existing account.spec.ts smoke test unaffected

fredericoo and others added 14 commits March 5, 2026 19:08
Why: PR review identified a latent bug (localStorage polyfill skipped in
workerd), type safety gaps, magic numbers, dead code, and structural
inconsistencies with existing fixture patterns.

How: Fix hasWorkingLocalStorage null detection by adding an explicit null
check before the try/catch — optional chaining silently no-ops when
localStorage is undefined, causing the function to return true and skip
the polyfill in exactly the environment (workerd) where it's needed.

Augment the global Env interface with HYDROGEN_E2E_MSW_SCENARIO to remove
the unsafe double cast in getMswScenario. Extract E2E_TUNNEL_HOSTNAME and
SESSION_TTL_IN_MS as named constants with "why" comments. Add JSDoc to
ensureNodeProcessForMsw explaining the NODE_ENV/versions.node strategy,
and a comment on module-level currentMswScenarioMeta explaining the
architectural constraint.

Convert AccountUtil to a Playwright fixture (matching CartUtil, DiscountUtil,
GiftCardUtil patterns), remove the pass-through expectLoggedInState method,
and update account.spec.ts to use the fixture.

Add explicit MswScenarioMeta return type and defensive throw after Map.get()
in getHandlersForScenario. Remove dead code guard in graphql.ts parseOperation
(regex only captures 'query'|'mutation'). Remove unused env option from
DevServer.
…ation

We've agreed to prioritise test utilities that take a `page` arg over
Playwright fixtures that override the test function signature. Revert
the AccountUtil fixture registration while keeping all other review
feedback changes from the prior commit.
Store credit is a Customer Account API concept that needs to be queried
separately from the Storefront API cart. The cart route loader now queries
CAAPI for the customer's store credit balance in parallel with the cart
data, with a graceful fallback to null for unauthenticated users.

The CartStoreCredit component aggregates balances across multiple store
credit accounts and renders a read-only section using the Money component,
following the same pattern as CartDiscounts and CartGiftCard.

E2E tests use an MSW scenario that mocks the StoreCreditBalance CAAPI
query returning $50.00 USD. Cart creation is done directly via the
Storefront API to avoid cookie domain issues caused by the MSW entry's
URL rewriting for CAAPI session injection.
@itsjustriley
Copy link
Contributor Author

Closing — work lives on the local branch test/e2e-store-credit. PR was created prematurely.

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.

2 participants