Improve application responsiveness and background processing
This commit is contained in:
@@ -386,15 +386,15 @@ describe('player profiles', () => {
|
||||
expect(getPlayerProfile('101', 9999)?.offset).toBe(25);
|
||||
for (const offset of [-1, NaN, 0.5]) expect(getPlayerProfile('101', offset)?.offset).toBe(0);
|
||||
const { load } = await import('../../src/routes/leaderboard/players/[guid]/+page.server.js');
|
||||
expect(load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?offset=25') }).profile).toEqual(second);
|
||||
expect((await load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?offset=25') })).profile).toEqual(second);
|
||||
});
|
||||
|
||||
it('loads canonical profile URLs, encodes GUIDs and returns 404 for missing players', async () => {
|
||||
await seedRecords();
|
||||
const { load } = await import('../../src/routes/leaderboard/players/[guid]/+page.server.js');
|
||||
const url = new URL('http://localhost/leaderboard/players/101');
|
||||
expect(load({ params: { guid: '101' }, url }).profile).toMatchObject({ name: 'Ace', stats: { kills: 770, gamesPlayed: 4 } });
|
||||
expect(() => load({ params: { guid: 'missing' }, url })).toThrow(expect.objectContaining({ status: 404 }));
|
||||
expect((await load({ params: { guid: '101' }, url })).profile).toMatchObject({ name: 'Ace', stats: { kills: 770, gamesPlayed: 4 } });
|
||||
await expect(load({ params: { guid: 'missing' }, url })).rejects.toThrow(expect.objectContaining({ status: 404 }));
|
||||
const { playerProfileHref } = await import('../../src/lib/leaderboard.js');
|
||||
expect(playerProfileHref('001/2?#')).toBe('/leaderboard/players/001%2F2%3F%23');
|
||||
});
|
||||
@@ -417,7 +417,7 @@ describe('leaderboard API', () => {
|
||||
const handle = await seedRecords();
|
||||
handle.prepare("UPDATE leaderboard_players SET name = 'JoshWright' WHERE guid = '101'").run();
|
||||
const { GET } = await import('../../src/routes/api/leaderboard/+server.js');
|
||||
const response = GET({ url: new URL('http://localhost/api/leaderboard?q=JoshWright&metric=kills') });
|
||||
const response = await GET({ url: new URL('http://localhost/api/leaderboard?q=JoshWright&metric=kills') });
|
||||
expect(response.status).toBe(200);
|
||||
const result = await response.json() as LeaderboardResponse;
|
||||
expect(result).toMatchObject({ total: 1, summary: { players: 4, matches: 5, kills: 1140 } });
|
||||
@@ -429,7 +429,7 @@ describe('leaderboard API', () => {
|
||||
it('returns the requested ranking and pagination', async () => {
|
||||
await seedRecords();
|
||||
const { GET } = await import('../../src/routes/api/leaderboard/+server.js');
|
||||
const response = GET({ url: new URL('http://localhost/api/leaderboard?game=t5&map=t5%3Atheater&metric=kills&limit=1&offset=1') });
|
||||
const response = await GET({ url: new URL('http://localhost/api/leaderboard?game=t5&map=t5%3Atheater&metric=kills&limit=1&offset=1') });
|
||||
expect(response.status).toBe(200);
|
||||
const result = await response.json() as LeaderboardResponse;
|
||||
expect(result).toMatchObject({ metric: 'kills', limit: 1, offset: 1, total: 3 });
|
||||
@@ -442,7 +442,7 @@ describe('leaderboard API', () => {
|
||||
for (const query of ['game=t7', 'game=', 'metric=unknown', 'limit=0', 'limit=101', 'limit=',
|
||||
'limit=1.5', 'limit=1e1', 'offset=-1', 'offset=1000001', 'offset=Infinity', 'offset=0.5',
|
||||
`q=${'a'.repeat(101)}`, `map=${'a'.repeat(1025)}`]) {
|
||||
const response = GET({ url: new URL(`http://localhost/api/leaderboard?${query}`) });
|
||||
const response = await GET({ url: new URL(`http://localhost/api/leaderboard?${query}`) });
|
||||
expect(response.status, query).toBe(400);
|
||||
expect(await response.json()).toMatchObject({ ok: false, kind: 'bad-request' });
|
||||
}
|
||||
@@ -455,9 +455,9 @@ describe('leaderboard API', () => {
|
||||
handle.prepare('UPDATE leaderboard_matches SET map = ?, map_key = ?, map_name = ? WHERE id = 1')
|
||||
.run(map, key, map);
|
||||
const { GET } = await import('../../src/routes/api/leaderboard/+server.js');
|
||||
const all = await GET({ url: new URL('http://localhost/api/leaderboard') }).json() as LeaderboardResponse;
|
||||
const all = await (await GET({ url: new URL('http://localhost/api/leaderboard') })).json() as LeaderboardResponse;
|
||||
const returnedKey = all.maps.find(option => option.map === map)!.key;
|
||||
const response = GET({ url: new URL(`http://localhost/api/leaderboard?map=${encodeURIComponent(returnedKey)}`) });
|
||||
const response = await GET({ url: new URL(`http://localhost/api/leaderboard?map=${encodeURIComponent(returnedKey)}`) });
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.json()).toMatchObject({ total: 2, summary: { matches: 1, kills: 200 } });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user