aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/machine_test.go
blob: fdfa42c795000ed61d00fd9dcaab9ac0dcc7ffd1 (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
package casino

import (
	"math/rand"
	"testing"
)

func TestMachineFreeSpinsUseProfileCount(t *testing.T) {
	m := newMachine(1, MachineConfig{ID: "slots", Game: GameSlots}, rand.New(rand.NewSource(7)))
	m.profile.FreeSpinCount = 5
	m.player = &Participant{Name: "alice", Connected: true, Wallet: &testWallet{credits: 100}}
	m.spinBet = 10
	m.spin = &SlotSpin{ScatterCount: 3}
	events := m.finishSpin()
	if m.freeSpins != 4 {
		t.Fatalf("freeSpins=%d, want 4 remaining after the first of 5 chained spins", m.freeSpins)
	}
	if m.phase != machineSpinning {
		t.Fatalf("phase=%s, want spinning", m.phase)
	}
	if !hasMessage(events, "trigger 5 free spins") {
		t.Fatalf("missing profile-count free spin message: %+v", events)
	}
}

func TestMachineMenuEventCarriesStructuredMenu(t *testing.T) {
	m := newMachine(1, MachineConfig{ID: "slots", Game: GameSlots}, rand.New(rand.NewSource(7)))
	m.player = &Participant{Name: "alice", Connected: true}
	events := m.privateMenu("You sit down at the slot machine.")
	if len(events) != 1 || events[0].Menu == nil || events[0].Menu.Kind != MenuSlotCommands || events[0].Menu.Body == "" {
		t.Fatalf("slot menu event=%+v", events)
	}
}

func TestMachineLeaveResetsPayoutRemainder(t *testing.T) {
	m := newMachine(1, MachineConfig{ID: "slots", Game: GameSlots}, rand.New(rand.NewSource(7)))
	m.player = &Participant{Name: "alice", Connected: true}
	m.bet = 10
	m.payoutRemainder = 0.5
	m.leave("alice")
	if m.payoutRemainder != 0 {
		t.Fatalf("payoutRemainder=%v leaked to the next player", m.payoutRemainder)
	}
}