// Whether handing a seat chips also puts them back in the game. const test = require("node:test"); const assert = require("node:assert"); const { Betting, makeTable } = require("./load"); test("a busted player who has been sat out comes back in", () => { const state = makeTable({ seatCount: 6, seated: [0, 1, 2], stack: 100 }); state.seats[1].stack = 0; Betting.beginHand(state); // the deal sits them out assert.equal(state.seats[1].inHand, false); assert.equal(Betting.buyInDealsThemIn(state.seats[1]), true); }); test("a chair being bought into for the first time comes in", () => { const state = makeTable({ seatCount: 6, seated: [0, 1], stack: 100 }); state.seats[4].name = "Eve"; state.seats[4].stack = null; assert.equal(Betting.buyInDealsThemIn(state.seats[4]), true); }); test("a seat sat out while holding chips stays out", () => { // A dealer sat them out on purpose and is topping them up. Dealing them back in // would be the tool guessing at something it wasn't told. const state = makeTable({ seatCount: 6, seated: [0, 1, 2], stack: 100 }); state.seats[2].inHand = false; assert.equal(Betting.buyInDealsThemIn(state.seats[2]), false); }); test("somebody already in the hand is left exactly where they are", () => { const state = makeTable({ seatCount: 6, seated: [0, 1, 2], stack: 100 }); assert.equal(Betting.buyInDealsThemIn(state.seats[0]), false); // Including a player who is in but out of chips — they're all-in, not sat out. state.seats[2].stack = 0; assert.equal(state.seats[2].inHand, true); assert.equal(Betting.buyInDealsThemIn(state.seats[2]), false); }); test("a blank stack field reads as nothing recorded, not as a number", () => { const state = makeTable({ seatCount: 6, seated: [0, 1], stack: 100 }); state.seats[3].name = "Dee"; state.seats[3].stack = ""; assert.equal(Betting.buyInDealsThemIn(state.seats[3]), true); }); test("it doesn't ask the table what a missing stack would have been", () => { // stackOf substitutes the table's starting stack for a seat that has none, which // would make a seat with nothing recorded look like it was holding chips. const state = makeTable({ seatCount: 6, seated: [0, 1], stack: 100 }); state.defaultStack = 500; state.seats[4].name = "Eve"; state.seats[4].stack = null; assert.equal(Betting.stackOf(state, state.seats[4]), 500); assert.equal(Betting.buyInDealsThemIn(state.seats[4]), true); }); test("asking doesn't change anything", () => { const state = makeTable({ seatCount: 6, seated: [0, 1, 2], stack: 100 }); state.seats[2].stack = 0; state.seats[2].inHand = false; const before = JSON.stringify(state); Betting.buyInDealsThemIn(state.seats[2]); assert.equal(JSON.stringify(state), before); }); test("nothing to decide about a seat that isn't there", () => { assert.equal(Betting.buyInDealsThemIn(null), false); assert.equal(Betting.buyInDealsThemIn(undefined), false); });