Skip to content
Merged
2 changes: 0 additions & 2 deletions tests/api-mocking/mock-e2e-allowlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export const ALLOWLISTED_HOSTS = [
'127.0.0.1',
'localhost',
'10.0.2.2', // Android emulator host
'gamma-api.polymarket.com',
'*.polymarket.com',
'metamask.github.io', // Test-snaps and test-dapp pages loaded in browser
];

Expand Down
63 changes: 61 additions & 2 deletions tests/api-mocking/mock-responses/defaults/polymarket-apis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/**
* Default mock responses for Polymarket API endpoints
* Default mock responses for Polymarket API endpoints.
*
* These defaults cover the calls fired by the wallet's Explore tab
* (TrendingView / usePredictMarketData) so that non-predict specs that pass
* through Explore (e.g. via navigateToBrowserView()) don't leak live requests
* to Polymarket. Predict and trending specs override these via
* POLYMARKET_COMPLETE_MOCKS registered as testSpecificMock at higher priority.
*
* clob.polymarket.com is intentionally not covered here — it only fires on
* trade actions, never during Explore render.
*/

/** Single source of truth for geoblock mock (eligible region). Reused in defaults and in POLYMARKET_COMPLETE_MOCKS. */
Expand All @@ -13,7 +22,57 @@ export const POLYMARKET_GEOBLOCK_ELIGIBLE = {
} as const;

export const POLYMARKET_API_MOCKS = {
GET: [POLYMARKET_GEOBLOCK_ELIGIBLE],
GET: [
POLYMARKET_GEOBLOCK_ELIGIBLE,
// gamma-api: events pagination — consumer reads `data?.data`
{
urlEndpoint:
/^https:\/\/gamma-api\.polymarket\.com\/events\/pagination(\?.*)?$/,
responseCode: 200,
response: { data: [] },
},
// gamma-api: public-search — consumer reads `data?.events`
{
urlEndpoint:
/^https:\/\/gamma-api\.polymarket\.com\/public-search(\?.*)?$/,
responseCode: 200,
response: { events: [] },
},
// gamma-api: markets list
{
urlEndpoint: /^https:\/\/gamma-api\.polymarket\.com\/markets(\?.*)?$/,
responseCode: 200,
response: [],
},
// polymarket.com: homepage carousel
{
urlEndpoint: 'https://polymarket.com/api/homepage/carousel',
responseCode: 200,
response: [],
},
// polymarket.com: crypto price feed
{
urlEndpoint: /^https:\/\/polymarket\.com\/api\/crypto\/crypto-price.*$/,
responseCode: 200,
response: {},
},
// data-api: positions / activity / upnl
{
urlEndpoint: /^https:\/\/data-api\.polymarket\.com\/positions(\?.*)?$/,
responseCode: 200,
response: [],
},
{
urlEndpoint: /^https:\/\/data-api\.polymarket\.com\/activity(\?.*)?$/,
responseCode: 200,
response: [],
},
{
urlEndpoint: /^https:\/\/data-api\.polymarket\.com\/upnl(\?.*)?$/,
responseCode: 200,
response: [],
},
],
POST: [],
PUT: [],
DELETE: [],
Expand Down
20 changes: 20 additions & 0 deletions tests/api-mocking/mock-responses/polymarket/polymarket-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export const POLYMARKET_EVENT_DETAILS_MOCKS = async (mockServer: Mockttp) => {
const url = new URL(request.url).searchParams.get('url');
return Boolean(url?.includes('gamma-api.polymarket.com/events/'));
})
.asPriority(PRIORITY.BASE)
Comment thread
cursor[bot] marked this conversation as resolved.
.thenCallback((request) => {
const url = new URL(request.url).searchParams.get('url');
const eventIdMatch = url?.match(/\/events\/([0-9]+)$/);
Expand Down Expand Up @@ -656,6 +657,24 @@ export const POLYMARKET_FEE_RATE_MOCKS = async (mockServer: Mockttp) => {
});
};

