aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/manager_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/casino/manager_test.go')
-rw-r--r--internal/casino/manager_test.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/internal/casino/manager_test.go b/internal/casino/manager_test.go
index 50cf114..fa26aa1 100644
--- a/internal/casino/manager_test.go
+++ b/internal/casino/manager_test.go
@@ -4,6 +4,7 @@ import "testing"
type testWallet struct {
chips, credits, paid int
+ open []Wager
}
func (w *testWallet) Wager(amount int) (Wager, error) {
@@ -17,7 +18,9 @@ func (w *testWallet) Wager(amount int) (Wager, error) {
w.chips -= chips
credits := amount - chips
w.credits -= credits
- return Wager{Total: amount, Chips: chips, Credits: credits}, nil
+ wager := Wager{Total: amount, Chips: chips, Credits: credits}
+ w.open = append(w.open, wager)
+ return wager, nil
}
func (w *testWallet) PayCredits(amount int) error {
@@ -25,6 +28,26 @@ func (w *testWallet) PayCredits(amount int) error {
return nil
}
+// ResolveStakes mirrors the production wallet: every outstanding stake is
+// settled (no longer refundable).
+func (w *testWallet) ResolveStakes() { w.open = nil }
+
+// RefundOutstanding returns every outstanding stake to the balances and
+// resolves the stakes, mirroring the production refund path: credits are
+// paid through PayCredits (recorded in paid), chips return as chips.
+func (w *testWallet) RefundOutstanding() (chips, credits int, err error) {
+ for _, wager := range w.open {
+ chips += wager.Chips
+ credits += wager.Credits
+ }
+ w.open = nil
+ w.chips += chips
+ if credits > 0 {
+ w.paid += credits
+ }
+ return chips, credits, nil
+}
+
func TestMixedWagerUsesChipsFirst(t *testing.T) {
w := &testWallet{chips: 7, credits: 50}
wager, err := w.Wager(12)