Skip to content

test: improves mocks to allow plain text reponses#26625

Merged
christopherferreira9 merged 13 commits into
mainfrom
cferreira/fix-confirmation-mock
Feb 27, 2026
Merged

test: improves mocks to allow plain text reponses#26625
christopherferreira9 merged 13 commits into
mainfrom
cferreira/fix-confirmation-mock

Conversation

@christopherferreira9
Copy link
Copy Markdown
Contributor

@christopherferreira9 christopherferreira9 commented Feb 26, 2026

Description

  • Fix geolocation mock to return plain text (us-ca) instead of a JSON object, matching the real API's response format. The app reads this with response.text(), so a JSON object gets stringified and can produce malformed URLs when used in path segments.
  • Support string responses in the mock server layer — both MockServerE2E.ts and mockHelpers.ts now return string responses as raw text instead of JSON-serializing them.
  • Add catch-all mock for the legacy /regions/{region}/tokens endpoint to DEFAULT_RAMPS_API_MOCKS, preventing unmocked live API calls.
  • On mUSD convert disables the synchronization only after tapping the CTA to make sure it is displayed before on a first time user.

This PR addresses a gigantic mocking error on default mocks, specifically speaking the onramp geolocation. This issue was causing random flakiness due to a bad formatted url coming from a mock.
Example: https://on-ramp-cache.uat-api.cx.metamask.io/regions/%7B%22id%22:%22/regions/us-ca%22,%22name%22:%22california%22,%22emoji%22:%22%F0%9F%87%BA%F0%9F%87%B8%22,%22detected%22:true%7D/tokens?action=deposit&sdk=2.1.5 (see run reference)

The reason for this is that the request for https://on-ramp.<ENV>-api.cx.metamask.io/geolocation was returning

{
    id: region.id,
    name: region.name,
    emoji: region.emoji,
    detected: true,
}

when in reality the geolocation endpoint returns plaintext containing the country code for the user's location. This PR adds the ability to the mock server to accept plain text instead of json as a response and fixes the mocking.

It then caused perps tests to fail due to region not available since the fallback country (US) is currently being blacklisted and this was the country used in the onramps default geolocation mock.

CI changes

ref was removed from the shard runner checkout as this was causing inconsistencies with the way every single workflow uses checkout. Builds do not contain a ref which results in building apps with a merge commit instead of the branch commit while tests would run with a different ref resulting in failed tests for changes that were already fixed on main.

Changelog

CHANGELOG entry:

Related issues

Fixes:

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Moderate risk: changes test infrastructure by installing a lifecycle-wide unhandledRejection filter and altering mock server shutdown behavior, which could mask unexpected promise rejections if the filter is too broad. Functional app code is untouched; impact is limited to E2E reliability and mocking fidelity.

Overview
Fixes onramp geolocation mocking to return plain text region codes (matching the real API) and updates the mocking layer (MockServerE2E, setupMockRequest) to return raw string bodies without JSON-serializing; adds a catch-all mock for legacy /regions/{region}/tokens to prevent live calls.

Hardens E2E infra by adding MockServerE2E.startDraining() (return 503 during cleanup) and installing a lifecycle-wide filter that suppresses mockttp Error('Aborted') unhandled rejections, with cleanup integrated into withFixtures.

Stabilizes flaky Detox flows: waits for elements to stop moving before taps (wallet token rows, confirm button), relaxes a swap analytics assertion to min length, adjusts unified-buy analytics region assertions to expect a string, adds perps geolocation mocking (non-blocked region), and tweaks/simplifies a few smoke tests (mUSD sync timing, SOL send assertions).

Written by Cursor Bugbot for commit 27fc622. This will update automatically on new commits. Configure here.

@christopherferreira9 christopherferreira9 requested a review from a team as a code owner February 26, 2026 11:12
@christopherferreira9 christopherferreira9 added team-qa QA team no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed labels Feb 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@christopherferreira9 christopherferreira9 added the skip-smart-e2e-selection Skip Smart E2E selection, i.e. select all E2E tests to run label Feb 26, 2026
@christopherferreira9 christopherferreira9 requested a review from a team as a code owner February 26, 2026 12:18
@christopherferreira9 christopherferreira9 changed the title test: improves on ramps mocks test: improves mocks to allow plain text reponses Feb 26, 2026
amitabh94
amitabh94 previously approved these changes Feb 26, 2026
Comment thread tests/page-objects/wallet/WalletView.ts
Comment thread tests/smoke/confirmations/send/send-solana-token.spec.ts
cortisiko
cortisiko previously approved these changes Feb 26, 2026
Comment thread tests/api-mocking/mock-responses/ramps/responses/ramps-geolocation.ts Outdated
Comment thread tests/smoke/ramps/onramp-unified-buy.spec.ts
Comment thread tests/api-mocking/mock-responses/perps-arbitrum-mocks.ts Outdated
@christopherferreira9 christopherferreira9 requested a review from a team as a code owner February 27, 2026 16:08
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - skip-smart-e2e-selection label found

All E2E tests pre-selected.

View GitHub Actions results

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread tests/framework/fixtures/FixtureHelper.ts
Comment thread tests/api-mocking/mock-responses/perps-arbitrum-mocks.ts
Copy link
Copy Markdown
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

LGTM

@christopherferreira9 christopherferreira9 added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 5cc6a74 Feb 27, 2026
184 of 185 checks passed
@christopherferreira9 christopherferreira9 deleted the cferreira/fix-confirmation-mock branch February 27, 2026 21:33
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 27, 2026
@metamaskbot metamaskbot added the release-7.69.0 Issue or pull request that will be included in release 7.69.0 label Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.69.0 Issue or pull request that will be included in release 7.69.0 size-M skip-smart-e2e-selection Skip Smart E2E selection, i.e. select all E2E tests to run team-qa QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants