This commit is contained in:
@@ -18,6 +18,54 @@ afterEach(async () => fixture.cleanup());
|
||||
|
||||
const payload = gameEvent('round_change', 17);
|
||||
|
||||
it.each(['game_start', 'round_change', 'heartbeat', 'game_end'] as const)(
|
||||
'preserves optional reporter identity and sequence for %s',
|
||||
async (event) => {
|
||||
const { parseGameEvent } = await import('../../src/lib/telemetry.js');
|
||||
const report = gameEvent(event);
|
||||
const match = ' opaque/Match:123 ';
|
||||
expect(parseGameEvent({ ...report, match, seq: 7 })).toEqual({
|
||||
...report,
|
||||
match,
|
||||
seq: 7
|
||||
});
|
||||
expect(parseGameEvent({ ...report, match })).toEqual({ ...report, match });
|
||||
expect(parseGameEvent({ ...report, seq: 7 })).toEqual({ ...report, seq: 7 });
|
||||
expect(parseGameEvent(report)).toEqual(report);
|
||||
const response = await post({ ...report, match, seq: 7 });
|
||||
expect(response.status).toBe(200);
|
||||
expect((await response.json()).telemetry).toMatchObject({ match, seq: 7 });
|
||||
const { listTelemetry } = await import('../../src/lib/server/fleet/telemetry.js');
|
||||
expect(listTelemetry()[0]).toMatchObject({ match, seq: 7 });
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ match: '' },
|
||||
{ match: ' \t\n' },
|
||||
{ match: 'x'.repeat(65) },
|
||||
{ match: null },
|
||||
{ match: 123 },
|
||||
{ seq: 0 },
|
||||
{ seq: -1 },
|
||||
{ seq: 1.5 },
|
||||
{ seq: Number.MAX_SAFE_INTEGER + 1 },
|
||||
{ seq: null },
|
||||
{ seq: '1' }
|
||||
])('rejects malformed optional reporter metadata: %j', async (metadata) => {
|
||||
const response = await post({ ...payload, ...metadata });
|
||||
expect(response.status).toBe(400);
|
||||
const { listTelemetry } = await import('../../src/lib/server/fleet/telemetry.js');
|
||||
expect(listTelemetry()).toEqual([]);
|
||||
});
|
||||
|
||||
it('accepts the maximum reporter key length and safe sequence number', async () => {
|
||||
const { parseGameEvent } = await import('../../src/lib/telemetry.js');
|
||||
expect(
|
||||
parseGameEvent({ ...payload, match: 'x'.repeat(64), seq: Number.MAX_SAFE_INTEGER })
|
||||
).toMatchObject({ match: 'x'.repeat(64), seq: Number.MAX_SAFE_INTEGER });
|
||||
});
|
||||
|
||||
it.each(['game_end', 'round reset', 'map change'])(
|
||||
'drops the previous match timing when game_start is missed after %s',
|
||||
async (boundary) => {
|
||||
|
||||
Reference in New Issue
Block a user