/**
* Mock for Polymarket CLOB prices-history API
* Returns an empty history series — sufficient for predict happy-path specs
* that render the chart (consumer treats non-array history as empty).
*/
export const POLYMARKET_PRICES_HISTORY_MOCKS = async (mockServer: Mockttp) => {
await mockServer
.forGet('/proxy')
.matching((request) => {
const url = new URL(request.url).searchParams.get('url');
return Boolean(url?.includes('clob.polymarket.com/prices-history'));
})
.asPriority(PRIORITY.BASE)
.thenReply(200, JSON.stringify({ history: [] }), {
'content-type': 'application/json',
});
};

/**
* Mock for Polymarket CLOB order book API
* Returns order book data for specific token IDs with correct market mapping
Expand Down Expand Up @@ -2214,6 +2233,7 @@ export const POLYMARKET_COMPLETE_MOCKS = async (mockServer: Mockttp) => {
await POLYMARKET_EVENT_DETAILS_MOCKS(mockServer);
await POLYMARKET_ORDER_BOOK_MOCKS(mockServer);
await POLYMARKET_PRICES_MOCKS(mockServer); // Mock for CLOB prices API
await POLYMARKET_PRICES_HISTORY_MOCKS(mockServer); // Mock for CLOB prices-history API (chart series)
await POLYMARKET_FEE_RATE_MOCKS(mockServer);
await POLYMARKET_MARKET_FEEDS_MOCKS(mockServer);
await POLYMARKET_CLOB_AUTH_MOCKS(mockServer);
Expand Down
54 changes: 54 additions & 0 deletions tests/api-mocking/mock-responses/trending-api-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,52 @@ export const TRENDING_API_MOCKS: MockEventsObject = {
},
priority: 1000,
},
{
// Event details fetched when user taps a prediction row in the trending feed.
// Returns the same Bitcoin event payload as /events/pagination so the detail
// screen renders without crashing.
urlEndpoint: /https:\/\/gamma-api\.polymarket\.com\/events\/1(\?.*)?$/,
responseCode: 200,
response: {
id: '1',
title: 'Will Bitcoin hit $100k?',
slug: 'bitcoin-100k',
icon: 'https://polymarket.com/icon.png',
description: 'Bitcoin price prediction',
startDate: '2024-01-01T00:00:00Z',
endDate: '2024-12-31T23:59:59Z',
markets: [
{
conditionId: '123',
question: 'Will Bitcoin hit $100k?',
status: 'open',
outcomes: '["Yes", "No"]',
outcomePrices: '["0.6", "0.4"]',
clobTokenIds: '["1", "2"]',
volumeNum: 1000000,
liquidity: 500000,
orderPriceMinTickSize: 0.01,
active: true,
closed: false,
sportsMarketType: 'moneyline',
groupItemTitle: 'Bitcoin',
},
],
tags: [{ label: 'Crypto', slug: 'crypto' }],
volume: 1000000,
liquidity: 500000,
},
priority: 1000,
},
{
// Prices-history (chart series) fetched on prediction detail render.
// Empty history is safe — consumer (PolymarketProvider) returns [] when
// history is not a non-empty array.
urlEndpoint: /https:\/\/clob\.polymarket\.com\/prices-history.*/,
responseCode: 200,
response: { history: [] },
priority: 1000,
},
{
urlEndpoint: /\/exchange.*/, // Hyperliquid
responseCode: 200,
Expand Down Expand Up @@ -257,5 +303,13 @@ export const TRENDING_API_MOCKS: MockEventsObject = {
},
priority: 1000,
},
{
// CLOB prices fetched on prediction detail render. Empty object is
// safe for trending-feed which only renders the prediction row.
urlEndpoint: /https:\/\/clob\.polymarket\.com\/prices.*/,
responseCode: 200,
response: {},
priority: 1000,
},
],
};
Loading