Exclude same-round departures from games played
This commit is contained in:
@@ -269,6 +269,40 @@ it('keeps disconnected player records while completing only the final roster', a
|
||||
roundsSurvived: 3, gamesPlayed: 1, gamesCompleted: 0 }, matches: [{ status: 'completed', completed: 0 }] });
|
||||
});
|
||||
|
||||
it.each([
|
||||
[server, 'zombie_theater', 't5'],
|
||||
['t6_zombie_town_1', 'zm_transit', 't6']
|
||||
])('does not count same-round departures as games played on %s', async (source, map, game) => {
|
||||
const { getLeaderboard } = await import('../../src/lib/server/fleet/leaderboard.js');
|
||||
const { getPlayerProfile } = await import('../../src/lib/server/fleet/player-profile.js');
|
||||
const departed = player('departed', { kills: 10 });
|
||||
const advanced = player('advanced', { kills: 20 });
|
||||
const finished = player('finished', { kills: 30 });
|
||||
await report('game_start', 0, [], source, map);
|
||||
await report('heartbeat', 5, [departed, advanced], source, map);
|
||||
await report('heartbeat', 5, [player(departed.guid, { kills: 15 }), advanced], source, map);
|
||||
await report('heartbeat', 5, [advanced], source, map);
|
||||
await report('round_change', 6, [advanced, finished], source, map);
|
||||
await report('game_end', 6, [finished], source, map);
|
||||
|
||||
const { closeDb } = await import('../../src/lib/server/db/index.js');
|
||||
closeDb();
|
||||
const board = getLeaderboard({ game });
|
||||
expect(board.entries.find(entry => entry.guid === departed.guid)).toMatchObject({
|
||||
gamesPlayed: 0, gamesCompleted: 0, kills: 15, highestRound: 5,
|
||||
averageKills: null, averageRounds: null, completionRate: null
|
||||
});
|
||||
expect(board.entries.find(entry => entry.guid === advanced.guid)).toMatchObject({ gamesPlayed: 1, gamesCompleted: 0 });
|
||||
expect(board.entries.find(entry => entry.guid === finished.guid)).toMatchObject({ gamesPlayed: 1, gamesCompleted: 1 });
|
||||
const profile = getPlayerProfile(departed.guid)!;
|
||||
expect(profile).toMatchObject({ stats: { gamesPlayed: 0, kills: 15 },
|
||||
maps: [{ gamesPlayed: 0, kills: 15 }], matchesTotal: 1,
|
||||
matches: [{ kills: 15, completed: 0 }], records: { bestKills: { value: 15 } } });
|
||||
expect(getLeaderboard({ game, map: profile.maps[0].key, metric: 'gamesPlayed' }).entries)
|
||||
.toContainEqual(expect.objectContaining({ guid: departed.guid, gamesPlayed: 0 }));
|
||||
expect(getPlayerProfile(departed.guid, 0, { game, map: profile.maps[0].key })?.matchesTotal).toBe(1);
|
||||
});
|
||||
|
||||
it('starts separate matches for game starts, map changes, round resets, and new rounds after an end', async () => {
|
||||
await report('game_start');
|
||||
await report('round_change', 5, [player(undefined, { kills: 50 })]);
|
||||
|
||||
Reference in New Issue
Block a user