package domaintest import ( "math" "time" "gitea.dwysokinski.me/twhelp/corev3/internal/domain" "github.com/brianvoe/gofakeit/v7" "github.com/stretchr/testify/require" ) func RandTribeTag() string { return gofakeit.LetterN(5) } type TribeCursorConfig struct { ID int ServerKey string ODScoreAtt int ODScoreDef int ODScoreTotal int Points int Dominance float64 DeletedAt time.Time } func NewTribeCursor(tb TestingTB, opts ...func(cfg *TribeCursorConfig)) domain.TribeCursor { tb.Helper() cfg := &TribeCursorConfig{ ID: RandID(), ServerKey: RandServerKey(), ODScoreAtt: gofakeit.IntRange(0, math.MaxInt), ODScoreDef: gofakeit.IntRange(0, math.MaxInt), ODScoreTotal: gofakeit.IntRange(0, math.MaxInt), Points: gofakeit.IntRange(0, math.MaxInt), Dominance: gofakeit.Float64Range(0.1, 99.9), DeletedAt: time.Time{}, } for _, opt := range opts { opt(cfg) } tc, err := domain.NewTribeCursor( cfg.ID, cfg.ServerKey, cfg.ODScoreAtt, cfg.ODScoreDef, cfg.ODScoreTotal, cfg.Points, cfg.Dominance, cfg.DeletedAt, ) require.NoError(tb, err) return tc } type TribeConfig struct { ID int ServerKey string Tag string OD domain.OpponentsDefeated BestRank int BestRankAt time.Time MostPoints int MostPointsAt time.Time MostVillages int MostVillagesAt time.Time DeletedAt time.Time } func NewTribe(tb TestingTB, opts ...func(cfg *TribeConfig)) domain.Tribe { tb.Helper() now := time.Now() cfg := &TribeConfig{ ID: RandID(), ServerKey: RandServerKey(), Tag: RandTribeTag(), OD: NewOpponentsDefeated(tb), BestRank: gofakeit.IntRange(1, 10000), BestRankAt: now, MostPoints: gofakeit.IntRange(1, 10000), MostPointsAt: now, MostVillages: gofakeit.IntRange(1, 10000), MostVillagesAt: now, DeletedAt: time.Time{}, } for _, opt := range opts { opt(cfg) } t, err := domain.UnmarshalTribeFromDatabase( cfg.ID, cfg.ServerKey, gofakeit.LetterN(50), cfg.Tag, gofakeit.IntRange(1, 10000), gofakeit.IntRange(1, 10000), gofakeit.IntRange(1, 10000), gofakeit.IntRange(1, 10000), gofakeit.IntRange(1, 10000), cfg.OD, gofakeit.URL(), gofakeit.Float64Range(0.1, 99.9), cfg.BestRank, cfg.BestRankAt, cfg.MostPoints, cfg.MostPointsAt, cfg.MostVillages, cfg.MostVillagesAt, now, cfg.DeletedAt, ) require.NoError(tb, err) return t } type TribeMetaConfig struct { ID int Tag string } func NewTribeMeta(tb TestingTB, opts ...func(cfg *TribeMetaConfig)) domain.TribeMeta { tb.Helper() cfg := &TribeMetaConfig{ ID: RandID(), Tag: RandTribeTag(), } for _, opt := range opts { opt(cfg) } return NewTribe(tb, func(tribeCfg *TribeConfig) { tribeCfg.ID = cfg.ID tribeCfg.Tag = cfg.Tag }).Meta() }