diff options
Diffstat (limited to 'internal/casino/unbet_test.go')
| -rw-r--r-- | internal/casino/unbet_test.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/internal/casino/unbet_test.go b/internal/casino/unbet_test.go new file mode 100644 index 0000000..d132b58 --- /dev/null +++ b/internal/casino/unbet_test.go @@ -0,0 +1,59 @@ +package casino + +import "testing" + +// The single unbet command must take back every pre-round wager at every +// table game; games no longer accept per-target "unbet <spot>" spellings. +func TestUnbetRefundsPreRoundWagersEveryGame(t *testing.T) { + t.Run("baccarat", func(t *testing.T) { + tab := newBaccaratTestTable(TableConfig{ID: "bac", Game: GameBaccarat, BettingTicks: 10}) + tab.join("a") + tab.join("b") + w := &testWallet{chips: 100} + tab.bet("a", "banker", 10, w) + if events := tab.action("a", "unbet"); !hasMessage(events, "take back") { + t.Fatalf("unbet: %+v", events) + } + if w.chips+w.paid != 100 || len(w.open) != 0 { + t.Fatalf("wallet not refunded: chips=%d paid=%d open=%d", w.chips, w.paid, len(w.open)) + } + }) + t.Run("blackjack", func(t *testing.T) { + tab := newBlackjackTable(1, TableConfig{ID: "bj", Game: GameBlackjack, BettingTicks: 10, + Blackjack: BlackjackConfig{Decks: 8, ActionTicks: 10}}, newTestRand()) + tab.join("a") + tab.join("b") + w := &testWallet{chips: 100} + tab.bet("a", "", 10, w) + if events := tab.action("a", "unbet"); !hasMessage(events, "take back") { + t.Fatalf("unbet: %+v", events) + } + if w.chips+w.paid != 100 || len(w.open) != 0 { + t.Fatalf("wallet not refunded: chips=%d paid=%d open=%d", w.chips, w.paid, len(w.open)) + } + }) + t.Run("roulette", func(t *testing.T) { + tab := rouletteFixture() + tab.join("a") + tab.join("idle") + w := &testWallet{chips: 100} + tab.bet("a", "red", 10, w) + if events := tab.action("a", "unbet"); !hasMessage(events, "take back") { + t.Fatalf("unbet: %+v", events) + } + if w.chips+w.paid != 100 || len(w.open) != 0 { + t.Fatalf("wallet not refunded: chips=%d paid=%d open=%d", w.chips, w.paid, len(w.open)) + } + if tab.phase != phaseWaiting { + t.Fatalf("empty roulette table did not reset: %s", tab.phase) + } + }) +} + +func TestUnbetWithNothingCommitted(t *testing.T) { + tab := newBaccaratTestTable(TableConfig{ID: "bac", Game: GameBaccarat, BettingTicks: 10}) + tab.join("a") + if events := tab.action("a", "unbet"); !hasMessage(events, "Nothing to take back") { + t.Fatalf("unbet with no wager: %+v", events) + } +} |
