Skip to content

Commit 1e823d2

Browse files
test(e2e): mock prices-history + tighten Polymarket defaults (MMQA-1800)
CI surfaced two pre-existing leaks the *.polymarket.com wildcard had been masking. Both are fixed here so the wildcard removal can ship. - POLYMARKET_COMPLETE_MOCKS: add prices-history mock returning { history: [] }. Predict happy-path specs (open-position, cash-out, claim-positions, geo-restriction) were making live calls to clob.polymarket.com/prices-history; the chart consumer in PolymarketProvider treats a non-array history as empty so this empty payload is safe. - trending-api-mocks: add events/1 (rich Bitcoin event payload matching the existing pagination response) and prices-history (empty history). trending-feed.spec.ts taps prediction row 1, which navigates to a detail screen that calls these endpoints; without the mocks the detail screen renders empty and the wallet's React tree throws. - defaults/polymarket-apis: drop the events/{id} and events?parent_event_id matchers. They were too aggressive — empty payloads cause the wallet to crash in detail screens. Detail-level calls should be covered by the spec's testSpecificMock, not by generic defaults. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5c9abbe commit 1e823d2

3 files changed

Lines changed: 65 additions & 13 deletions

File tree

tests/api-mocking/mock-responses/defaults/polymarket-apis.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@ export const POLYMARKET_API_MOCKS = {
3838
responseCode: 200,
3939
response: { events: [] },
4040
},
41-
// gamma-api: single event lookup — consumer accesses `data?.markets`
42-
{
43-
urlEndpoint: /^https:\/\/gamma-api\.polymarket\.com\/events\/[^/?]+$/,
44-
responseCode: 200,
45-
response: { markets: [] },
46-
},
47-
// gamma-api: parent event lookup
48-
{
49-
urlEndpoint:
50-
/^https:\/\/gamma-api\.polymarket\.com\/events(\?.*parent_event_id=.*)?$/,
51-
responseCode: 200,
52-
response: [],
53-
},
5441
// gamma-api: markets list
5542
{
5643
urlEndpoint: /^https:\/\/gamma-api\.polymarket\.com\/markets(\?.*)?$/,

tests/api-mocking/mock-responses/polymarket/polymarket-mocks.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,24 @@ export const POLYMARKET_FEE_RATE_MOCKS = async (mockServer: Mockttp) => {
656656
});
657657
};
658658

659+
/**
660+
* Mock for Polymarket CLOB prices-history API
661+
* Returns an empty history series — sufficient for predict happy-path specs
662+
* that render the chart (consumer treats non-array history as empty).
663+
*/
664+
export const POLYMARKET_PRICES_HISTORY_MOCKS = async (mockServer: Mockttp) => {
665+
await mockServer
666+
.forGet('/proxy')
667+
.matching((request) => {
668+
const url = new URL(request.url).searchParams.get('url');
669+
return Boolean(url?.includes('clob.polymarket.com/prices-history'));
670+
})
671+
.asPriority(PRIORITY.BASE)
672+
.thenReply(200, JSON.stringify({ history: [] }), {
673+
'content-type': 'application/json',
674+
});
675+
};
676+
659677
/**
660678
* Mock for Polymarket CLOB order book API
661679
* Returns order book data for specific token IDs with correct market mapping
@@ -2184,6 +2202,7 @@ export const POLYMARKET_COMPLETE_MOCKS = async (mockServer: Mockttp) => {
21842202
await POLYMARKET_EVENT_DETAILS_MOCKS(mockServer);
21852203
await POLYMARKET_ORDER_BOOK_MOCKS(mockServer);
21862204
await POLYMARKET_PRICES_MOCKS(mockServer); // Mock for CLOB prices API
2205+
await POLYMARKET_PRICES_HISTORY_MOCKS(mockServer); // Mock for CLOB prices-history API (chart series)
21872206
await POLYMARKET_FEE_RATE_MOCKS(mockServer);
21882207
await POLYMARKET_MARKET_FEEDS_MOCKS(mockServer);
21892208
await POLYMARKET_CLOB_AUTH_MOCKS(mockServer);

tests/api-mocking/mock-responses/trending-api-mocks.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,52 @@ export const TRENDING_API_MOCKS: MockEventsObject = {
161161
},
162162
priority: 1000,
163163
},
164+
{
165+
// Event details fetched when user taps a prediction row in the trending feed.
166+
// Returns the same Bitcoin event payload as /events/pagination so the detail
167+
// screen renders without crashing.
168+
urlEndpoint: /https:\/\/gamma-api\.polymarket\.com\/events\/1(\?.*)?$/,
169+
responseCode: 200,
170+
response: {
171+
id: '1',
172+
title: 'Will Bitcoin hit $100k?',
173+
slug: 'bitcoin-100k',
174+
icon: 'https://polymarket.com/icon.png',
175+
description: 'Bitcoin price prediction',
176+
startDate: '2024-01-01T00:00:00Z',
177+
endDate: '2024-12-31T23:59:59Z',
178+
markets: [
179+
{
180+
conditionId: '123',
181+
question: 'Will Bitcoin hit $100k?',
182+
status: 'open',
183+
outcomes: '["Yes", "No"]',
184+
outcomePrices: '["0.6", "0.4"]',
185+
clobTokenIds: '["1", "2"]',
186+
volumeNum: 1000000,
187+
liquidity: 500000,
188+
orderPriceMinTickSize: 0.01,
189+
active: true,
190+
closed: false,
191+
sportsMarketType: 'moneyline',
192+
groupItemTitle: 'Bitcoin',
193+
},
194+
],
195+
tags: [{ label: 'Crypto', slug: 'crypto' }],
196+
volume: 1000000,
197+
liquidity: 500000,
198+
},
199+
priority: 1000,
200+
},
201+
{
202+
// Prices-history (chart series) fetched on prediction detail render.
203+
// Empty history is safe — consumer (PolymarketProvider) returns [] when
204+
// history is not a non-empty array.
205+
urlEndpoint: /https:\/\/clob\.polymarket\.com\/prices-history.*/,
206+
responseCode: 200,
207+
response: { history: [] },
208+
priority: 1000,
209+
},
164210
{
165211
urlEndpoint: /\/exchange.*/, // Hyperliquid
166212
responseCode: 200,

0 commit comments

Comments
 (0)