aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_rooms_casino_evict_test.go
blob: 426c13a54ec18dbb2d2629aedcb6fe131c41d5e3 (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
package admin

// Regression: deleting a single room through the editor API must evict the
// room's cached casino games and refund their outstanding wagers, exactly
// like the bulk-delete path does. Skipping eviction strands seated players'
// wagers in games whose room no longer exists.

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestRoomDeleteEvictsCasinoGames(t *testing.T) {
	s := newTestAdminServer(t, map[int]string{1: "id: 1\nname: Room\n"})
	var evicted []int
	s.evictRoom = func(id int) { evicted = append(evicted, id) }

	rec := httptest.NewRecorder()
	s.handleRoomByID(rec, httptest.NewRequest(http.MethodDelete, "/api/rooms/1", nil))
	if _, ok := s.world.GetRoomPath(1); ok {
		t.Fatalf("room was not removed: %s", rec.Body.String())
	}
	if len(evicted) != 1 || evicted[0] != 1 {
		t.Fatalf("room deletion evicted %v, want [1] (outstanding wagers were not resolved)", evicted)
	}
}