Commit 5cc6a74
authored
test: improves mocks to allow plain text reponses (#26625)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **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](https://github.com/MetaMask/metamask-mobile/actions/runs/22429213914/job/64944977184))
The reason for this is that the request for
`https://on-ramp.<ENV>-api.cx.metamask.io/geolocation` was returning
```typescript
{
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](https://github.com/MetaMask/metamask-mobile/blob/main/builds.yml#L40)
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.
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry:
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
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**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I've included tests if applicable
- [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!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).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
27fc622. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 1ae46b5 commit 5cc6a74
15 files changed
Lines changed: 260 additions & 122 deletions
File tree
- .github/workflows
- tests
- api-mocking
- helpers
- mock-responses
- defaults
- ramps/responses
- framework
- fixtures
- page-objects/wallet
- smoke
- confirmations
- send
- transactions
- perps
- ramps
- swap
- wallet
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | 99 | | |
103 | 100 | | |
104 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
165 | 168 | | |
166 | 169 | | |
167 | 170 | | |
| |||
326 | 329 | | |
327 | 330 | | |
328 | 331 | | |
329 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
330 | 336 | | |
331 | 337 | | |
332 | 338 | | |
| |||
430 | 436 | | |
431 | 437 | | |
432 | 438 | | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
433 | 460 | | |
434 | 461 | | |
435 | 462 | | |
| |||
453 | 480 | | |
454 | 481 | | |
455 | 482 | | |
456 | | - | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
457 | 489 | | |
458 | 490 | | |
459 | 491 | | |
| |||
468 | 500 | | |
469 | 501 | | |
470 | 502 | | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
| 503 | + | |
477 | 504 | | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
484 | 510 | | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
490 | 516 | | |
491 | | - | |
492 | | - | |
493 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
494 | 528 | | |
495 | 529 | | |
496 | | - | |
497 | | - | |
| 530 | + | |
| 531 | + | |
498 | 532 | | |
499 | 533 | | |
500 | 534 | | |
501 | 535 | | |
502 | 536 | | |
503 | 537 | | |
504 | 538 | | |
505 | | - | |
506 | | - | |
| 539 | + | |
| 540 | + | |
507 | 541 | | |
508 | 542 | | |
| 543 | + | |
509 | 544 | | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
| 545 | + | |
515 | 546 | | |
516 | 547 | | |
517 | 548 | | |
518 | | - | |
| 549 | + | |
519 | 550 | | |
520 | | - | |
| 551 | + | |
521 | 552 | | |
522 | 553 | | |
523 | 554 | | |
| |||
528 | 559 | | |
529 | 560 | | |
530 | 561 | | |
531 | | - | |
532 | 562 | | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
549 | 566 | | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
558 | 575 | | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
564 | 603 | | |
| 604 | + | |
565 | 605 | | |
566 | 606 | | |
567 | 607 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
210 | 209 | | |
211 | 210 | | |
212 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
| |||
0 commit comments