core/internal/domain/domaintest/player.go

74 lines
1.5 KiB
Go

package domaintest
import (
"time"
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/require"
)
type PlayerConfig struct {
ID int
Points int
NumVillages int
ServerKey string
OD domain.OpponentsDefeated
BestRank int
BestRankAt time.Time
MostPoints int
MostPointsAt time.Time
MostVillages int
MostVillagesAt time.Time
LastActivityAt time.Time
}
func NewPlayer(tb TestingTB, opts ...func(cfg *PlayerConfig)) domain.Player {
tb.Helper()
now := time.Now()
cfg := &PlayerConfig{
ID: RandID(),
ServerKey: RandServerKey(),
Points: gofakeit.IntRange(1, 10000),
NumVillages: gofakeit.IntRange(1, 10000),
OD: NewOpponentsDefeated(tb),
BestRank: gofakeit.IntRange(1, 10000),
BestRankAt: now,
MostPoints: gofakeit.IntRange(1, 10000),
MostPointsAt: now,
MostVillages: gofakeit.IntRange(1, 10000),
MostVillagesAt: now,
LastActivityAt: now,
}
for _, opt := range opts {
opt(cfg)
}
p, err := domain.UnmarshalPlayerFromDatabase(
cfg.ID,
cfg.ServerKey,
gofakeit.LetterN(50),
cfg.NumVillages,
cfg.Points,
gofakeit.IntRange(1, 10000),
gofakeit.IntRange(1, 10000),
cfg.OD,
gofakeit.URL(),
cfg.BestRank,
cfg.BestRankAt,
cfg.MostPoints,
cfg.MostPointsAt,
cfg.MostVillages,
cfg.MostVillagesAt,
cfg.LastActivityAt,
now,
time.Time{},
)
require.NoError(tb, err)
return p
}