aboutsummaryrefslogtreecommitdiff
path: root/internal/game/credits_pickup_test.go
blob: 61509e434433f007b9043723b8db6faccc31c7df (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 game

import (
	"testing"

	"thehouseoficarus/internal/net"
)

// TestPickupCreditsSentinelQuantity: credit pickups request a sentinel
// quantity far above any possible ground stock. RemoveReservedItem is
// all-or-nothing and rejects such a request; the pickup must use capped
// removal so picking up 10 credits succeeds instead of answering
// "That's not yours!".
func TestPickupCreditsSentinelQuantity(t *testing.T) {
	h := newHarness(t)
	h.seedAccount("alice", "pw", false)
	p := h.seedCharacter("alice", "alice")
	h.g.RunOnOwner(func() {
		p.Credits = 100
		h.g.World.AddGroundItem(p.RoomID, "credits", 10)
		sess := &net.Session{Player: p, Conn: newChanConn()}
		h.g.pickupCredits(sess, p, "credits")
		if p.Credits != 110 {
			t.Errorf("credits after pickup = %d, want 110 (output: %s)", p.Credits, sess.Conn.(*chanConn).Bytes())
		}
	})
}

// TestGetAllPicksUpCreditsWithSentinelQuantity: the same sentinel rule for
// the "get all" path.
func TestGetAllPicksUpCreditsWithSentinelQuantity(t *testing.T) {
	h := newHarness(t)
	h.seedAccount("alice", "pw", false)
	p := h.seedCharacter("alice", "alice")
	h.g.RunOnOwner(func() {
		p.Credits = 0
		h.g.World.AddGroundItem(p.RoomID, "credits", 10)
		sess := &net.Session{Player: p, Conn: newChanConn()}
		h.g.doGetAll(sess)
		if p.Credits != 10 {
			t.Errorf("credits after get-all = %d, want 10 (output: %s)", p.Credits, sess.Conn.(*chanConn).Bytes())
		}
	})
}