2024-01-02 09:54:11 +00:00
|
|
|
package domaintest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2024-04-06 04:32:29 +00:00
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
2024-03-01 07:15:06 +00:00
|
|
|
"github.com/brianvoe/gofakeit/v7"
|
2024-01-02 09:54:11 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2024-03-05 06:14:41 +00:00
|
|
|
type VillageCursorConfig struct {
|
|
|
|
ID int
|
|
|
|
ServerKey string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewVillageCursor(tb TestingTB, opts ...func(cfg *VillageCursorConfig)) domain.VillageCursor {
|
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
cfg := &VillageCursorConfig{
|
|
|
|
ID: RandID(),
|
|
|
|
ServerKey: RandServerKey(),
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(cfg)
|
|
|
|
}
|
|
|
|
|
2024-03-10 08:30:03 +00:00
|
|
|
vc, err := domain.NewVillageCursor(
|
2024-03-05 06:14:41 +00:00
|
|
|
cfg.ID,
|
|
|
|
cfg.ServerKey,
|
|
|
|
)
|
|
|
|
require.NoError(tb, err)
|
|
|
|
|
2024-03-10 08:30:03 +00:00
|
|
|
return vc
|
2024-03-05 06:14:41 +00:00
|
|
|
}
|
|
|
|
|
2024-01-02 09:54:11 +00:00
|
|
|
type VillageConfig struct {
|
|
|
|
ID int
|
|
|
|
ServerKey string
|
|
|
|
PlayerID int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewVillage(tb TestingTB, opts ...func(cfg *VillageConfig)) domain.Village {
|
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
cfg := &VillageConfig{
|
|
|
|
ID: RandID(),
|
|
|
|
ServerKey: RandServerKey(),
|
|
|
|
PlayerID: gofakeit.IntRange(0, 10000),
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
v, err := domain.UnmarshalVillageFromDatabase(
|
|
|
|
cfg.ID,
|
|
|
|
cfg.ServerKey,
|
|
|
|
gofakeit.LetterN(50),
|
|
|
|
gofakeit.IntRange(1, 10000),
|
2024-03-06 07:14:31 +00:00
|
|
|
gofakeit.IntRange(1, 999),
|
|
|
|
gofakeit.IntRange(1, 999),
|
2024-01-02 09:54:11 +00:00
|
|
|
gofakeit.LetterN(3),
|
|
|
|
0,
|
|
|
|
cfg.PlayerID,
|
|
|
|
gofakeit.URL(),
|
|
|
|
time.Now(),
|
|
|
|
)
|
|
|
|
require.NoError(tb, err)
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
2024-03-06 06:35:26 +00:00
|
|
|
|
|
|
|
type VillageWithRelationsConfig struct {
|
2024-03-10 09:37:44 +00:00
|
|
|
VillageOptions []func(cfg *VillageConfig)
|
|
|
|
PlayerOptions []func(cfg *PlayerWithRelationsConfig)
|
2024-03-06 06:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewVillageWithRelations(tb TestingTB, opts ...func(cfg *VillageWithRelationsConfig)) domain.VillageWithRelations {
|
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
cfg := &VillageWithRelationsConfig{}
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(cfg)
|
|
|
|
}
|
|
|
|
|
2024-03-10 09:37:44 +00:00
|
|
|
v := NewVillage(tb, cfg.VillageOptions...)
|
2024-03-06 06:35:26 +00:00
|
|
|
|
|
|
|
if v.PlayerID() > 0 {
|
2024-03-10 09:37:44 +00:00
|
|
|
cfg.PlayerOptions = append([]func(cfg *PlayerWithRelationsConfig){
|
|
|
|
func(cfg *PlayerWithRelationsConfig) {
|
|
|
|
cfg.PlayerOptions = append(cfg.PlayerOptions, func(cfg *PlayerConfig) {
|
|
|
|
cfg.ID = v.PlayerID()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}, cfg.PlayerOptions...)
|
|
|
|
}
|
|
|
|
|
|
|
|
var player domain.PlayerMetaWithRelations
|
|
|
|
if len(cfg.PlayerOptions) > 0 {
|
|
|
|
player = NewPlayerWithRelations(tb, cfg.PlayerOptions...).Meta()
|
2024-03-06 06:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return v.WithRelations(domain.NullPlayerMetaWithRelations{
|
2024-03-10 09:37:44 +00:00
|
|
|
V: player,
|
|
|
|
Valid: !player.IsZero(),
|
2024-03-06 06:35:26 +00:00
|
|
|
})
|
|
|
|
}
|