A game may take drafts: an input it does not call settled can be replaced, and the round waits for settled ones
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jm2auWk6RP71CjaAb4FMoG
This commit is contained in:
1 parent
6133a2469a
commit
927e49cf79
4 files changed
+48
-2
No files matched your search
@@ -43,4 +43,24 @@ describe('rooms', () => {
|
||||
expect(reopened.get(room.id).state).not.toBeNull();
|
||||
errors.mockRestore();
|
||||
});
|
||||
|
||||
it('holds a draft until it is settled, and lets it be replaced until then', () => {
|
||||
type Draft = Input & { final?: boolean };
|
||||
const drafts: GameSpec<State, Input> = {
|
||||
...game,
|
||||
cleanInput: (raw) => ({ ...game.cleanInput(raw), final: (raw as Draft)?.final === true }) as Draft,
|
||||
settled: (input) => (input as Draft).final === true
|
||||
};
|
||||
const { rooms, room, ann, bo } = table(drafts);
|
||||
rooms.submit(room, ann, { pick: 5 }, 0);
|
||||
rooms.submit(room, bo, { pick: 2, final: true }, 0);
|
||||
expect(rooms.waitingOn(room)).toEqual(['A']);
|
||||
rooms.submit(room, ann, { pick: 4 }, 0);
|
||||
expect(room.resolved).toBe(0);
|
||||
rooms.submit(room, ann, { pick: 3, final: true }, 0);
|
||||
expect(room.resolved).toBe(1);
|
||||
expect(room.state!.rounds[0].picks).toEqual({ A: 3, B: 2 });
|
||||
rooms.submit(room, bo, { pick: 1, final: true }, 1);
|
||||
expect(() => rooms.submit(room, bo, { pick: 2 }, 1)).toThrow(/not your move/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user