-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsalvage_test.go
More file actions
33 lines (31 loc) · 1.05 KB
/
Copy pathsalvage_test.go
File metadata and controls
33 lines (31 loc) · 1.05 KB
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
package idlerpg
import (
"context"
"testing"
)
func TestSalvageGivesScrapGold(t *testing.T) {
m, r, st := newMgr()
ctx := context.Background()
m.Handle(chanMsg("alice", "!rpg"))
// give alice an existing weapon so the next find replaces (salvages) it
st.HSet(ctx, sheetKey("net|alice"), itemField("weapon"), 5)
st.HSet(ctx, sheetKey("net|alice"), rarityField("weapon"), 0)
goldBefore := int64(0)
if s, _ := st.HGetAll(ctx, sheetKey("net|alice")); s["gold"] != goldBefore {
goldBefore = s["gold"]
}
p := player{network: "net", nick: "alice", channel: "#chan", key: "net|alice"}
// force a strong find by passing a high level (so it beats the level-5 weapon)
for i := 0; i < 40; i++ {
m.findItem(ctx, p, 60)
if s, _ := st.HGetAll(ctx, sheetKey("net|alice")); s["gold"] > goldBefore {
break
}
}
if s, _ := st.HGetAll(ctx, sheetKey("net|alice")); s["gold"] <= goldBefore {
t.Fatalf("replacing gear should yield scrap gold, gold=%d", s["gold"])
}
if !r.has("salvaged the old one") {
t.Fatalf("a salvage should be announced, got %v", r.lines)
}
}