core/internal/domain/domaintest/player_snapshot.go

91 lines
1.7 KiB
Go

package domaintest
import (
"time"
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
"github.com/brianvoe/gofakeit/v7"
"github.com/stretchr/testify/require"
)
type PlayerSnapshotCursorConfig struct {
ID int
ServerKey string
Date time.Time
}
func NewPlayerSnapshotCursor(tb TestingTB, opts ...func(cfg *PlayerSnapshotCursorConfig)) domain.PlayerSnapshotCursor {
tb.Helper()
cfg := &PlayerSnapshotCursorConfig{
ID: RandID(),
ServerKey: RandServerKey(),
Date: gofakeit.Date(),
}
for _, opt := range opts {
opt(cfg)
}
psc, err := domain.NewPlayerSnapshotCursor(
cfg.ID,
cfg.ServerKey,
cfg.Date,
)
require.NoError(tb, err)
return psc
}
type PlayerSnapshotConfig struct {
ID int
PlayerID int
ServerKey string
NumVillages int
Points int
Rank int
TribeID int
OD domain.OpponentsDefeated
Date time.Time
CreatedAt time.Time
}
func NewPlayerSnapshot(tb TestingTB, opts ...func(cfg *PlayerSnapshotConfig)) domain.PlayerSnapshot {
tb.Helper()
now := time.Now()
cfg := &PlayerSnapshotConfig{
ID: RandID(),
PlayerID: RandID(),
ServerKey: RandServerKey(),
NumVillages: gofakeit.IntRange(1, 10000),
Points: gofakeit.IntRange(1, 10000),
Rank: gofakeit.IntRange(1, 10000),
TribeID: RandID(),
OD: NewOpponentsDefeated(tb),
Date: now,
CreatedAt: now,
}
for _, opt := range opts {
opt(cfg)
}
ps, err := domain.UnmarshalPlayerSnapshotFromDatabase(
cfg.ID,
cfg.PlayerID,
cfg.ServerKey,
cfg.NumVillages,
cfg.Points,
cfg.Rank,
cfg.TribeID,
cfg.OD,
cfg.Date,
cfg.CreatedAt,
)
require.NoError(tb, err)
return ps
}