Files
wownerogue/test/movementManager.test.js
T
jwinterm fad2a695bd Wownerogue
A browser-based roguelike synchronized with crypto block timing. A run is a race
against the next block: reach the exit before the block lands, or the house wins.
The same codebase runs the solo dungeon, the social Tavern, and operator-selected
PvP and race rulesets, with separate free and paid leaderboards.

Self-hostable under the MIT License. See README.md to run it, docs/ARCHITECTURE.md
for the design, and docs/DEPLOY.md to operate an instance.
2026-07-27 08:23:01 -04:00

34 lines
1.2 KiB
JavaScript

const MovementManager = require('../src/game/movementManager');
// Minimal fake game implementing movePlayer & getState
function makeGame() {
return {
player: { x: 5, y: 5, getState() { return { x: this.x, y: this.y }; } },
movePlayer(dx, dy) {
this.player.x += dx;
this.player.y += dy;
return { status: 'moved' };
},
getState() { return { player: { x: this.player.x, y: this.player.y } }; }
};
}
describe('MovementManager', () => {
test('applies movement and rate limits subsequent rapid moves', () => {
const activeGames = new Map();
const socketId = 'sock1';
const game = makeGame();
activeGames.set(socketId, game);
const emitted = [];
const io = { to: () => ({ emit: (evt, data) => emitted.push({ evt, data }) }) };
const debugManager = { getCurrentBlockHeight: () => 123 };
const mm = new MovementManager({ activeGames, io, debugManager, moveCooldown: 100 });
mm.handleMove(socketId, { direction: 'right' });
mm.handleMove(socketId, { direction: 'right' }); // should be rate-limited
expect(game.player.x).toBe(6); // only first move applied
expect(emitted.filter(e => e.evt === 'game_update').length).toBe(1);
});
});