Skip to content

Commit 3d97a82

Browse files
committed
Update Predict E2E mocks for keyset events
1 parent d094762 commit 3d97a82

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ export const POLYMARKET_GEOBLOCK_ELIGIBLE = {
2424
export const POLYMARKET_API_MOCKS = {
2525
GET: [
2626
POLYMARKET_GEOBLOCK_ELIGIBLE,
27-
// gamma-api: events pagination — consumer reads `data?.data`
27+
// gamma-api: events pagination — legacy consumer reads `data?.data`
2828
{
2929
urlEndpoint:
3030
/^https:\/\/gamma-api\.polymarket\.com\/events\/pagination(\?.*)?$/,
3131
responseCode: 200,
3232
response: { data: [] },
3333
},
34+
// gamma-api: events keyset — consumer reads `events` and `next_cursor`
35+
{
36+
urlEndpoint:
37+
/^https:\/\/gamma-api\.polymarket\.com\/events\/keyset(\?.*)?$/,
38+
responseCode: 200,
39+
response: { events: [], next_cursor: null },
40+
},
3441
// gamma-api: public-search — consumer reads `data?.events`
3542
{
3643
urlEndpoint:

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ export const POLYMARKET_API_DOWN = async (mockServer: Mockttp) => {
130130
},
131131
});
132132

133+
await setupMockRequest(mockServer, {
134+
requestMethod: 'GET',
135+
url: /^https:\/\/gamma-api\.polymarket\.com\/events\/keyset/,
136+
responseCode: 500,
137+
response: {
138+
error: 'Internal Server Error',
139+
message: 'Service temporarily unavailable',
140+
statusCode: 500,
141+
},
142+
});
143+
133144
await setupMockRequest(mockServer, {
134145
requestMethod: 'GET',
135146
url: /^https:\/\/gamma-api\.polymarket\.com\/events\/\d+/,
@@ -1376,7 +1387,7 @@ export const POLYMARKET_USDC_BALANCE_MOCKS = async (
13761387
* Mock for all Polymarket endpoints (positions, redeemable positions, activity, UpNL, order book, and value)
13771388
* Mock for Polymarket market feeds API
13781389
* Returns market feed data using the proxy pattern (consistent with other mocks)
1379-
* Intercepts proxy calls to gamma-api.polymarket.com/events/pagination
1390+
* Intercepts proxy calls to gamma-api.polymarket.com/events/pagination and /events/keyset
13801391
*/
13811392
export const POLYMARKET_MARKET_FEEDS_MOCKS = async (mockServer: Mockttp) => {
13821393
// Mock proxy calls to gamma-api.polymarket.com (consistent with other mocks)
@@ -1385,7 +1396,8 @@ export const POLYMARKET_MARKET_FEEDS_MOCKS = async (mockServer: Mockttp) => {
13851396
.matching((request) => {
13861397
const url = new URL(request.url).searchParams.get('url');
13871398
return Boolean(
1388-
url?.includes('gamma-api.polymarket.com/events/pagination'),
1399+
url?.includes('gamma-api.polymarket.com/events/pagination') ||
1400+
url?.includes('gamma-api.polymarket.com/events/keyset'),
13891401
);
13901402
})
13911403
.asPriority(PRIORITY.BASE)
@@ -1427,13 +1439,20 @@ export const POLYMARKET_MARKET_FEEDS_MOCKS = async (mockServer: Mockttp) => {
14271439
selectedFeed = POLYMARKET_TRENDING_FEED;
14281440
}
14291441

1430-
// Return the feed data in the correct API structure
1442+
const isKeysetRequest = polymarketUrl.pathname.endsWith('/events/keyset');
1443+
1444+
// Return the feed data in the correct API structure for the requested endpoint.
14311445
return {
14321446
statusCode: 200,
1433-
json: {
1434-
data: selectedFeed.data,
1435-
pagination: selectedFeed.pagination,
1436-
},
1447+
json: isKeysetRequest
1448+
? {
1449+
events: selectedFeed.data,
1450+
next_cursor: null,
1451+
}
1452+
: {
1453+
data: selectedFeed.data,
1454+
pagination: selectedFeed.pagination,
1455+
},
14371456
};
14381457
});
14391458

0 commit comments

Comments
 (0)