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

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

	"thehouseoficarus/internal/casino"
	"thehouseoficarus/internal/world"
)

// TestCasinoMachineAddressableByID: a slot cabinet's authored id must be a
// usable address. The shipped room declares `id: huff_puff_01` with a variant,
// and matching only the variant/game left the cabinet unreachable as
// `play huff_puff_01`.
func TestCasinoMachineAddressableByID(t *testing.T) {
	dir := t.TempDir()
	if err := os.MkdirAll(filepath.Join(dir, "rooms"), 0755); err != nil {
		t.Fatal(err)
	}
	room := "name: Casino\ncasino_machines:\n  - id: huff_puff_01\n    game: slots\n    variant: huff_and_even_more_puff\n"
	if err := os.WriteFile(filepath.Join(dir, "rooms", "1.yaml"), []byte(room), 0644); err != nil {
		t.Fatal(err)
	}
	g := &Game{Deps: Deps{World: world.New(dir)}, Casino: casino.NewManager(1)}

	machine, ok := g.casinoMachine(1, "huff_puff_01")
	if !ok || machine == nil {
		t.Fatal("machine id huff_puff_01 is not addressable")
	}
}