aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/unbet_test.go
blob: d132b58d33947eebdd03701bea055e2a061ab348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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)
	}
}