Files
claude (blind_chess) ce36755a89 feat(server): per-viewer capture tally on joined and update messages
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 20:09:26 -04:00

33 lines
1.1 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { captureTally } from '../../src/captures.js';
import type { Game, MoveRecord } from '../../src/state.js';
import type { Color, PieceType } from '@blind-chess/shared';
function rec(by: Color, capturedPieceType?: PieceType): MoveRecord {
return {
ply: 1, by, from: 'e2', to: 'e4', san: 'e4',
capturedPieceType, flags: {}, at: 0,
};
}
describe('captureTally', () => {
it('counts captures per viewer', () => {
const moveHistory: MoveRecord[] = [
rec('w', 'p'), rec('b'), rec('w', 'n'),
rec('b', 'p'), rec('w', 'p'),
];
const game = { moveHistory } as unknown as Game;
expect(captureTally(game, 'w')).toEqual({
byYou: { p: 2, n: 1 }, byOpponent: { p: 1 },
});
expect(captureTally(game, 'b')).toEqual({
byYou: { p: 1 }, byOpponent: { p: 2, n: 1 },
});
});
it('returns empty tallies when there are no captures', () => {
const game = { moveHistory: [rec('w'), rec('b')] } as unknown as Game;
expect(captureTally(game, 'w')).toEqual({ byYou: {}, byOpponent: {} });
});
});