You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/denisovdennis/autohero/internal/model"
|
|
"github.com/denisovdennis/autohero/internal/storage"
|
|
)
|
|
|
|
func TestBuildOfflineReportFromDigest_Fought(t *testing.T) {
|
|
h := &GameHandler{}
|
|
hero := &model.Hero{State: model.StateWalking, HP: 100}
|
|
d := storage.OfflineDigestRow{
|
|
MonstersKilled: 2,
|
|
XPGained: 10,
|
|
GoldGained: 5,
|
|
Loot: []model.LootDrop{},
|
|
}
|
|
r := h.buildOfflineReportFromDigest(hero, time.Minute, d)
|
|
if r == nil {
|
|
t.Fatal("expected report")
|
|
}
|
|
if r.MonstersKilled != 2 || r.XPGained != 10 || r.GoldGained != 5 {
|
|
t.Fatalf("unexpected counters: %+v", r)
|
|
}
|
|
if r.Message == "" {
|
|
t.Fatal("expected message")
|
|
}
|
|
}
|
|
|
|
func TestBuildOfflineReportFromDigest_EmptyAlive(t *testing.T) {
|
|
h := &GameHandler{}
|
|
hero := &model.Hero{State: model.StateWalking, HP: 100}
|
|
d := storage.OfflineDigestRow{Loot: []model.LootDrop{}}
|
|
if r := h.buildOfflineReportFromDigest(hero, time.Minute, d); r != nil {
|
|
t.Fatalf("expected nil, got %+v", r)
|
|
}
|
|
}
|
|
|
|
func TestBuildOfflineReportFromDigest_DeadNoDigest(t *testing.T) {
|
|
h := &GameHandler{}
|
|
hero := &model.Hero{State: model.StateDead, HP: 0}
|
|
d := storage.OfflineDigestRow{Loot: []model.LootDrop{}}
|
|
r := h.buildOfflineReportFromDigest(hero, time.Minute, d)
|
|
if r == nil {
|
|
t.Fatal("expected death message report")
|
|
}
|
|
}
|