aboutsummaryrefslogtreecommitdiff
path: root/internal/game/blackjack_rules_test.go
blob: ebf5f64356410b663ede95cec74ce7d9647bb2d4 (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
package game

import (
	"os"
	"path/filepath"
	"strings"
	"testing"

	"thehouseoficarus/internal/casino"
	"thehouseoficarus/internal/net"
	"thehouseoficarus/internal/player"
	"thehouseoficarus/internal/world"
)

func TestLookBlackjackFixtureWithoutScenery(t *testing.T) {
	dir := t.TempDir()
	if err := os.MkdirAll(filepath.Join(dir, "rooms"), 0755); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(filepath.Join(dir, "rooms", "1.yaml"), []byte("name: Anywhere\ncasino_tables:\n- id: test\n  game: blackjack\n  blackjack:\n    decks: 1\n    blackjack_payout: 1.2\n"), 0644); err != nil {
		t.Fatal(err)
	}
	g := &Game{Deps: Deps{World: world.New(dir)}, Casino: casino.NewManager(1)}
	conn := &casinoTestConn{}
	sess := &net.Session{Player: player.New("alice"), Conn: conn}
	sess.Player.RoomID = 1
	for _, target := range []string{"blackjack", "blackjack table", "table", "test", "test table"} {
		conn.data = nil
		if !g.lookCasinoTable(sess, target, casino.GameBlackjack) {
			t.Fatalf("did not match %q", target)
		}
		text := plainRoulette(string(conn.data))
		for _, want := range []string{"DECKS", "1", "BLACKJACK PAYS 6 TO 5", "AFTER SPLIT" + strings.Repeat(" ", 21) + "YES"} {
			if !strings.Contains(text, want) {
				t.Fatalf("look %s missing %q: %s", target, want, text)
			}
		}
	}
	if g.lookCasinoTable(sess, "other", casino.GameBlackjack) {
		t.Fatal("matched unrelated target")
	}
}