51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/modules/player/model"
|
|
"testing"
|
|
)
|
|
|
|
func TestFindPetDataSnapshotInPlayerInfo(t *testing.T) {
|
|
t.Run("pet list", func(t *testing.T) {
|
|
want := model.PetInfo{CatchTime: 1001, Level: 55}
|
|
info := model.PlayerInfo{
|
|
PetList: []model.PetInfo{want},
|
|
}
|
|
|
|
got, ok := findPetDataSnapshotInPlayerInfo(info, want.CatchTime)
|
|
if !ok {
|
|
t.Fatal("expected pet snapshot in pet list")
|
|
}
|
|
if got.CatchTime != want.CatchTime || got.Level != want.Level {
|
|
t.Fatalf("unexpected pet snapshot: %+v", got)
|
|
}
|
|
})
|
|
|
|
t.Run("backup pet list", func(t *testing.T) {
|
|
want := model.PetInfo{CatchTime: 2002, Level: 66}
|
|
info := model.PlayerInfo{
|
|
BackupPetList: []model.PetInfo{want},
|
|
}
|
|
|
|
got, ok := findPetDataSnapshotInPlayerInfo(info, want.CatchTime)
|
|
if !ok {
|
|
t.Fatal("expected pet snapshot in backup pet list")
|
|
}
|
|
if got.CatchTime != want.CatchTime || got.Level != want.Level {
|
|
t.Fatalf("unexpected pet snapshot: %+v", got)
|
|
}
|
|
})
|
|
|
|
t.Run("not found", func(t *testing.T) {
|
|
info := model.PlayerInfo{
|
|
PetList: []model.PetInfo{{CatchTime: 3003}},
|
|
BackupPetList: []model.PetInfo{{CatchTime: 4004}},
|
|
}
|
|
|
|
_, ok := findPetDataSnapshotInPlayerInfo(info, 9999)
|
|
if ok {
|
|
t.Fatal("expected missing pet snapshot")
|
|
}
|
|
})
|
|
}
|