feat(skeleton): display store credit balance in cart + e2e tests#3608
Closed
itsjustriley wants to merge 14 commits intomainfrom
Closed
feat(skeleton): display store credit balance in cart + e2e tests#3608itsjustriley wants to merge 14 commits intomainfrom
itsjustriley wants to merge 14 commits intomainfrom
Conversation
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.
Contributor
Author
|
Closing — work lives on the local branch test/e2e-store-credit. PR was created prematurely. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CartSummaryusing a newCartStoreCreditcomponent, following the same pattern asCartDiscountsandCartGiftCardstore-creditscenario that mocks theStoreCreditBalanceCAAPI queryStoreCreditUtile2e fixture andstoreCredit.spec.tswith 3 test casesDesign 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-mswbranch).Test plan
storeCredit.spec.ts— 3 tests pass (balance visibility, currency format, empty state)cart.spec.ts— 18 tests pass (no regressions)account.spec.tssmoke test unaffected