Skip to content

Commit af67f7d

Browse files
authored
Merge pull request #409 from topcoder-platform/develop
Better support for large numbers of submissions RE: relative scoring
2 parents 2de35fe + 840290e commit af67f7d

2 files changed

Lines changed: 377 additions & 19 deletions

File tree

src/api/scoring-result/scoring-result.service.spec.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,109 @@ describe('ScoringResultService', () => {
21462146
]);
21472147
});
21482148

2149+
it('fetches all challenge submission pages using total headers when totalPages is absent', async () => {
2150+
const { service, httpService } = createService();
2151+
const fetchChallengeSubmissions = (
2152+
service as any
2153+
).fetchChallengeSubmissions.bind(service) as (
2154+
token: string,
2155+
submissionApiUrl: string,
2156+
challengeId: string,
2157+
) => Promise<Record<string, unknown>[]>;
2158+
const firstPage = Array.from({ length: 100 }, (_, index) => ({
2159+
id: `submission-${index + 1}`,
2160+
}));
2161+
const secondPage = [{ id: 'submission-101' }];
2162+
const pages: Record<number, Array<{ id: string }>> = {
2163+
1: firstPage,
2164+
2: secondPage,
2165+
};
2166+
2167+
httpService.get.mockImplementation(
2168+
(_url: string, options: { params: { page: number } }) =>
2169+
of({
2170+
data: {
2171+
data: pages[options.params.page] ?? [],
2172+
},
2173+
headers: {
2174+
'X-Per-Page': '100',
2175+
'X-Total': '101',
2176+
},
2177+
}),
2178+
);
2179+
2180+
const submissions = await fetchChallengeSubmissions(
2181+
'm2m-token',
2182+
'https://api.topcoder-dev.com/v6',
2183+
basePayload.challengeId,
2184+
);
2185+
2186+
expect(submissions).toHaveLength(101);
2187+
expect(submissions[submissions.length - 1]).toEqual({
2188+
id: 'submission-101',
2189+
});
2190+
expect(httpService.get).toHaveBeenCalledTimes(2);
2191+
expect(httpService.get).toHaveBeenNthCalledWith(
2192+
1,
2193+
'https://api.topcoder-dev.com/v6/submissions',
2194+
expect.objectContaining({
2195+
params: expect.objectContaining({
2196+
page: 1,
2197+
perPage: 100,
2198+
}),
2199+
}),
2200+
);
2201+
expect(httpService.get).toHaveBeenNthCalledWith(
2202+
2,
2203+
'https://api.topcoder-dev.com/v6/submissions',
2204+
expect.objectContaining({
2205+
params: expect.objectContaining({
2206+
page: 2,
2207+
perPage: 100,
2208+
}),
2209+
}),
2210+
);
2211+
});
2212+
2213+
it('fetches another submission page when pagination metadata is missing and the page is full', async () => {
2214+
const { service, httpService } = createService();
2215+
const fetchChallengeSubmissions = (
2216+
service as any
2217+
).fetchChallengeSubmissions.bind(service) as (
2218+
token: string,
2219+
submissionApiUrl: string,
2220+
challengeId: string,
2221+
) => Promise<Record<string, unknown>[]>;
2222+
const firstPage = Array.from({ length: 100 }, (_, index) => ({
2223+
id: `submission-${index + 1}`,
2224+
}));
2225+
const secondPage = [{ id: 'submission-101' }];
2226+
const pages: Record<number, Array<{ id: string }>> = {
2227+
1: firstPage,
2228+
2: secondPage,
2229+
};
2230+
2231+
httpService.get.mockImplementation(
2232+
(_url: string, options: { params: { page: number } }) =>
2233+
of({
2234+
data: pages[options.params.page] ?? [],
2235+
headers: {},
2236+
}),
2237+
);
2238+
2239+
const submissions = await fetchChallengeSubmissions(
2240+
'm2m-token',
2241+
'https://api.topcoder-dev.com/v6',
2242+
basePayload.challengeId,
2243+
);
2244+
2245+
expect(submissions).toHaveLength(101);
2246+
expect(submissions[submissions.length - 1]).toEqual({
2247+
id: 'submission-101',
2248+
});
2249+
expect(httpService.get).toHaveBeenCalledTimes(2);
2250+
});
2251+
21492252
it('excludes no-credit and errored scores from MINIMIZE best-score baselines', () => {
21502253
const { service } = createService();
21512254
const computeBestScores = (service as any).computeBestScores.bind(

0 commit comments

Comments
 (0)