refactor: base models #106
|
@ -37,52 +37,44 @@ func TestEnnoblement_Create(t *testing.T) {
|
|||
|
||||
params := []domain.CreateEnnoblementParams{
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: village1.ID,
|
||||
NewOwnerID: playerSquirtle.ID,
|
||||
NewTribeID: playerSquirtle.TribeID,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: village1.Points,
|
||||
CreatedAt: time.Now().Add(-20 * time.Minute),
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
VillageID: village1.ID,
|
||||
NewOwnerID: playerSquirtle.ID,
|
||||
NewTribeID: playerSquirtle.TribeID,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: village1.Points,
|
||||
CreatedAt: time.Now().Add(-20 * time.Minute),
|
||||
ServerKey: server.Key,
|
||||
},
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: village2.ID,
|
||||
NewOwnerID: playerSquirtle.ID,
|
||||
NewTribeID: playerSquirtle.TribeID,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: village2.Points,
|
||||
CreatedAt: time.Now().Add(-20 * time.Minute),
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
VillageID: village2.ID,
|
||||
NewOwnerID: playerSquirtle.ID,
|
||||
NewTribeID: playerSquirtle.TribeID,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: village2.Points,
|
||||
CreatedAt: time.Now().Add(-20 * time.Minute),
|
||||
ServerKey: server.Key,
|
||||
},
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: village1.ID,
|
||||
NewOwnerID: playerTomasKH96.ID,
|
||||
NewTribeID: playerTomasKH96.TribeID,
|
||||
OldOwnerID: playerSquirtle.ID,
|
||||
OldTribeID: playerSquirtle.TribeID,
|
||||
Points: village1.Points,
|
||||
CreatedAt: time.Now().Add(-5 * time.Minute),
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
VillageID: village1.ID,
|
||||
NewOwnerID: playerTomasKH96.ID,
|
||||
NewTribeID: playerTomasKH96.TribeID,
|
||||
OldOwnerID: playerSquirtle.ID,
|
||||
OldTribeID: playerSquirtle.TribeID,
|
||||
Points: village1.Points,
|
||||
CreatedAt: time.Now().Add(-5 * time.Minute),
|
||||
ServerKey: server.Key,
|
||||
},
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: village2.ID,
|
||||
NewOwnerID: playerTomasKH96.ID,
|
||||
NewTribeID: playerTomasKH96.TribeID,
|
||||
OldOwnerID: playerSquirtle.ID,
|
||||
OldTribeID: playerSquirtle.TribeID,
|
||||
Points: village2.Points,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
VillageID: village2.ID,
|
||||
NewOwnerID: playerTomasKH96.ID,
|
||||
NewTribeID: playerTomasKH96.TribeID,
|
||||
OldOwnerID: playerSquirtle.ID,
|
||||
OldTribeID: playerSquirtle.TribeID,
|
||||
Points: village2.Points,
|
||||
CreatedAt: time.Now(),
|
||||
ServerKey: server.Key,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -95,10 +87,18 @@ func TestEnnoblement_Create(t *testing.T) {
|
|||
for _, p := range params {
|
||||
var found bool
|
||||
for _, e := range ennoblements {
|
||||
if e.CreatedAt.Unix() != p.CreatedAt.Unix() || p.ServerKey != e.ServerKey {
|
||||
continue
|
||||
p2 := domain.CreateEnnoblementParams{
|
||||
VillageID: e.VillageID,
|
||||
NewOwnerID: e.NewOwnerID,
|
||||
NewTribeID: e.NewTribeID,
|
||||
OldOwnerID: e.OldOwnerID,
|
||||
OldTribeID: e.OldTribeID,
|
||||
Points: e.Points,
|
||||
CreatedAt: e.CreatedAt,
|
||||
ServerKey: e.ServerKey,
|
||||
}
|
||||
if cmp.Equal(p.BaseEnnoblement, e.BaseEnnoblement, cmpopts.IgnoreTypes(time.Time{})) {
|
||||
|
||||
if cmp.Equal(p, p2, cmpopts.EquateApproxTime(1*time.Second)) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
@ -124,8 +124,14 @@ func TestEnnoblement_Create(t *testing.T) {
|
|||
ennoblement := getEnnoblementFromFixture(t, fixture, "pl169-village-2-1")
|
||||
|
||||
err = repo.Create(context.Background(), domain.CreateEnnoblementParams{
|
||||
BaseEnnoblement: ennoblement.ToDomain().BaseEnnoblement,
|
||||
ServerKey: ennoblement.ServerKey,
|
||||
VillageID: ennoblement.VillageID,
|
||||
NewOwnerID: ennoblement.NewOwnerID,
|
||||
NewTribeID: ennoblement.NewTribeID,
|
||||
OldOwnerID: ennoblement.OldOwnerID,
|
||||
OldTribeID: ennoblement.OldTribeID,
|
||||
Points: ennoblement.Points,
|
||||
CreatedAt: ennoblement.CreatedAt,
|
||||
ServerKey: ennoblement.ServerKey,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
|
@ -82,21 +82,19 @@ func (e Ennoblement) ToDomain() domain.Ennoblement {
|
|||
}
|
||||
|
||||
return domain.Ennoblement{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: e.VillageID,
|
||||
NewOwnerID: e.NewOwnerID,
|
||||
NewTribeID: e.NewTribeID,
|
||||
OldOwnerID: e.OldOwnerID,
|
||||
OldTribeID: e.OldTribeID,
|
||||
Points: e.Points,
|
||||
CreatedAt: e.CreatedAt,
|
||||
},
|
||||
ID: e.ID,
|
||||
Village: village,
|
||||
NewOwner: newOwner,
|
||||
NewTribe: newTribe,
|
||||
OldOwner: oldOwner,
|
||||
OldTribe: oldTribe,
|
||||
ServerKey: e.ServerKey,
|
||||
VillageID: e.VillageID,
|
||||
NewOwnerID: e.NewOwnerID,
|
||||
NewTribeID: e.NewTribeID,
|
||||
OldOwnerID: e.OldOwnerID,
|
||||
OldTribeID: e.OldTribeID,
|
||||
Points: e.Points,
|
||||
CreatedAt: e.CreatedAt,
|
||||
ID: e.ID,
|
||||
Village: village,
|
||||
NewOwner: newOwner,
|
||||
NewTribe: newTribe,
|
||||
OldOwner: oldOwner,
|
||||
OldTribe: oldTribe,
|
||||
ServerKey: e.ServerKey,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"time"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/bundb/internal/model"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
|
@ -15,25 +17,34 @@ func TestEnnoblement(t *testing.T) {
|
|||
|
||||
var id int64 = 1234
|
||||
params := domain.CreateEnnoblementParams{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: 112,
|
||||
NewOwnerID: 113,
|
||||
NewTribeID: 114,
|
||||
OldOwnerID: 115,
|
||||
OldTribeID: 116,
|
||||
Points: 117,
|
||||
CreatedAt: time.Now().Add(-20 * time.Hour),
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
VillageID: 112,
|
||||
NewOwnerID: 113,
|
||||
NewTribeID: 114,
|
||||
OldOwnerID: 115,
|
||||
OldTribeID: 116,
|
||||
Points: 117,
|
||||
CreatedAt: time.Now().Add(-20 * time.Hour),
|
||||
ServerKey: "pl151",
|
||||
}
|
||||
|
||||
result := model.NewEnnoblement(params)
|
||||
result.ID = id
|
||||
|
||||
ennoblementWithoutRelations := result.ToDomain()
|
||||
assert.Equal(t, params.BaseEnnoblement, ennoblementWithoutRelations.BaseEnnoblement)
|
||||
assert.Equal(t, params.VillageID, ennoblementWithoutRelations.VillageID)
|
||||
assert.Equal(t, params.NewOwnerID, ennoblementWithoutRelations.NewOwnerID)
|
||||
assert.Equal(t, params.NewTribeID, ennoblementWithoutRelations.NewTribeID)
|
||||
assert.Equal(t, params.OldOwnerID, ennoblementWithoutRelations.OldOwnerID)
|
||||
assert.Equal(t, params.OldTribeID, ennoblementWithoutRelations.OldTribeID)
|
||||
assert.Equal(t, params.Points, ennoblementWithoutRelations.Points)
|
||||
assert.Equal(t, params.CreatedAt, ennoblementWithoutRelations.CreatedAt)
|
||||
assert.Equal(t, params.ServerKey, ennoblementWithoutRelations.ServerKey)
|
||||
assert.Equal(t, id, ennoblementWithoutRelations.ID)
|
||||
assert.Zero(t, ennoblementWithoutRelations.Village)
|
||||
assert.Zero(t, ennoblementWithoutRelations.NewOwner)
|
||||
assert.Zero(t, ennoblementWithoutRelations.NewTribe)
|
||||
assert.Zero(t, ennoblementWithoutRelations.OldOwner)
|
||||
assert.Zero(t, ennoblementWithoutRelations.OldTribe)
|
||||
|
||||
result.Village = model.Village{
|
||||
ID: 12345,
|
||||
|
@ -51,9 +62,18 @@ func TestEnnoblement(t *testing.T) {
|
|||
ID: 11234,
|
||||
}
|
||||
ennoblementWithRelations := result.ToDomain()
|
||||
assert.Equal(t, params.BaseEnnoblement, ennoblementWithRelations.BaseEnnoblement)
|
||||
assert.Equal(t, params.ServerKey, ennoblementWithRelations.ServerKey)
|
||||
assert.Equal(t, id, ennoblementWithRelations.ID)
|
||||
assert.Empty(t, cmp.Diff(
|
||||
ennoblementWithoutRelations,
|
||||
ennoblementWithRelations,
|
||||
cmpopts.IgnoreFields(
|
||||
domain.Ennoblement{},
|
||||
"Village",
|
||||
"NewOwner",
|
||||
"NewTribe",
|
||||
"OldOwner",
|
||||
"OldTribe",
|
||||
),
|
||||
))
|
||||
assert.True(t, ennoblementWithRelations.Village.Valid)
|
||||
assert.Equal(t, result.Village.ID, ennoblementWithRelations.Village.Village.ID)
|
||||
assert.True(t, ennoblementWithRelations.NewOwner.Valid)
|
||||
|
|
|
@ -49,19 +49,17 @@ func (p Player) ToDomain() domain.Player {
|
|||
}
|
||||
}
|
||||
return domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated(p.OpponentsDefeated),
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
NumVillages: p.NumVillages,
|
||||
Points: p.Points,
|
||||
Rank: p.Rank,
|
||||
TribeID: p.TribeID,
|
||||
ProfileURL: p.ProfileURL,
|
||||
},
|
||||
ServerKey: p.ServerKey,
|
||||
Tribe: tribe,
|
||||
CreatedAt: p.CreatedAt,
|
||||
DeletedAt: p.DeletedAt,
|
||||
OpponentsDefeated: domain.OpponentsDefeated(p.OpponentsDefeated),
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
NumVillages: p.NumVillages,
|
||||
Points: p.Points,
|
||||
Rank: p.Rank,
|
||||
TribeID: p.TribeID,
|
||||
ProfileURL: p.ProfileURL,
|
||||
ServerKey: p.ServerKey,
|
||||
Tribe: tribe,
|
||||
CreatedAt: p.CreatedAt,
|
||||
DeletedAt: p.DeletedAt,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/bundb/internal/model"
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -14,51 +16,55 @@ func TestPlayer(t *testing.T) {
|
|||
|
||||
deletedAt := time.Now().Add(-100 * time.Hour)
|
||||
playerParams := domain.CreatePlayerParams{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
Rank: 6,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-999",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
}
|
||||
tribeParams := domain.CreateTribeParams{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: playerParams.TribeID,
|
||||
},
|
||||
ServerKey: playerParams.ServerKey,
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
Rank: 6,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-999",
|
||||
ServerKey: "pl151",
|
||||
}
|
||||
|
||||
result := model.NewPlayer(playerParams)
|
||||
|
||||
result.DeletedAt = deletedAt
|
||||
playerWithoutTribe := result.ToDomain()
|
||||
assert.Equal(t, playerParams.BasePlayer, playerWithoutTribe.BasePlayer)
|
||||
assert.EqualValues(t, playerParams.OpponentsDefeated, playerWithoutTribe.OpponentsDefeated)
|
||||
assert.Equal(t, playerParams.ID, playerWithoutTribe.ID)
|
||||
assert.Equal(t, playerParams.Name, playerWithoutTribe.Name)
|
||||
assert.Equal(t, playerParams.NumVillages, playerWithoutTribe.NumVillages)
|
||||
assert.Equal(t, playerParams.Points, playerWithoutTribe.Points)
|
||||
assert.Equal(t, playerParams.Rank, playerWithoutTribe.Rank)
|
||||
assert.Equal(t, playerParams.TribeID, playerWithoutTribe.TribeID)
|
||||
assert.Equal(t, playerParams.ProfileURL, playerWithoutTribe.ProfileURL)
|
||||
assert.Equal(t, playerParams.ServerKey, playerWithoutTribe.ServerKey)
|
||||
assert.WithinDuration(t, time.Now(), playerWithoutTribe.CreatedAt, 10*time.Millisecond)
|
||||
assert.Zero(t, playerWithoutTribe.Tribe)
|
||||
assert.Equal(t, deletedAt, playerWithoutTribe.DeletedAt)
|
||||
|
||||
result.Tribe = model.NewTribe(tribeParams)
|
||||
result.Tribe = model.Tribe{
|
||||
ID: playerParams.TribeID,
|
||||
}
|
||||
result.DeletedAt = time.Time{}
|
||||
playerWithTribe := result.ToDomain()
|
||||
assert.Equal(t, playerParams.BasePlayer, playerWithTribe.BasePlayer)
|
||||
assert.Equal(t, playerParams.ServerKey, playerWithTribe.ServerKey)
|
||||
assert.Empty(t, cmp.Diff(
|
||||
playerWithoutTribe,
|
||||
playerWithTribe,
|
||||
cmpopts.IgnoreFields(domain.Player{}, "Tribe", "DeletedAt"),
|
||||
))
|
||||
assert.WithinDuration(t, time.Now(), playerWithTribe.CreatedAt, 10*time.Millisecond)
|
||||
assert.Zero(t, playerWithTribe.DeletedAt)
|
||||
assert.True(t, playerWithTribe.Tribe.Valid)
|
||||
assert.Equal(t, tribeParams.ID, playerWithTribe.Tribe.Tribe.ID)
|
||||
assert.Equal(t, playerParams.TribeID, playerWithTribe.Tribe.Tribe.ID)
|
||||
}
|
||||
|
|
|
@ -47,21 +47,19 @@ func NewTribe(p domain.CreateTribeParams) Tribe {
|
|||
|
||||
func (t Tribe) ToDomain() domain.Tribe {
|
||||
return domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated(t.OpponentsDefeated),
|
||||
ID: t.ID,
|
||||
Name: t.Name,
|
||||
Tag: t.Tag,
|
||||
NumVillages: t.NumVillages,
|
||||
NumMembers: t.NumMembers,
|
||||
Points: t.Points,
|
||||
AllPoints: t.AllPoints,
|
||||
Rank: t.Rank,
|
||||
ProfileURL: t.ProfileURL,
|
||||
},
|
||||
ServerKey: t.ServerKey,
|
||||
Dominance: t.Dominance,
|
||||
CreatedAt: t.CreatedAt,
|
||||
DeletedAt: t.DeletedAt,
|
||||
OpponentsDefeated: domain.OpponentsDefeated(t.OpponentsDefeated),
|
||||
ID: t.ID,
|
||||
Name: t.Name,
|
||||
Tag: t.Tag,
|
||||
NumVillages: t.NumVillages,
|
||||
NumMembers: t.NumMembers,
|
||||
Points: t.Points,
|
||||
AllPoints: t.AllPoints,
|
||||
Rank: t.Rank,
|
||||
ProfileURL: t.ProfileURL,
|
||||
ServerKey: t.ServerKey,
|
||||
Dominance: t.Dominance,
|
||||
CreatedAt: t.CreatedAt,
|
||||
DeletedAt: t.DeletedAt,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,34 +14,42 @@ func TestTribe(t *testing.T) {
|
|||
|
||||
deletedAt := time.Now().Add(-100 * time.Hour)
|
||||
params := domain.CreateTribeParams{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Tag: "tag 999",
|
||||
NumMembers: 2,
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
AllPoints: 5,
|
||||
Rank: 6,
|
||||
ProfileURL: "tribe-999",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Tag: "tag 999",
|
||||
NumMembers: 2,
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
AllPoints: 5,
|
||||
Rank: 6,
|
||||
ProfileURL: "tribe-999",
|
||||
ServerKey: "pl151",
|
||||
}
|
||||
|
||||
result := model.NewTribe(params)
|
||||
result.DeletedAt = deletedAt
|
||||
tribe := result.ToDomain()
|
||||
assert.Equal(t, params.BaseTribe, tribe.BaseTribe)
|
||||
assert.EqualValues(t, params.OpponentsDefeated, result.OpponentsDefeated)
|
||||
assert.Equal(t, params.ID, result.ID)
|
||||
assert.Equal(t, params.Name, result.Name)
|
||||
assert.Equal(t, params.Tag, result.Tag)
|
||||
assert.Equal(t, params.NumMembers, result.NumMembers)
|
||||
assert.Equal(t, params.NumVillages, result.NumVillages)
|
||||
assert.Equal(t, params.Points, result.Points)
|
||||
assert.Equal(t, params.AllPoints, result.AllPoints)
|
||||
assert.Equal(t, params.Rank, result.Rank)
|
||||
assert.Equal(t, params.ProfileURL, result.ProfileURL)
|
||||
assert.Equal(t, params.ServerKey, result.ServerKey)
|
||||
assert.Equal(t, params.ServerKey, tribe.ServerKey)
|
||||
assert.WithinDuration(t, time.Now(), tribe.CreatedAt, 10*time.Millisecond)
|
||||
assert.Equal(t, deletedAt, tribe.DeletedAt)
|
||||
|
|
|
@ -49,19 +49,17 @@ func (v Village) ToDomain() domain.Village {
|
|||
}
|
||||
}
|
||||
return domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: v.ID,
|
||||
Name: v.Name,
|
||||
Points: v.Points,
|
||||
X: v.X,
|
||||
Y: v.Y,
|
||||
Continent: v.Continent,
|
||||
Bonus: v.Bonus,
|
||||
PlayerID: v.PlayerID,
|
||||
ProfileURL: v.ProfileURL,
|
||||
},
|
||||
ServerKey: v.ServerKey,
|
||||
Player: player,
|
||||
CreatedAt: v.CreatedAt,
|
||||
ID: v.ID,
|
||||
Name: v.Name,
|
||||
Points: v.Points,
|
||||
X: v.X,
|
||||
Y: v.Y,
|
||||
Continent: v.Continent,
|
||||
Bonus: v.Bonus,
|
||||
PlayerID: v.PlayerID,
|
||||
ProfileURL: v.ProfileURL,
|
||||
ServerKey: v.ServerKey,
|
||||
Player: player,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/bundb/internal/model"
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -13,24 +15,29 @@ func TestVillage(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
params := domain.CreateVillageParams{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Points: 4,
|
||||
X: 500,
|
||||
Y: 500,
|
||||
Continent: "K55",
|
||||
Bonus: 0,
|
||||
PlayerID: 1235,
|
||||
ProfileURL: "profile-999",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Points: 4,
|
||||
X: 500,
|
||||
Y: 500,
|
||||
Continent: "K55",
|
||||
Bonus: 0,
|
||||
PlayerID: 1235,
|
||||
ProfileURL: "profile-999",
|
||||
ServerKey: "pl151",
|
||||
}
|
||||
|
||||
result := model.NewVillage(params)
|
||||
|
||||
villageWithoutPlayer := result.ToDomain()
|
||||
assert.Equal(t, params.BaseVillage, villageWithoutPlayer.BaseVillage)
|
||||
assert.Equal(t, params.ID, villageWithoutPlayer.ID)
|
||||
assert.Equal(t, params.Name, villageWithoutPlayer.Name)
|
||||
assert.Equal(t, params.Points, villageWithoutPlayer.Points)
|
||||
assert.Equal(t, params.X, villageWithoutPlayer.X)
|
||||
assert.Equal(t, params.Continent, villageWithoutPlayer.Continent)
|
||||
assert.Equal(t, params.Bonus, villageWithoutPlayer.Bonus)
|
||||
assert.Equal(t, params.PlayerID, villageWithoutPlayer.PlayerID)
|
||||
assert.Equal(t, params.ProfileURL, villageWithoutPlayer.ProfileURL)
|
||||
assert.Equal(t, params.ServerKey, villageWithoutPlayer.ServerKey)
|
||||
assert.WithinDuration(t, time.Now(), villageWithoutPlayer.CreatedAt, 10*time.Millisecond)
|
||||
|
||||
|
@ -41,8 +48,11 @@ func TestVillage(t *testing.T) {
|
|||
},
|
||||
}
|
||||
villageWithPlayer := result.ToDomain()
|
||||
assert.Equal(t, params.BaseVillage, villageWithPlayer.BaseVillage)
|
||||
assert.Equal(t, params.ServerKey, villageWithPlayer.ServerKey)
|
||||
assert.Empty(t, cmp.Diff(
|
||||
villageWithoutPlayer,
|
||||
villageWithPlayer,
|
||||
cmpopts.IgnoreFields(domain.Village{}, "Player"),
|
||||
))
|
||||
assert.WithinDuration(t, time.Now(), villageWithPlayer.CreatedAt, 10*time.Millisecond)
|
||||
assert.True(t, villageWithPlayer.Player.Valid)
|
||||
assert.Equal(t, result.Player.ID, villageWithPlayer.Player.Player.ID)
|
||||
|
|
|
@ -33,47 +33,43 @@ func TestPlayer_CreateOrUpdate(t *testing.T) {
|
|||
tribeCSA := getTribeFromFixture(t, fixture, "pl169-csa")
|
||||
createParams := []domain.CreatePlayerParams{
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
Rank: 6,
|
||||
TribeID: tribeTT.ID,
|
||||
ProfileURL: "profile-999",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: serverKey,
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
Rank: 6,
|
||||
TribeID: tribeTT.ID,
|
||||
ProfileURL: "profile-999",
|
||||
ServerKey: serverKey,
|
||||
},
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-998",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: serverKey,
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: serverKey,
|
||||
},
|
||||
}
|
||||
updateParams := make([]domain.CreatePlayerParams, 0, len(createParams))
|
||||
|
@ -85,26 +81,24 @@ func TestPlayer_CreateOrUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
updateParams = append(updateParams, domain.CreatePlayerParams{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: p.RankAtt + 1,
|
||||
ScoreAtt: p.ScoreAtt + 1,
|
||||
RankDef: p.RankDef + 1,
|
||||
ScoreDef: p.ScoreDef + 1,
|
||||
RankSup: p.RankSup + 1,
|
||||
ScoreSup: p.ScoreSup + 1,
|
||||
RankTotal: p.RankTotal + 1,
|
||||
ScoreTotal: p.ScoreTotal + 1,
|
||||
},
|
||||
ID: p.ID,
|
||||
Name: p.Name + "Update",
|
||||
NumVillages: p.NumVillages + 1,
|
||||
Points: p.Points + 1,
|
||||
Rank: p.Rank + 1,
|
||||
TribeID: tribeID,
|
||||
ProfileURL: p.ProfileURL + "Update",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: p.RankAtt + 1,
|
||||
ScoreAtt: p.ScoreAtt + 1,
|
||||
RankDef: p.RankDef + 1,
|
||||
ScoreDef: p.ScoreDef + 1,
|
||||
RankSup: p.RankSup + 1,
|
||||
ScoreSup: p.ScoreSup + 1,
|
||||
RankTotal: p.RankTotal + 1,
|
||||
ScoreTotal: p.ScoreTotal + 1,
|
||||
},
|
||||
ServerKey: p.ServerKey,
|
||||
ID: p.ID,
|
||||
Name: p.Name + "Update",
|
||||
NumVillages: p.NumVillages + 1,
|
||||
Points: p.Points + 1,
|
||||
Rank: p.Rank + 1,
|
||||
TribeID: tribeID,
|
||||
ProfileURL: p.ProfileURL + "Update",
|
||||
ServerKey: p.ServerKey,
|
||||
})
|
||||
ids = append(ids, p.ID)
|
||||
}
|
||||
|
@ -135,24 +129,22 @@ func TestPlayer_CreateOrUpdate(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
err := repo.CreateOrUpdate(context.Background(), domain.CreatePlayerParams{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
Rank: 6,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: "pl999",
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
Rank: 6,
|
||||
ServerKey: "pl999",
|
||||
})
|
||||
var pgErr pgdriver.Error
|
||||
assert.ErrorAs(t, err, &pgErr)
|
||||
|
@ -645,7 +637,14 @@ func assertCreatedPlayers(tb testing.TB, params []domain.CreatePlayerParams, pla
|
|||
break
|
||||
}
|
||||
}
|
||||
assert.Equal(tb, p.BasePlayer, player.BasePlayer)
|
||||
assert.EqualValues(tb, p.OpponentsDefeated, player.OpponentsDefeated)
|
||||
assert.Equal(tb, p.ID, player.ID)
|
||||
assert.Equal(tb, p.Name, player.Name)
|
||||
assert.Equal(tb, p.NumVillages, player.NumVillages)
|
||||
assert.Equal(tb, p.Points, player.Points)
|
||||
assert.Equal(tb, p.Rank, player.Rank)
|
||||
assert.Equal(tb, p.TribeID, player.TribeID)
|
||||
assert.Equal(tb, p.ProfileURL, player.ProfileURL)
|
||||
assert.Equal(tb, p.ServerKey, player.ServerKey)
|
||||
assert.Zero(tb, player.DeletedAt)
|
||||
assert.WithinDuration(tb, player.CreatedAt, time.Now(), 1*time.Second)
|
||||
|
|
|
@ -33,80 +33,74 @@ func TestTribe_CreateOrUpdate(t *testing.T) {
|
|||
serverKey := "pl169"
|
||||
createParams := []domain.CreateTribeParams{
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Tag: "tag 999",
|
||||
NumMembers: 2,
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
AllPoints: 5,
|
||||
Rank: 6,
|
||||
ProfileURL: "profile-999",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: serverKey,
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Tag: "tag 999",
|
||||
NumMembers: 2,
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
AllPoints: 5,
|
||||
Rank: 6,
|
||||
ProfileURL: "profile-999",
|
||||
ServerKey: serverKey,
|
||||
},
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
Tag: "tag 998",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-998",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: serverKey,
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
Tag: "tag 998",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: serverKey,
|
||||
},
|
||||
}
|
||||
updateParams := make([]domain.CreateTribeParams, 0, len(createParams))
|
||||
ids := make([]int64, 0, len(createParams))
|
||||
for _, p := range createParams {
|
||||
updateParams = append(updateParams, domain.CreateTribeParams{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: p.RankAtt + 1,
|
||||
ScoreAtt: p.ScoreAtt + 1,
|
||||
RankDef: p.RankDef + 1,
|
||||
ScoreDef: p.ScoreDef + 1,
|
||||
RankSup: p.RankSup + 1,
|
||||
ScoreSup: p.ScoreSup + 1,
|
||||
RankTotal: p.RankTotal + 1,
|
||||
ScoreTotal: p.ScoreTotal + 1,
|
||||
},
|
||||
ID: p.ID,
|
||||
Name: p.Name + "Update",
|
||||
Tag: p.Tag + "U",
|
||||
NumMembers: p.NumMembers + 1,
|
||||
NumVillages: p.NumVillages + 1,
|
||||
Points: p.Points + 1,
|
||||
AllPoints: p.AllPoints + 1,
|
||||
Rank: p.Rank + 1,
|
||||
ProfileURL: p.ProfileURL + "Update",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: p.RankAtt + 1,
|
||||
ScoreAtt: p.ScoreAtt + 1,
|
||||
RankDef: p.RankDef + 1,
|
||||
ScoreDef: p.ScoreDef + 1,
|
||||
RankSup: p.RankSup + 1,
|
||||
ScoreSup: p.ScoreSup + 1,
|
||||
RankTotal: p.RankTotal + 1,
|
||||
ScoreTotal: p.ScoreTotal + 1,
|
||||
},
|
||||
ServerKey: p.ServerKey,
|
||||
ID: p.ID,
|
||||
Name: p.Name + "Update",
|
||||
Tag: p.Tag + "U",
|
||||
NumMembers: p.NumMembers + 1,
|
||||
NumVillages: p.NumVillages + 1,
|
||||
Points: p.Points + 1,
|
||||
AllPoints: p.AllPoints + 1,
|
||||
Rank: p.Rank + 1,
|
||||
ProfileURL: p.ProfileURL + "Update",
|
||||
ServerKey: p.ServerKey,
|
||||
})
|
||||
ids = append(ids, p.ID)
|
||||
}
|
||||
|
@ -137,27 +131,25 @@ func TestTribe_CreateOrUpdate(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
err := repo.CreateOrUpdate(context.Background(), domain.CreateTribeParams{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Tag: "tag 999",
|
||||
NumMembers: 2,
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
AllPoints: 5,
|
||||
Rank: 6,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: "pl999",
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Tag: "tag 999",
|
||||
NumMembers: 2,
|
||||
NumVillages: 3,
|
||||
Points: 4,
|
||||
AllPoints: 5,
|
||||
Rank: 6,
|
||||
ServerKey: "pl999",
|
||||
})
|
||||
var pgErr pgdriver.Error
|
||||
assert.ErrorAs(t, err, &pgErr)
|
||||
|
@ -651,7 +643,16 @@ func assertCreatedTribes(tb testing.TB, params []domain.CreateTribeParams, tribe
|
|||
break
|
||||
}
|
||||
}
|
||||
assert.Equal(tb, p.BaseTribe, tribe.BaseTribe)
|
||||
assert.EqualValues(tb, p.OpponentsDefeated, tribe.OpponentsDefeated)
|
||||
assert.Equal(tb, p.ID, tribe.ID)
|
||||
assert.Equal(tb, p.Name, tribe.Name)
|
||||
assert.Equal(tb, p.Tag, tribe.Tag)
|
||||
assert.Equal(tb, p.NumMembers, tribe.NumMembers)
|
||||
assert.Equal(tb, p.NumVillages, tribe.NumVillages)
|
||||
assert.Equal(tb, p.Points, tribe.Points)
|
||||
assert.Equal(tb, p.AllPoints, tribe.AllPoints)
|
||||
assert.Equal(tb, p.Rank, tribe.Rank)
|
||||
assert.Equal(tb, p.ProfileURL, tribe.ProfileURL)
|
||||
assert.Equal(tb, p.ServerKey, tribe.ServerKey)
|
||||
assert.Equal(tb, 0.0, tribe.Dominance)
|
||||
assert.Zero(tb, tribe.DeletedAt)
|
||||
|
|
|
@ -31,32 +31,28 @@ func TestVillage_CreateOrUpdate(t *testing.T) {
|
|||
playerRIP := getPlayerFromFixture(t, fixture, "de188-rest-in-peace")
|
||||
createParams := []domain.CreateVillageParams{
|
||||
{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Points: 4,
|
||||
X: 500,
|
||||
Y: 500,
|
||||
Continent: "K55",
|
||||
Bonus: 0,
|
||||
PlayerID: playerGSus.ID,
|
||||
ProfileURL: "profile-999",
|
||||
},
|
||||
ServerKey: serverKey,
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Points: 4,
|
||||
X: 500,
|
||||
Y: 500,
|
||||
Continent: "K55",
|
||||
Bonus: 0,
|
||||
PlayerID: playerGSus.ID,
|
||||
ProfileURL: "profile-999",
|
||||
ServerKey: serverKey,
|
||||
},
|
||||
{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1000,
|
||||
Name: "name 1000",
|
||||
Points: 5,
|
||||
X: 501,
|
||||
Y: 500,
|
||||
Continent: "K55",
|
||||
Bonus: 2,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1000",
|
||||
},
|
||||
ServerKey: serverKey,
|
||||
ID: 1000,
|
||||
Name: "name 1000",
|
||||
Points: 5,
|
||||
X: 501,
|
||||
Y: 500,
|
||||
Continent: "K55",
|
||||
Bonus: 2,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1000",
|
||||
ServerKey: serverKey,
|
||||
},
|
||||
}
|
||||
updateParams := make([]domain.CreateVillageParams, 0, len(createParams))
|
||||
|
@ -68,18 +64,16 @@ func TestVillage_CreateOrUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
updateParams = append(updateParams, domain.CreateVillageParams{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: p.ID,
|
||||
Name: p.Name + "Update",
|
||||
Points: p.Points + 1,
|
||||
X: p.X + 1,
|
||||
Y: p.Y + 1,
|
||||
Continent: p.Continent + "1",
|
||||
Bonus: p.Bonus + 1,
|
||||
PlayerID: playerID,
|
||||
ProfileURL: p.ProfileURL + "Update",
|
||||
},
|
||||
ServerKey: p.ServerKey,
|
||||
ID: p.ID,
|
||||
Name: p.Name + "Update",
|
||||
Points: p.Points + 1,
|
||||
X: p.X + 1,
|
||||
Y: p.Y + 1,
|
||||
Continent: p.Continent + "1",
|
||||
Bonus: p.Bonus + 1,
|
||||
PlayerID: playerID,
|
||||
ProfileURL: p.ProfileURL + "Update",
|
||||
ServerKey: p.ServerKey,
|
||||
})
|
||||
ids = append(ids, p.ID)
|
||||
}
|
||||
|
@ -110,16 +104,14 @@ func TestVillage_CreateOrUpdate(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
err := repo.CreateOrUpdate(context.Background(), domain.CreateVillageParams{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Points: 4,
|
||||
X: 500,
|
||||
Y: 500,
|
||||
Continent: "K55",
|
||||
Bonus: 0,
|
||||
PlayerID: 0,
|
||||
},
|
||||
ID: 999,
|
||||
Name: "name 999",
|
||||
Points: 4,
|
||||
X: 500,
|
||||
Y: 500,
|
||||
Continent: "K55",
|
||||
Bonus: 0,
|
||||
PlayerID: 0,
|
||||
ServerKey: "pl999",
|
||||
})
|
||||
var pgErr pgdriver.Error
|
||||
|
@ -410,7 +402,15 @@ func assertCreatedVillages(tb testing.TB, params []domain.CreateVillageParams, v
|
|||
break
|
||||
}
|
||||
}
|
||||
assert.Equal(tb, p.BaseVillage, village.BaseVillage)
|
||||
assert.Equal(tb, p.ID, village.ID)
|
||||
assert.Equal(tb, p.Name, village.Name)
|
||||
assert.Equal(tb, p.Points, village.Points)
|
||||
assert.Equal(tb, p.X, village.X)
|
||||
assert.Equal(tb, p.Y, village.Y)
|
||||
assert.Equal(tb, p.Continent, village.Continent)
|
||||
assert.Equal(tb, p.Bonus, village.Bonus)
|
||||
assert.Equal(tb, p.PlayerID, village.PlayerID)
|
||||
assert.Equal(tb, p.ProfileURL, village.ProfileURL)
|
||||
assert.Equal(tb, p.ServerKey, village.ServerKey)
|
||||
assert.WithinDuration(tb, village.CreatedAt, time.Now(), 1*time.Second)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type BaseEnnoblement struct {
|
||||
type Ennoblement struct {
|
||||
ID int64
|
||||
VillageID int64
|
||||
NewOwnerID int64
|
||||
NewTribeID int64
|
||||
|
@ -13,24 +14,23 @@ type BaseEnnoblement struct {
|
|||
OldTribeID int64
|
||||
Points int64
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type Ennoblement struct {
|
||||
BaseEnnoblement
|
||||
|
||||
ID int64
|
||||
Village NullVillage
|
||||
NewOwner NullPlayer
|
||||
NewTribe NullTribe
|
||||
OldOwner NullPlayer
|
||||
OldTribe NullTribe
|
||||
ServerKey string
|
||||
Village NullVillage
|
||||
NewOwner NullPlayer
|
||||
NewTribe NullTribe
|
||||
OldOwner NullPlayer
|
||||
OldTribe NullTribe
|
||||
ServerKey string
|
||||
}
|
||||
|
||||
type CreateEnnoblementParams struct {
|
||||
BaseEnnoblement
|
||||
|
||||
ServerKey string
|
||||
VillageID int64
|
||||
NewOwnerID int64
|
||||
NewTribeID int64
|
||||
OldOwnerID int64
|
||||
OldTribeID int64
|
||||
Points int64
|
||||
CreatedAt time.Time
|
||||
ServerKey string
|
||||
}
|
||||
|
||||
type EnnoblementSortBy uint8
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type BasePlayer struct {
|
||||
type Player struct {
|
||||
OpponentsDefeated
|
||||
|
||||
ID int64
|
||||
|
@ -15,15 +15,10 @@ type BasePlayer struct {
|
|||
Rank int64
|
||||
TribeID int64
|
||||
ProfileURL string
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
BasePlayer
|
||||
|
||||
ServerKey string
|
||||
Tribe NullTribe // only available when ListPlayersParams.IncludeTribe == true
|
||||
CreatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
ServerKey string
|
||||
Tribe NullTribe // only available when ListPlayersParams.IncludeTribe == true
|
||||
CreatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
}
|
||||
|
||||
type NullPlayer struct {
|
||||
|
@ -32,9 +27,16 @@ type NullPlayer struct {
|
|||
}
|
||||
|
||||
type CreatePlayerParams struct {
|
||||
BasePlayer
|
||||
OpponentsDefeated
|
||||
|
||||
ServerKey string
|
||||
ID int64
|
||||
Name string
|
||||
NumVillages int64
|
||||
Points int64
|
||||
Rank int64
|
||||
TribeID int64
|
||||
ProfileURL string
|
||||
ServerKey string
|
||||
}
|
||||
|
||||
type PlayerSortBy uint8
|
||||
|
|
|
@ -5,11 +5,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type OpenServer struct {
|
||||
Key string
|
||||
URL string
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Key string
|
||||
URL string
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type BaseTribe struct {
|
||||
type Tribe struct {
|
||||
OpponentsDefeated
|
||||
|
||||
ID int64
|
||||
|
@ -18,15 +18,10 @@ type BaseTribe struct {
|
|||
AllPoints int64
|
||||
Rank int64
|
||||
ProfileURL string
|
||||
}
|
||||
|
||||
type Tribe struct {
|
||||
BaseTribe
|
||||
|
||||
ServerKey string
|
||||
Dominance float64
|
||||
CreatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
ServerKey string
|
||||
Dominance float64
|
||||
CreatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
}
|
||||
|
||||
type NullTribe struct {
|
||||
|
@ -35,9 +30,18 @@ type NullTribe struct {
|
|||
}
|
||||
|
||||
type CreateTribeParams struct {
|
||||
BaseTribe
|
||||
OpponentsDefeated
|
||||
|
||||
ServerKey string
|
||||
ID int64
|
||||
Name string
|
||||
Tag string
|
||||
NumMembers int64
|
||||
NumVillages int64
|
||||
Points int64
|
||||
AllPoints int64
|
||||
Rank int64
|
||||
ProfileURL string
|
||||
ServerKey string
|
||||
}
|
||||
|
||||
type TribeSortBy uint8
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type BaseVillage struct {
|
||||
type Village struct {
|
||||
ID int64
|
||||
Name string
|
||||
Points int64
|
||||
|
@ -15,14 +15,9 @@ type BaseVillage struct {
|
|||
Bonus int64
|
||||
PlayerID int64
|
||||
ProfileURL string
|
||||
}
|
||||
|
||||
type Village struct {
|
||||
BaseVillage
|
||||
|
||||
ServerKey string
|
||||
Player NullPlayer // only available when ListVillagesParams.IncludePlayer == true
|
||||
CreatedAt time.Time
|
||||
ServerKey string
|
||||
Player NullPlayer // only available when ListVillagesParams.IncludePlayer == true
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (v Village) FullName() string {
|
||||
|
@ -35,9 +30,16 @@ type NullVillage struct {
|
|||
}
|
||||
|
||||
type CreateVillageParams struct {
|
||||
BaseVillage
|
||||
|
||||
ServerKey string
|
||||
ID int64
|
||||
Name string
|
||||
Points int64
|
||||
X int64
|
||||
Y int64
|
||||
Continent string
|
||||
Bonus int64
|
||||
PlayerID int64
|
||||
ProfileURL string
|
||||
ServerKey string
|
||||
}
|
||||
|
||||
type ListVillagesParams struct {
|
||||
|
|
|
@ -11,13 +11,11 @@ func TestVillage_FullName(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
v := domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1234,
|
||||
Name: "Village",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
Continent: "K44",
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "Village",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
Continent: "K44",
|
||||
}
|
||||
assert.Equal(t, "Village (450|450) K44", v.FullName())
|
||||
}
|
||||
|
|
|
@ -74,116 +74,96 @@ func TestEnnoblement_list(t *testing.T) {
|
|||
|
||||
ennoblements := []domain.Ennoblement{
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: 123,
|
||||
NewOwnerID: 124,
|
||||
NewTribeID: 125,
|
||||
OldOwnerID: 126,
|
||||
OldTribeID: 127,
|
||||
Points: 128,
|
||||
CreatedAt: now,
|
||||
},
|
||||
ID: 1234,
|
||||
VillageID: 123,
|
||||
NewOwnerID: 124,
|
||||
NewTribeID: 125,
|
||||
OldOwnerID: 126,
|
||||
OldTribeID: 127,
|
||||
Points: 128,
|
||||
CreatedAt: now,
|
||||
ID: 1234,
|
||||
Village: domain.NullVillage{
|
||||
Valid: true,
|
||||
Village: domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 123,
|
||||
Name: "village name",
|
||||
Continent: "K44",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
ProfileURL: "profile-123",
|
||||
},
|
||||
ID: 123,
|
||||
Name: "village name",
|
||||
Continent: "K44",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
ProfileURL: "profile-123",
|
||||
},
|
||||
},
|
||||
NewOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 124,
|
||||
Name: "new owner name",
|
||||
ProfileURL: "profile-124",
|
||||
},
|
||||
ID: 124,
|
||||
Name: "new owner name",
|
||||
ProfileURL: "profile-124",
|
||||
},
|
||||
},
|
||||
NewTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 125,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
ProfileURL: "profile-125",
|
||||
},
|
||||
ID: 125,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
ProfileURL: "profile-125",
|
||||
},
|
||||
},
|
||||
OldOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 126,
|
||||
Name: "old owner name",
|
||||
ProfileURL: "profile-126",
|
||||
},
|
||||
ID: 126,
|
||||
Name: "old owner name",
|
||||
ProfileURL: "profile-126",
|
||||
},
|
||||
},
|
||||
OldTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 127,
|
||||
Name: "old tribe name",
|
||||
Tag: "old tribe tag",
|
||||
ProfileURL: "profile-127",
|
||||
},
|
||||
ID: 127,
|
||||
Name: "old tribe name",
|
||||
Tag: "old tribe tag",
|
||||
ProfileURL: "profile-127",
|
||||
},
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
},
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: 311,
|
||||
NewOwnerID: 312,
|
||||
NewTribeID: 313,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: 129,
|
||||
CreatedAt: now,
|
||||
},
|
||||
ID: 12345,
|
||||
VillageID: 311,
|
||||
NewOwnerID: 312,
|
||||
NewTribeID: 313,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: 129,
|
||||
CreatedAt: now,
|
||||
ID: 12345,
|
||||
Village: domain.NullVillage{
|
||||
Valid: true,
|
||||
Village: domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 311,
|
||||
Name: "village name",
|
||||
Continent: "K55",
|
||||
X: 550,
|
||||
Y: 550,
|
||||
ProfileURL: "profile-311",
|
||||
},
|
||||
ID: 311,
|
||||
Name: "village name",
|
||||
Continent: "K55",
|
||||
X: 550,
|
||||
Y: 550,
|
||||
ProfileURL: "profile-311",
|
||||
},
|
||||
},
|
||||
NewOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 312,
|
||||
Name: "new owner name",
|
||||
ProfileURL: "profile-312",
|
||||
},
|
||||
ID: 312,
|
||||
Name: "new owner name",
|
||||
ProfileURL: "profile-312",
|
||||
},
|
||||
},
|
||||
NewTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 313,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
ProfileURL: "profile-313",
|
||||
},
|
||||
ID: 313,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
ProfileURL: "profile-313",
|
||||
},
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
|
@ -310,48 +290,40 @@ func TestEnnoblement_list(t *testing.T) {
|
|||
|
||||
ennoblements := []domain.Ennoblement{
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: 311,
|
||||
NewOwnerID: 312,
|
||||
NewTribeID: 313,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: 129,
|
||||
CreatedAt: now,
|
||||
},
|
||||
ID: 12345,
|
||||
VillageID: 311,
|
||||
NewOwnerID: 312,
|
||||
NewTribeID: 313,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: 129,
|
||||
CreatedAt: now,
|
||||
ID: 12345,
|
||||
Village: domain.NullVillage{
|
||||
Valid: true,
|
||||
Village: domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 311,
|
||||
Name: "village name",
|
||||
Continent: "K44",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
ProfileURL: "profile-311",
|
||||
},
|
||||
ID: 311,
|
||||
Name: "village name",
|
||||
Continent: "K44",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
ProfileURL: "profile-311",
|
||||
},
|
||||
},
|
||||
NewOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 312,
|
||||
Name: "new owner name",
|
||||
ProfileURL: "profile-312",
|
||||
},
|
||||
ID: 312,
|
||||
Name: "new owner name",
|
||||
ProfileURL: "profile-312",
|
||||
},
|
||||
},
|
||||
NewTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 313,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
ProfileURL: "profile-313",
|
||||
},
|
||||
ID: 313,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
ProfileURL: "profile-313",
|
||||
},
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
|
|
|
@ -14,64 +14,52 @@ func TestNewEnnoblement(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
ennoblement := domain.Ennoblement{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: 123,
|
||||
NewOwnerID: 124,
|
||||
NewTribeID: 125,
|
||||
OldOwnerID: 126,
|
||||
OldTribeID: 127,
|
||||
Points: 128,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
ID: 1234,
|
||||
ID: 1234,
|
||||
VillageID: 123,
|
||||
NewOwnerID: 124,
|
||||
NewTribeID: 125,
|
||||
OldOwnerID: 126,
|
||||
OldTribeID: 127,
|
||||
Points: 128,
|
||||
CreatedAt: time.Now(),
|
||||
Village: domain.NullVillage{
|
||||
Valid: true,
|
||||
Village: domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 123,
|
||||
Name: "village name",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
Continent: "K44",
|
||||
},
|
||||
ID: 123,
|
||||
Name: "village name",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
Continent: "K44",
|
||||
},
|
||||
},
|
||||
NewOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 124,
|
||||
Name: "new owner name",
|
||||
},
|
||||
ID: 124,
|
||||
Name: "new owner name",
|
||||
},
|
||||
},
|
||||
NewTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 125,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
},
|
||||
ID: 125,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
},
|
||||
},
|
||||
OldOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 126,
|
||||
Name: "old owner name",
|
||||
},
|
||||
ID: 126,
|
||||
Name: "old owner name",
|
||||
},
|
||||
},
|
||||
OldTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 125,
|
||||
Name: "old tribe name",
|
||||
Tag: "old tribe tag",
|
||||
},
|
||||
ID: 125,
|
||||
Name: "old tribe name",
|
||||
Tag: "old tribe tag",
|
||||
},
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
|
@ -84,109 +72,89 @@ func TestNewListEnnoblementsResp(t *testing.T) {
|
|||
|
||||
ennoblements := []domain.Ennoblement{
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: 123,
|
||||
NewOwnerID: 124,
|
||||
NewTribeID: 125,
|
||||
OldOwnerID: 126,
|
||||
OldTribeID: 127,
|
||||
Points: 128,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
ID: 1234,
|
||||
ID: 1234,
|
||||
VillageID: 123,
|
||||
NewOwnerID: 124,
|
||||
NewTribeID: 125,
|
||||
OldOwnerID: 126,
|
||||
OldTribeID: 127,
|
||||
Points: 128,
|
||||
CreatedAt: time.Now(),
|
||||
Village: domain.NullVillage{
|
||||
Valid: true,
|
||||
Village: domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 123,
|
||||
Name: "village name",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
Continent: "K44",
|
||||
},
|
||||
ID: 123,
|
||||
Name: "village name",
|
||||
X: 450,
|
||||
Y: 450,
|
||||
Continent: "K44",
|
||||
},
|
||||
},
|
||||
NewOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 124,
|
||||
Name: "new owner name",
|
||||
},
|
||||
ID: 124,
|
||||
Name: "new owner name",
|
||||
},
|
||||
},
|
||||
NewTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 125,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
},
|
||||
ID: 125,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
},
|
||||
},
|
||||
OldOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 126,
|
||||
Name: "old owner name",
|
||||
},
|
||||
ID: 126,
|
||||
Name: "old owner name",
|
||||
},
|
||||
},
|
||||
OldTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 125,
|
||||
Name: "old tribe name",
|
||||
Tag: "old tribe tag",
|
||||
},
|
||||
ID: 125,
|
||||
Name: "old tribe name",
|
||||
Tag: "old tribe tag",
|
||||
},
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
},
|
||||
{
|
||||
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: 311,
|
||||
NewOwnerID: 312,
|
||||
NewTribeID: 313,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: 129,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
ID: 1234,
|
||||
ID: 1234,
|
||||
VillageID: 311,
|
||||
NewOwnerID: 312,
|
||||
NewTribeID: 313,
|
||||
OldOwnerID: 0,
|
||||
OldTribeID: 0,
|
||||
Points: 129,
|
||||
CreatedAt: time.Now(),
|
||||
Village: domain.NullVillage{
|
||||
Valid: true,
|
||||
Village: domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 311,
|
||||
Name: "village name",
|
||||
X: 449,
|
||||
Y: 450,
|
||||
Continent: "K44",
|
||||
},
|
||||
ID: 311,
|
||||
Name: "village name",
|
||||
X: 449,
|
||||
Y: 450,
|
||||
Continent: "K44",
|
||||
},
|
||||
},
|
||||
NewOwner: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 312,
|
||||
Name: "new owner name",
|
||||
},
|
||||
ID: 312,
|
||||
Name: "new owner name",
|
||||
},
|
||||
},
|
||||
NewTribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 313,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
},
|
||||
ID: 313,
|
||||
Name: "new tribe name",
|
||||
Tag: "new tribe tag",
|
||||
},
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
|
|
|
@ -13,77 +13,71 @@ import (
|
|||
|
||||
func TestNewPlayer(t *testing.T) {
|
||||
playerWithoutTribe := domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
CreatedAt: time.Now(),
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
assertPlayer(t, playerWithoutTribe, model.NewPlayer(playerWithoutTribe))
|
||||
|
||||
playerWithTribe := domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
|
@ -93,76 +87,70 @@ func TestNewPlayer(t *testing.T) {
|
|||
|
||||
func TestNewPlayerMeta(t *testing.T) {
|
||||
playerWithoutTribe := domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
CreatedAt: time.Now(),
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
assertPlayerMeta(t, playerWithoutTribe, model.NewPlayerMeta(playerWithoutTribe))
|
||||
|
||||
playerWithTribe := domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ServerKey: "pl151",
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
|
@ -309,78 +297,72 @@ func TestNewListPlayersResp(t *testing.T) {
|
|||
|
||||
players := []domain.Player{
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
Rank: 4,
|
||||
TribeID: 0,
|
||||
ProfileURL: "profile-998",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
Rank: 4,
|
||||
TribeID: 0,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: "pl151",
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: false,
|
||||
},
|
||||
|
@ -398,26 +380,24 @@ func TestNewGetPlayerResp(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
player := domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
CreatedAt: time.Now(),
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
assertPlayer(t, player, model.NewGetPlayerResp(player).Data)
|
||||
}
|
||||
|
|
|
@ -15,30 +15,28 @@ func TestNewTribe(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
tribe := domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
assertTribe(t, tribe, model.NewTribe(tribe))
|
||||
}
|
||||
|
@ -47,30 +45,28 @@ func TestNewTribeMeta(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
tribe := domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
assertTribeMeta(t, tribe, model.NewTribeMeta(tribe))
|
||||
}
|
||||
|
@ -196,71 +192,6 @@ func TestNewListTribesResp(t *testing.T) {
|
|||
|
||||
tribes := []domain.Tribe{
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 9,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
Tag: "tag 998",
|
||||
NumMembers: 1,
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
AllPoints: 4,
|
||||
Rank: 5,
|
||||
ProfileURL: "profile-998",
|
||||
},
|
||||
ServerKey: "pl163",
|
||||
Dominance: 12.55,
|
||||
CreatedAt: time.Now().Add(-5000 * time.Hour),
|
||||
DeletedAt: time.Now(),
|
||||
},
|
||||
}
|
||||
resp := model.NewListTribesResp(tribes)
|
||||
assert.Len(t, resp.Data, len(tribes))
|
||||
for i, tribe := range resp.Data {
|
||||
assertTribe(t, tribes[i], tribe)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewGetTribeResp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tribe := domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
|
@ -280,10 +211,69 @@ func TestNewGetTribeResp(t *testing.T) {
|
|||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 9,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
Tag: "tag 998",
|
||||
NumMembers: 1,
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
AllPoints: 4,
|
||||
Rank: 5,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: "pl163",
|
||||
Dominance: 12.55,
|
||||
CreatedAt: time.Now().Add(-5000 * time.Hour),
|
||||
DeletedAt: time.Now(),
|
||||
},
|
||||
}
|
||||
resp := model.NewListTribesResp(tribes)
|
||||
assert.Len(t, resp.Data, len(tribes))
|
||||
for i, tribe := range resp.Data {
|
||||
assertTribe(t, tribes[i], tribe)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewGetTribeResp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tribe := domain.Tribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
assertTribe(t, tribe, model.NewGetTribeResp(tribe).Data)
|
||||
}
|
||||
|
|
|
@ -13,25 +13,113 @@ func TestNewVillage(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
barbarianVillage := domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: time.Time{},
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: time.Time{},
|
||||
}
|
||||
assertVillage(t, barbarianVillage, model.NewVillage(barbarianVillage))
|
||||
|
||||
playerVillage := domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 997,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: "pl151",
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
assertVillage(t, playerVillage, model.NewVillage(playerVillage))
|
||||
}
|
||||
|
||||
func TestNewVillageMeta(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
village := domain.Village{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: time.Time{},
|
||||
}
|
||||
assertVillageMeta(t, village, model.NewVillageMeta(village))
|
||||
}
|
||||
|
||||
func TestNewListVillagesResp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
villages := []domain.Village{
|
||||
{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
|
@ -41,12 +129,10 @@ func TestNewVillage(t *testing.T) {
|
|||
Bonus: 1,
|
||||
PlayerID: 997,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
|
@ -64,12 +150,10 @@ func TestNewVillage(t *testing.T) {
|
|||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ServerKey: "pl151",
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
|
@ -89,25 +173,17 @@ func TestNewVillage(t *testing.T) {
|
|||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
assertVillage(t, playerVillage, model.NewVillage(playerVillage))
|
||||
}
|
||||
|
||||
func TestNewVillageMeta(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
village := domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
|
@ -117,103 +193,9 @@ func TestNewVillageMeta(t *testing.T) {
|
|||
Bonus: 1,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: time.Time{},
|
||||
}
|
||||
assertVillageMeta(t, village, model.NewVillageMeta(village))
|
||||
}
|
||||
|
||||
func TestNewListVillagesResp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
villages := []domain.Village{
|
||||
{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 997,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: time.Time{},
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: time.Time{},
|
||||
},
|
||||
}
|
||||
resp := model.NewListVillagesResp(villages)
|
||||
|
@ -227,20 +209,18 @@ func TestNewGetVillageResp(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
village := domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: time.Time{},
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: "pl151",
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: time.Time{},
|
||||
}
|
||||
assertVillage(t, village, model.NewGetVillageResp(village).Data)
|
||||
}
|
||||
|
|
|
@ -67,78 +67,72 @@ func TestPlayer_list(t *testing.T) {
|
|||
|
||||
players := []domain.Player{
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: server.Key,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
},
|
||||
},
|
||||
CreatedAt: now,
|
||||
},
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
Rank: 4,
|
||||
TribeID: 0,
|
||||
ProfileURL: "profile-998",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
Rank: 4,
|
||||
TribeID: 0,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: server.Key,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: false,
|
||||
},
|
||||
|
@ -233,26 +227,24 @@ func TestPlayer_list(t *testing.T) {
|
|||
|
||||
players := []domain.Player{
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
Rank: 4,
|
||||
TribeID: 0,
|
||||
ProfileURL: "profile-998",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
Rank: 4,
|
||||
TribeID: 0,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: server.Key,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: false,
|
||||
},
|
||||
|
@ -334,26 +326,24 @@ func TestPlayer_list(t *testing.T) {
|
|||
|
||||
players := []domain.Player{
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
Rank: 4,
|
||||
TribeID: 0,
|
||||
ProfileURL: "profile-998",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 8,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
Rank: 4,
|
||||
TribeID: 0,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: server.Key,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: false,
|
||||
},
|
||||
|
@ -629,53 +619,49 @@ func TestPlayer_getByID(t *testing.T) {
|
|||
versionSvc.GetByCodeReturns(version, nil)
|
||||
serverSvc.GetNormalByVersionCodeAndKeyReturns(server, nil)
|
||||
playerSvc.GetByServerKeyAndIDReturns(domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: server.Key,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
},
|
||||
},
|
||||
CreatedAt: now,
|
||||
|
|
|
@ -82,57 +82,53 @@ func TestTribe_list(t *testing.T) {
|
|||
|
||||
tribes := []domain.Tribe{
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
},
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 9,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
Tag: "tag 998",
|
||||
NumMembers: 1,
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
AllPoints: 4,
|
||||
Rank: 5,
|
||||
ProfileURL: "profile-998",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 9,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.55,
|
||||
CreatedAt: now.Add(-5000 * time.Hour),
|
||||
DeletedAt: now,
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
Tag: "tag 998",
|
||||
NumMembers: 1,
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
AllPoints: 4,
|
||||
Rank: 5,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.55,
|
||||
CreatedAt: now.Add(-5000 * time.Hour),
|
||||
DeletedAt: now,
|
||||
},
|
||||
}
|
||||
return tribes, int64(len(tribes)), nil
|
||||
|
@ -229,57 +225,53 @@ func TestTribe_list(t *testing.T) {
|
|||
|
||||
tribes := []domain.Tribe{
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
},
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 9,
|
||||
},
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
Tag: "tag 998",
|
||||
NumMembers: 1,
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
AllPoints: 4,
|
||||
Rank: 5,
|
||||
ProfileURL: "profile-998",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
ScoreDef: 4,
|
||||
RankSup: 5,
|
||||
ScoreSup: 6,
|
||||
RankTotal: 7,
|
||||
ScoreTotal: 9,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.55,
|
||||
CreatedAt: now.Add(-5000 * time.Hour),
|
||||
DeletedAt: now,
|
||||
ID: 998,
|
||||
Name: "name 998",
|
||||
Tag: "tag 998",
|
||||
NumMembers: 1,
|
||||
NumVillages: 2,
|
||||
Points: 3,
|
||||
AllPoints: 4,
|
||||
Rank: 5,
|
||||
ProfileURL: "profile-998",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.55,
|
||||
CreatedAt: now.Add(-5000 * time.Hour),
|
||||
DeletedAt: now,
|
||||
},
|
||||
}
|
||||
return tribes, int64(len(tribes)), nil
|
||||
|
@ -365,30 +357,28 @@ func TestTribe_list(t *testing.T) {
|
|||
|
||||
tribes := []domain.Tribe{
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
},
|
||||
}
|
||||
return tribes, int64(len(tribes)) + 15, nil
|
||||
|
@ -655,29 +645,27 @@ func TestTribe_getByID(t *testing.T) {
|
|||
versionSvc.GetByCodeReturns(version, nil)
|
||||
serverSvc.GetNormalByVersionCodeAndKeyReturns(server, nil)
|
||||
tribeSvc.GetByServerKeyAndIDReturns(domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
}, nil)
|
||||
},
|
||||
versionCode: version.Code,
|
||||
|
@ -843,30 +831,28 @@ func TestTribe_getByTag(t *testing.T) {
|
|||
versionSvc.GetByCodeReturns(version, nil)
|
||||
serverSvc.GetNormalByVersionCodeAndKeyReturns(server, nil)
|
||||
tribeSvc.GetByServerKeyAndTagReturns(domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "*CSA*",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "*CSA*",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
}, nil)
|
||||
},
|
||||
versionCode: version.Code,
|
||||
|
|
|
@ -68,68 +68,62 @@ func TestVillage_list(t *testing.T) {
|
|||
|
||||
villages := []domain.Village{
|
||||
{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 997,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 997,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: server.Key,
|
||||
Player: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: server.Key,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
},
|
||||
},
|
||||
CreatedAt: now,
|
||||
|
@ -138,20 +132,18 @@ func TestVillage_list(t *testing.T) {
|
|||
CreatedAt: now,
|
||||
},
|
||||
{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 12345,
|
||||
Name: "name 2",
|
||||
Points: 1,
|
||||
X: 22,
|
||||
Y: 22,
|
||||
Continent: "K22",
|
||||
Bonus: 0,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-12345",
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: now,
|
||||
ID: 12345,
|
||||
Name: "name 2",
|
||||
Points: 1,
|
||||
X: 22,
|
||||
Y: 22,
|
||||
Continent: "K22",
|
||||
Bonus: 0,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-12345",
|
||||
ServerKey: server.Key,
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: now,
|
||||
},
|
||||
}
|
||||
return villages, int64(len(villages)), nil
|
||||
|
@ -235,20 +227,18 @@ func TestVillage_list(t *testing.T) {
|
|||
|
||||
villages := []domain.Village{
|
||||
{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 12345,
|
||||
Name: "name 2",
|
||||
Points: 1,
|
||||
X: 22,
|
||||
Y: 22,
|
||||
Continent: "K22",
|
||||
Bonus: 0,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-12345",
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: now,
|
||||
ID: 12345,
|
||||
Name: "name 2",
|
||||
Points: 1,
|
||||
X: 22,
|
||||
Y: 22,
|
||||
Continent: "K22",
|
||||
Bonus: 0,
|
||||
PlayerID: 0,
|
||||
ProfileURL: "profile-12345",
|
||||
ServerKey: server.Key,
|
||||
Player: domain.NullPlayer{},
|
||||
CreatedAt: now,
|
||||
},
|
||||
}
|
||||
return villages, int64(len(villages)) + 12354, nil
|
||||
|
@ -427,68 +417,62 @@ func TestVillage_getByID(t *testing.T) {
|
|||
versionSvc.GetByCodeReturns(version, nil)
|
||||
serverSvc.GetNormalByVersionCodeAndKeyReturns(server, nil)
|
||||
villageSvc.GetByServerKeyAndIDReturns(domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 997,
|
||||
ProfileURL: "profile-1234",
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 1234,
|
||||
Name: "name",
|
||||
Points: 1,
|
||||
X: 2,
|
||||
Y: 3,
|
||||
Continent: "K11",
|
||||
Bonus: 1,
|
||||
PlayerID: 997,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: server.Key,
|
||||
Player: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
TribeID: 1234,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: server.Key,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
ID: 1234,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-1234",
|
||||
ServerKey: server.Key,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: now,
|
||||
},
|
||||
},
|
||||
CreatedAt: now,
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
@ -31,7 +32,7 @@ type EnnoblementRepository interface {
|
|||
|
||||
//counterfeiter:generate -o internal/mock/ennoblement_getter.gen.go . EnnoblementGetter
|
||||
type EnnoblementGetter interface {
|
||||
GetEnnoblements(ctx context.Context, baseURL string, since time.Time) ([]domain.BaseEnnoblement, error)
|
||||
GetEnnoblements(ctx context.Context, baseURL string, since time.Time) ([]tw.Ennoblement, error)
|
||||
}
|
||||
|
||||
type Ennoblement struct {
|
||||
|
@ -82,11 +83,17 @@ func (e *Ennoblement) Refresh(ctx context.Context, key, url string) error {
|
|||
params := make([]domain.CreateEnnoblementParams, 0, len(chunk))
|
||||
for _, ennoblement := range chunk {
|
||||
params = append(params, domain.CreateEnnoblementParams{
|
||||
BaseEnnoblement: ennoblement,
|
||||
ServerKey: key,
|
||||
VillageID: ennoblement.VillageID,
|
||||
NewOwnerID: ennoblement.NewOwnerID,
|
||||
NewTribeID: ennoblement.NewTribeID,
|
||||
OldOwnerID: ennoblement.OldOwnerID,
|
||||
OldTribeID: ennoblement.OldTribeID,
|
||||
Points: ennoblement.Points,
|
||||
CreatedAt: ennoblement.CreatedAt,
|
||||
ServerKey: key,
|
||||
})
|
||||
}
|
||||
if err := e.repo.Create(ctx, params...); err != nil {
|
||||
if err = e.repo.Create(ctx, params...); err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
return fmt.Errorf("EnnoblementRepository.Create: %w", err)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -25,7 +26,7 @@ func TestEnnoblement_Refresh(t *testing.T) {
|
|||
key string
|
||||
url string
|
||||
ennoblementsRepo []domain.Ennoblement
|
||||
ennoblementsClient []domain.BaseEnnoblement
|
||||
ennoblementsClient []tw.Ennoblement
|
||||
}{
|
||||
{
|
||||
name: "OK: since=now-20h",
|
||||
|
@ -33,20 +34,18 @@ func TestEnnoblement_Refresh(t *testing.T) {
|
|||
url: "https://pl151.plemiona.pl",
|
||||
ennoblementsRepo: []domain.Ennoblement{
|
||||
{
|
||||
BaseEnnoblement: domain.BaseEnnoblement{
|
||||
VillageID: 112,
|
||||
NewOwnerID: 113,
|
||||
NewTribeID: 114,
|
||||
OldOwnerID: 115,
|
||||
OldTribeID: 116,
|
||||
Points: 117,
|
||||
CreatedAt: time.Now().Add(-20 * time.Hour),
|
||||
},
|
||||
ID: 111,
|
||||
ServerKey: "pl151",
|
||||
ID: 111,
|
||||
VillageID: 112,
|
||||
NewOwnerID: 113,
|
||||
NewTribeID: 114,
|
||||
OldOwnerID: 115,
|
||||
OldTribeID: 116,
|
||||
Points: 117,
|
||||
CreatedAt: time.Now().Add(-20 * time.Hour),
|
||||
ServerKey: "pl151",
|
||||
},
|
||||
},
|
||||
ennoblementsClient: []domain.BaseEnnoblement{
|
||||
ennoblementsClient: []tw.Ennoblement{
|
||||
{
|
||||
VillageID: 211,
|
||||
NewOwnerID: 212,
|
||||
|
@ -71,7 +70,7 @@ func TestEnnoblement_Refresh(t *testing.T) {
|
|||
name: "OK: since=1970",
|
||||
key: "pl151",
|
||||
url: "https://pl151.plemiona.pl",
|
||||
ennoblementsClient: []domain.BaseEnnoblement{
|
||||
ennoblementsClient: []tw.Ennoblement{
|
||||
{
|
||||
VillageID: 211,
|
||||
NewOwnerID: 212,
|
||||
|
@ -112,7 +111,13 @@ func TestEnnoblement_Refresh(t *testing.T) {
|
|||
_, params := repo.CreateArgsForCall(0)
|
||||
assert.Len(t, params, len(tt.ennoblementsClient))
|
||||
for i, ennoblement := range tt.ennoblementsClient {
|
||||
assert.Equal(t, ennoblement, params[i].BaseEnnoblement)
|
||||
assert.Equal(t, ennoblement.Points, params[i].Points)
|
||||
assert.Equal(t, ennoblement.VillageID, params[i].VillageID)
|
||||
assert.Equal(t, ennoblement.NewOwnerID, params[i].NewOwnerID)
|
||||
assert.Equal(t, ennoblement.NewTribeID, params[i].NewTribeID)
|
||||
assert.Equal(t, ennoblement.OldOwnerID, params[i].OldOwnerID)
|
||||
assert.Equal(t, ennoblement.OldTribeID, params[i].OldTribeID)
|
||||
assert.Equal(t, ennoblement.CreatedAt, params[i].CreatedAt)
|
||||
assert.Equal(t, tt.key, params[i].ServerKey)
|
||||
}
|
||||
require.Equal(t, 1, client.GetEnnoblementsCallCount())
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"sort"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
@ -26,7 +27,7 @@ type PlayerRepository interface {
|
|||
|
||||
//counterfeiter:generate -o internal/mock/player_getter.gen.go . PlayerGetter
|
||||
type PlayerGetter interface {
|
||||
GetPlayers(ctx context.Context, baseURL string) ([]domain.BasePlayer, error)
|
||||
GetPlayers(ctx context.Context, baseURL string) ([]tw.Player, error)
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
|
@ -67,7 +68,7 @@ func (p *Player) Refresh(ctx context.Context, key, url string) (int64, error) {
|
|||
return int64(len(players)), nil
|
||||
}
|
||||
|
||||
func (p *Player) createOrUpdate(ctx context.Context, key string, players []domain.BasePlayer) error {
|
||||
func (p *Player) createOrUpdate(ctx context.Context, key string, players []tw.Player) error {
|
||||
ctx, span := tracer.Start(ctx, "Player.createOrUpdate", trace.WithAttributes(
|
||||
attribute.String("server.key", key),
|
||||
))
|
||||
|
@ -84,8 +85,15 @@ func (p *Player) createOrUpdate(ctx context.Context, key string, players []domai
|
|||
params := make([]domain.CreatePlayerParams, 0, len(chunk))
|
||||
for _, player := range chunk {
|
||||
params = append(params, domain.CreatePlayerParams{
|
||||
BasePlayer: player,
|
||||
ServerKey: key,
|
||||
OpponentsDefeated: domain.OpponentsDefeated(player.OpponentsDefeated),
|
||||
ID: player.ID,
|
||||
Name: player.Name,
|
||||
NumVillages: player.NumVillages,
|
||||
Points: player.Points,
|
||||
Rank: player.Rank,
|
||||
TribeID: player.TribeID,
|
||||
ProfileURL: player.ProfileURL,
|
||||
ServerKey: key,
|
||||
})
|
||||
}
|
||||
if err := p.repo.CreateOrUpdate(ctx, params...); err != nil {
|
||||
|
@ -98,7 +106,7 @@ func (p *Player) createOrUpdate(ctx context.Context, key string, players []domai
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Player) delete(ctx context.Context, key string, existing []domain.BasePlayer) error {
|
||||
func (p *Player) delete(ctx context.Context, key string, existing []tw.Player) error {
|
||||
ctx, span := tracer.Start(ctx, "Player.delete", trace.WithAttributes(
|
||||
attribute.String("server.key", key),
|
||||
))
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
|
@ -20,9 +21,9 @@ func TestPlayer_Refresh(t *testing.T) {
|
|||
|
||||
serverKey, serverUrl := "pl169", "https://pl169.plemiona.pl"
|
||||
|
||||
players := []domain.BasePlayer{
|
||||
players := []tw.Player{
|
||||
{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
|
@ -40,7 +41,7 @@ func TestPlayer_Refresh(t *testing.T) {
|
|||
ProfileURL: "profile-998",
|
||||
},
|
||||
{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
|
@ -64,31 +65,36 @@ func TestPlayer_Refresh(t *testing.T) {
|
|||
|
||||
existingPlayers := []domain.Player{
|
||||
{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: serverKey,
|
||||
CreatedAt: time.Now(),
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: serverKey,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
{
|
||||
BasePlayer: players[0],
|
||||
ServerKey: serverKey,
|
||||
CreatedAt: time.Now(),
|
||||
OpponentsDefeated: domain.OpponentsDefeated(players[0].OpponentsDefeated),
|
||||
ID: players[0].ID,
|
||||
Name: players[0].Name,
|
||||
NumVillages: players[0].NumVillages,
|
||||
Points: players[0].Points,
|
||||
Rank: players[0].Rank,
|
||||
TribeID: players[0].TribeID,
|
||||
ProfileURL: players[0].ProfileURL,
|
||||
ServerKey: serverKey,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
}
|
||||
repo := &mock.FakePlayerRepository{}
|
||||
|
@ -108,7 +114,14 @@ func TestPlayer_Refresh(t *testing.T) {
|
|||
_, params := repo.CreateOrUpdateArgsForCall(0)
|
||||
assert.Len(t, params, len(players))
|
||||
for i, p := range params {
|
||||
assert.Equal(t, players[i], p.BasePlayer)
|
||||
assert.EqualValues(t, players[i].OpponentsDefeated, p.OpponentsDefeated)
|
||||
assert.Equal(t, players[i].ID, p.ID)
|
||||
assert.Equal(t, players[i].Name, p.Name)
|
||||
assert.Equal(t, players[i].NumVillages, p.NumVillages)
|
||||
assert.Equal(t, players[i].Points, p.Points)
|
||||
assert.Equal(t, players[i].Rank, p.Rank)
|
||||
assert.Equal(t, players[i].TribeID, p.TribeID)
|
||||
assert.Equal(t, players[i].ProfileURL, p.ProfileURL)
|
||||
assert.Equal(t, serverKey, p.ServerKey)
|
||||
}
|
||||
|
||||
|
@ -309,16 +322,12 @@ func TestPlayer_GetByServerKeyAndID(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
player := domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 123,
|
||||
TribeID: 123,
|
||||
},
|
||||
ID: 123,
|
||||
TribeID: 123,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 123,
|
||||
},
|
||||
ID: 123,
|
||||
},
|
||||
},
|
||||
ServerKey: "pl151",
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
@ -24,10 +25,10 @@ type ServerRepository interface {
|
|||
|
||||
//counterfeiter:generate -o internal/mock/open_server_config_info_getter.gen.go . OpenServerConfigInfoGetter
|
||||
type OpenServerConfigInfoGetter interface {
|
||||
GetOpenServers(ctx context.Context, baseURL string) ([]domain.OpenServer, error)
|
||||
GetServerConfig(ctx context.Context, baseURL string) (domain.ServerConfig, error)
|
||||
GetBuildingInfo(ctx context.Context, baseURL string) (domain.BuildingInfo, error)
|
||||
GetUnitInfo(ctx context.Context, baseURL string) (domain.UnitInfo, error)
|
||||
GetOpenServers(ctx context.Context, baseURL string) ([]tw.Server, error)
|
||||
GetServerConfig(ctx context.Context, baseURL string) (tw.ServerConfig, error)
|
||||
GetBuildingInfo(ctx context.Context, baseURL string) (tw.BuildingInfo, error)
|
||||
GetUnitInfo(ctx context.Context, baseURL string) (tw.UnitInfo, error)
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
|
@ -141,15 +142,15 @@ func (s *Server) UpdateInfoAndConfig(ctx context.Context, key, url string) error
|
|||
|
||||
_, err = s.repo.UpdateByKey(ctx, key, domain.UpdateServerParams{
|
||||
Config: domain.NullServerConfig{
|
||||
Config: cfg,
|
||||
Config: newServerConfig(cfg),
|
||||
Valid: true,
|
||||
},
|
||||
UnitInfo: domain.NullUnitInfo{
|
||||
Info: unitInfo,
|
||||
Info: newUnitInfo(unitInfo),
|
||||
Valid: true,
|
||||
},
|
||||
BuildingInfo: domain.NullBuildingInfo{
|
||||
Info: buildingInfo,
|
||||
Info: newBuildingInfo(buildingInfo),
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
|
@ -290,7 +291,7 @@ func (s *Server) GetNormalByVersionCodeAndKey(ctx context.Context, versionCode,
|
|||
return servers[0], nil
|
||||
}
|
||||
|
||||
func isInOpen(servers []domain.OpenServer, key string) bool {
|
||||
func isInOpen(servers []tw.Server, key string) bool {
|
||||
for _, srv := range servers {
|
||||
if srv.Key == key {
|
||||
return true
|
||||
|
@ -307,3 +308,64 @@ func isSpecialServer(special []domain.Server, key string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func newServerConfig(cfg tw.ServerConfig) domain.ServerConfig {
|
||||
return domain.ServerConfig{
|
||||
Speed: cfg.Speed,
|
||||
UnitSpeed: cfg.UnitSpeed,
|
||||
Moral: cfg.Moral,
|
||||
Build: domain.ServerConfigBuild(cfg.Build),
|
||||
Misc: domain.ServerConfigMisc(cfg.Misc),
|
||||
Commands: domain.ServerConfigCommands(cfg.Commands),
|
||||
Newbie: domain.ServerConfigNewbie(cfg.Newbie),
|
||||
Game: domain.ServerConfigGame(cfg.Game),
|
||||
Buildings: domain.ServerConfigBuildings(cfg.Buildings),
|
||||
Snob: domain.ServerConfigSnob(cfg.Snob),
|
||||
Ally: domain.ServerConfigAlly(cfg.Ally),
|
||||
Coord: domain.ServerConfigCoord(cfg.Coord),
|
||||
Sitter: domain.ServerConfigSitter(cfg.Sitter),
|
||||
Sleep: domain.ServerConfigSleep(cfg.Sleep),
|
||||
Night: domain.ServerConfigNight(cfg.Night),
|
||||
Win: domain.ServerConfigWin(cfg.Win),
|
||||
}
|
||||
}
|
||||
|
||||
func newUnitInfo(info tw.UnitInfo) domain.UnitInfo {
|
||||
return domain.UnitInfo{
|
||||
Spear: domain.Unit(info.Spear),
|
||||
Sword: domain.Unit(info.Sword),
|
||||
Axe: domain.Unit(info.Axe),
|
||||
Archer: domain.Unit(info.Archer),
|
||||
Spy: domain.Unit(info.Spy),
|
||||
Light: domain.Unit(info.Light),
|
||||
Marcher: domain.Unit(info.Marcher),
|
||||
Heavy: domain.Unit(info.Heavy),
|
||||
Ram: domain.Unit(info.Ram),
|
||||
Catapult: domain.Unit(info.Catapult),
|
||||
Knight: domain.Unit(info.Knight),
|
||||
Snob: domain.Unit(info.Snob),
|
||||
Militia: domain.Unit(info.Militia),
|
||||
}
|
||||
}
|
||||
|
||||
func newBuildingInfo(info tw.BuildingInfo) domain.BuildingInfo {
|
||||
return domain.BuildingInfo{
|
||||
Main: domain.Building(info.Main),
|
||||
Barracks: domain.Building(info.Barracks),
|
||||
Stable: domain.Building(info.Stable),
|
||||
Garage: domain.Building(info.Garage),
|
||||
Watchtower: domain.Building(info.Watchtower),
|
||||
Snob: domain.Building(info.Snob),
|
||||
Smith: domain.Building(info.Smith),
|
||||
Place: domain.Building(info.Place),
|
||||
Statue: domain.Building(info.Statue),
|
||||
Market: domain.Building(info.Market),
|
||||
Wood: domain.Building(info.Wood),
|
||||
Stone: domain.Building(info.Stone),
|
||||
Iron: domain.Building(info.Iron),
|
||||
Farm: domain.Building(info.Farm),
|
||||
Storage: domain.Building(info.Storage),
|
||||
Hide: domain.Building(info.Hide),
|
||||
Wall: domain.Building(info.Wall),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -20,7 +21,7 @@ func TestServer_Refresh(t *testing.T) {
|
|||
host := "plemiona.pl"
|
||||
versionCode := "pl"
|
||||
|
||||
openServers := []domain.OpenServer{
|
||||
openServers := []tw.Server{
|
||||
{
|
||||
Key: "pl151",
|
||||
URL: "https://pl151.plemiona.pl",
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"sort"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
@ -27,7 +28,7 @@ type TribeRepository interface {
|
|||
|
||||
//counterfeiter:generate -o internal/mock/tribe_getter.gen.go . TribeGetter
|
||||
type TribeGetter interface {
|
||||
GetTribes(ctx context.Context, baseURL string) ([]domain.BaseTribe, error)
|
||||
GetTribes(ctx context.Context, baseURL string) ([]tw.Tribe, error)
|
||||
}
|
||||
|
||||
type Tribe struct {
|
||||
|
@ -68,7 +69,7 @@ func (t *Tribe) Refresh(ctx context.Context, key, url string) (int64, error) {
|
|||
return int64(len(tribes)), nil
|
||||
}
|
||||
|
||||
func (t *Tribe) createOrUpdate(ctx context.Context, key string, tribes []domain.BaseTribe) error {
|
||||
func (t *Tribe) createOrUpdate(ctx context.Context, key string, tribes []tw.Tribe) error {
|
||||
ctx, span := tracer.Start(ctx, "Tribe.createOrUpdate", trace.WithAttributes(
|
||||
attribute.String("server.key", key),
|
||||
))
|
||||
|
@ -85,8 +86,17 @@ func (t *Tribe) createOrUpdate(ctx context.Context, key string, tribes []domain.
|
|||
params := make([]domain.CreateTribeParams, 0, len(chunk))
|
||||
for _, tribe := range chunk {
|
||||
params = append(params, domain.CreateTribeParams{
|
||||
BaseTribe: tribe,
|
||||
ServerKey: key,
|
||||
OpponentsDefeated: domain.OpponentsDefeated(tribe.OpponentsDefeated),
|
||||
ID: tribe.ID,
|
||||
Name: tribe.Name,
|
||||
Tag: tribe.Tag,
|
||||
NumMembers: tribe.NumMembers,
|
||||
NumVillages: tribe.NumVillages,
|
||||
Points: tribe.Points,
|
||||
AllPoints: tribe.AllPoints,
|
||||
Rank: tribe.Rank,
|
||||
ProfileURL: tribe.ProfileURL,
|
||||
ServerKey: key,
|
||||
})
|
||||
}
|
||||
if err := t.repo.CreateOrUpdate(ctx, params...); err != nil {
|
||||
|
@ -99,7 +109,7 @@ func (t *Tribe) createOrUpdate(ctx context.Context, key string, tribes []domain.
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *Tribe) delete(ctx context.Context, key string, existing []domain.BaseTribe) error {
|
||||
func (t *Tribe) delete(ctx context.Context, key string, existing []tw.Tribe) error {
|
||||
ctx, span := tracer.Start(ctx, "Tribe.delete", trace.WithAttributes(
|
||||
attribute.String("server.key", key),
|
||||
))
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -23,9 +24,9 @@ func TestTribe_Refresh(t *testing.T) {
|
|||
|
||||
serverKey, serverUrl := "pl169", "https://pl169.plemiona.pl"
|
||||
|
||||
tribes := []domain.BaseTribe{
|
||||
tribes := []tw.Tribe{
|
||||
{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
|
@ -46,7 +47,7 @@ func TestTribe_Refresh(t *testing.T) {
|
|||
ProfileURL: "profile-998",
|
||||
},
|
||||
{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 3,
|
||||
|
@ -72,36 +73,43 @@ func TestTribe_Refresh(t *testing.T) {
|
|||
|
||||
existingTribes := []domain.Tribe{
|
||||
{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
RankAtt: 8,
|
||||
ScoreAtt: 7,
|
||||
RankDef: 6,
|
||||
ScoreDef: 5,
|
||||
RankSup: 4,
|
||||
ScoreSup: 3,
|
||||
RankTotal: 2,
|
||||
ScoreTotal: 1,
|
||||
},
|
||||
ServerKey: serverKey,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
ID: 997,
|
||||
Name: "name 997",
|
||||
Tag: "tag 997",
|
||||
NumMembers: 6,
|
||||
NumVillages: 5,
|
||||
Points: 4,
|
||||
AllPoints: 3,
|
||||
Rank: 2,
|
||||
ProfileURL: "profile-997",
|
||||
ServerKey: serverKey,
|
||||
Dominance: 12.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
{
|
||||
BaseTribe: tribes[0],
|
||||
ServerKey: serverKey,
|
||||
Dominance: 11.5,
|
||||
CreatedAt: time.Now(),
|
||||
OpponentsDefeated: domain.OpponentsDefeated(tribes[0].OpponentsDefeated),
|
||||
ID: tribes[0].ID,
|
||||
Name: tribes[0].Name,
|
||||
Tag: tribes[0].Tag,
|
||||
NumMembers: tribes[0].NumMembers,
|
||||
NumVillages: tribes[0].NumVillages,
|
||||
Points: tribes[0].Points,
|
||||
AllPoints: tribes[0].AllPoints,
|
||||
Rank: tribes[0].Rank,
|
||||
ProfileURL: tribes[0].ProfileURL,
|
||||
ServerKey: serverKey,
|
||||
Dominance: 11.5,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
}
|
||||
repo := &mock.FakeTribeRepository{}
|
||||
|
@ -121,7 +129,16 @@ func TestTribe_Refresh(t *testing.T) {
|
|||
_, params := repo.CreateOrUpdateArgsForCall(0)
|
||||
assert.Len(t, params, len(tribes))
|
||||
for i, p := range params {
|
||||
assert.Equal(t, tribes[i], p.BaseTribe)
|
||||
assert.EqualValues(t, tribes[i].OpponentsDefeated, p.OpponentsDefeated)
|
||||
assert.Equal(t, tribes[i].ID, p.ID)
|
||||
assert.Equal(t, tribes[i].Name, p.Name)
|
||||
assert.Equal(t, tribes[i].Tag, p.Tag)
|
||||
assert.Equal(t, tribes[i].NumMembers, p.NumMembers)
|
||||
assert.Equal(t, tribes[i].NumVillages, p.NumVillages)
|
||||
assert.Equal(t, tribes[i].Points, p.Points)
|
||||
assert.Equal(t, tribes[i].AllPoints, p.AllPoints)
|
||||
assert.Equal(t, tribes[i].Rank, p.Rank)
|
||||
assert.Equal(t, tribes[i].ProfileURL, p.ProfileURL)
|
||||
assert.Equal(t, serverKey, p.ServerKey)
|
||||
}
|
||||
|
||||
|
@ -322,9 +339,7 @@ func TestTribe_GetByServerKeyAndID(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
tribe := domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 123,
|
||||
},
|
||||
ID: 123,
|
||||
ServerKey: "pl151",
|
||||
}
|
||||
repo := &mock.FakeTribeRepository{}
|
||||
|
@ -368,10 +383,8 @@ func TestTribe_GetByServerKeyAndTag(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
tribe := domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 123,
|
||||
Tag: "taggg",
|
||||
},
|
||||
ID: 123,
|
||||
Tag: "taggg",
|
||||
ServerKey: "pl151",
|
||||
}
|
||||
repo := &mock.FakeTribeRepository{}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
@ -23,7 +24,7 @@ type VillageRepository interface {
|
|||
|
||||
//counterfeiter:generate -o internal/mock/village_getter.gen.go . VillageGetter
|
||||
type VillageGetter interface {
|
||||
GetVillages(ctx context.Context, baseURL string) ([]domain.BaseVillage, error)
|
||||
GetVillages(ctx context.Context, baseURL string) ([]tw.Village, error)
|
||||
}
|
||||
|
||||
type Village struct {
|
||||
|
@ -63,8 +64,16 @@ func (v *Village) Refresh(ctx context.Context, key, url string) (domain.RefreshV
|
|||
params := make([]domain.CreateVillageParams, 0, len(chunk))
|
||||
for _, village := range chunk {
|
||||
params = append(params, domain.CreateVillageParams{
|
||||
BaseVillage: village,
|
||||
ServerKey: key,
|
||||
ID: village.ID,
|
||||
Name: village.Name,
|
||||
Points: village.Points,
|
||||
X: village.X,
|
||||
Y: village.Y,
|
||||
Continent: village.Continent,
|
||||
Bonus: village.Bonus,
|
||||
PlayerID: village.PlayerID,
|
||||
ProfileURL: village.ProfileURL,
|
||||
ServerKey: key,
|
||||
})
|
||||
|
||||
if village.PlayerID > 0 {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -19,7 +20,7 @@ import (
|
|||
func TestVillage_Refresh(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
villages := []domain.BaseVillage{
|
||||
villages := []tw.Village{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "111",
|
||||
|
@ -83,16 +84,17 @@ func TestVillage_Refresh(t *testing.T) {
|
|||
require.Equal(t, 1, repo.CreateOrUpdateCallCount())
|
||||
_, params := repo.CreateOrUpdateArgsForCall(0)
|
||||
assert.Len(t, params, len(villages))
|
||||
for _, village := range villages {
|
||||
var villageToCreate domain.CreateVillageParams
|
||||
for _, p := range params {
|
||||
if p.ID == village.ID {
|
||||
villageToCreate = p
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.Equal(t, village, villageToCreate.BaseVillage)
|
||||
assert.Equal(t, serverKey, villageToCreate.ServerKey)
|
||||
for i, village := range villages {
|
||||
assert.Equal(t, village.ID, params[i].ID)
|
||||
assert.Equal(t, village.Name, params[i].Name)
|
||||
assert.Equal(t, village.ProfileURL, params[i].ProfileURL)
|
||||
assert.Equal(t, village.X, params[i].X)
|
||||
assert.Equal(t, village.Y, params[i].Y)
|
||||
assert.Equal(t, village.Points, params[i].Points)
|
||||
assert.Equal(t, village.Continent, params[i].Continent)
|
||||
assert.Equal(t, village.Bonus, params[i].Bonus)
|
||||
assert.Equal(t, village.PlayerID, params[i].PlayerID)
|
||||
assert.Equal(t, serverKey, params[i].ServerKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,23 +237,17 @@ func TestVillage_GetByServerKeyAndID(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
player := domain.Village{
|
||||
BaseVillage: domain.BaseVillage{
|
||||
ID: 123,
|
||||
PlayerID: 123,
|
||||
},
|
||||
ID: 123,
|
||||
PlayerID: 123,
|
||||
Player: domain.NullPlayer{
|
||||
Valid: true,
|
||||
Player: domain.Player{
|
||||
BasePlayer: domain.BasePlayer{
|
||||
ID: 123,
|
||||
TribeID: 1234,
|
||||
},
|
||||
ID: 123,
|
||||
TribeID: 1234,
|
||||
Tribe: domain.NullTribe{
|
||||
Valid: true,
|
||||
Tribe: domain.Tribe{
|
||||
BaseTribe: domain.BaseTribe{
|
||||
ID: 1234,
|
||||
},
|
||||
ID: 1234,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -2,12 +2,9 @@ package tw
|
|||
|
||||
import (
|
||||
"encoding/xml"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
)
|
||||
|
||||
type building struct {
|
||||
Text string `xml:",chardata"`
|
||||
type Building struct {
|
||||
MaxLevel int8 `xml:"max_level"`
|
||||
MinLevel int8 `xml:"min_level"`
|
||||
Wood int32 `xml:"wood"`
|
||||
|
@ -22,63 +19,24 @@ type building struct {
|
|||
BuildTimeFactor float64 `xml:"build_time_factor"`
|
||||
}
|
||||
|
||||
func (b building) toDomain() domain.Building {
|
||||
return domain.Building{
|
||||
MaxLevel: b.MaxLevel,
|
||||
MinLevel: b.MinLevel,
|
||||
Wood: b.Wood,
|
||||
Stone: b.Stone,
|
||||
Iron: b.Iron,
|
||||
Pop: b.Pop,
|
||||
WoodFactor: b.WoodFactor,
|
||||
StoneFactor: b.StoneFactor,
|
||||
IronFactor: b.IronFactor,
|
||||
PopFactor: b.PopFactor,
|
||||
BuildTime: b.BuildTime,
|
||||
BuildTimeFactor: b.BuildTimeFactor,
|
||||
}
|
||||
}
|
||||
|
||||
type buildingInfo struct {
|
||||
type BuildingInfo struct {
|
||||
XMLName xml.Name `xml:"config"`
|
||||
Text string `xml:",chardata"`
|
||||
Main building `xml:"main"`
|
||||
Barracks building `xml:"barracks"`
|
||||
Stable building `xml:"stable"`
|
||||
Garage building `xml:"garage"`
|
||||
Watchtower building `xml:"watchtower"`
|
||||
Snob building `xml:"snob"`
|
||||
Smith building `xml:"smith"`
|
||||
Place building `xml:"place"`
|
||||
Statue building `xml:"statue"`
|
||||
Market building `xml:"market"`
|
||||
Wood building `xml:"wood"`
|
||||
Stone building `xml:"stone"`
|
||||
Iron building `xml:"iron"`
|
||||
Farm building `xml:"farm"`
|
||||
Storage building `xml:"storage"`
|
||||
Hide building `xml:"hide"`
|
||||
Wall building `xml:"wall"`
|
||||
}
|
||||
|
||||
func (b buildingInfo) toDomain() domain.BuildingInfo {
|
||||
return domain.BuildingInfo{
|
||||
Main: b.Main.toDomain(),
|
||||
Barracks: b.Barracks.toDomain(),
|
||||
Stable: b.Stable.toDomain(),
|
||||
Garage: b.Garage.toDomain(),
|
||||
Watchtower: b.Watchtower.toDomain(),
|
||||
Snob: b.Snob.toDomain(),
|
||||
Smith: b.Smith.toDomain(),
|
||||
Place: b.Place.toDomain(),
|
||||
Statue: b.Statue.toDomain(),
|
||||
Market: b.Market.toDomain(),
|
||||
Wood: b.Wood.toDomain(),
|
||||
Stone: b.Stone.toDomain(),
|
||||
Iron: b.Iron.toDomain(),
|
||||
Farm: b.Farm.toDomain(),
|
||||
Storage: b.Storage.toDomain(),
|
||||
Hide: b.Hide.toDomain(),
|
||||
Wall: b.Wall.toDomain(),
|
||||
}
|
||||
Main Building `xml:"main"`
|
||||
Barracks Building `xml:"barracks"`
|
||||
Stable Building `xml:"stable"`
|
||||
Garage Building `xml:"garage"`
|
||||
Watchtower Building `xml:"watchtower"`
|
||||
Snob Building `xml:"snob"`
|
||||
Smith Building `xml:"smith"`
|
||||
Place Building `xml:"place"`
|
||||
Statue Building `xml:"statue"`
|
||||
Market Building `xml:"market"`
|
||||
Wood Building `xml:"wood"`
|
||||
Stone Building `xml:"stone"`
|
||||
Iron Building `xml:"iron"`
|
||||
Farm Building `xml:"farm"`
|
||||
Storage Building `xml:"storage"`
|
||||
Hide Building `xml:"hide"`
|
||||
Wall Building `xml:"wall"`
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
"github.com/elliotchance/phpserialize"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
|
@ -92,7 +91,12 @@ func NewClient(opts ...ClientOption) *Client {
|
|||
return c
|
||||
}
|
||||
|
||||
func (c *Client) GetOpenServers(ctx context.Context, baseURL string) ([]domain.OpenServer, error) {
|
||||
type Server struct {
|
||||
Key string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (c *Client) GetOpenServers(ctx context.Context, baseURL string) ([]Server, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.GetOpenServers", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
))
|
||||
|
@ -122,7 +126,7 @@ func (c *Client) GetOpenServers(ctx context.Context, baseURL string) ([]domain.O
|
|||
return nil, fmt.Errorf("phpserialize.UnmarshalAssociativeArray: %w", err)
|
||||
}
|
||||
|
||||
servers := make([]domain.OpenServer, 0, len(m))
|
||||
servers := make([]Server, 0, len(m))
|
||||
for key, val := range m {
|
||||
keyStr, ok := key.(string)
|
||||
if !ok || keyStr == "" {
|
||||
|
@ -140,7 +144,7 @@ func (c *Client) GetOpenServers(ctx context.Context, baseURL string) ([]domain.O
|
|||
return nil, err
|
||||
}
|
||||
|
||||
servers = append(servers, domain.OpenServer{
|
||||
servers = append(servers, Server{
|
||||
Key: keyStr,
|
||||
URL: urlStr,
|
||||
})
|
||||
|
@ -149,58 +153,58 @@ func (c *Client) GetOpenServers(ctx context.Context, baseURL string) ([]domain.O
|
|||
return servers, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetServerConfig(ctx context.Context, baseURL string) (domain.ServerConfig, error) {
|
||||
func (c *Client) GetServerConfig(ctx context.Context, baseURL string) (ServerConfig, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.GetServerConfig", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
))
|
||||
defer span.End()
|
||||
|
||||
var cfg serverConfig
|
||||
var cfg ServerConfig
|
||||
|
||||
if err := c.getXML(ctx, buildURL(baseURL, endpointConfig), &cfg); err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
return domain.ServerConfig{}, fmt.Errorf("c.getXML: %w", err)
|
||||
return ServerConfig{}, fmt.Errorf("c.getXML: %w", err)
|
||||
}
|
||||
|
||||
return cfg.toDomain(), nil
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetBuildingInfo(ctx context.Context, baseURL string) (domain.BuildingInfo, error) {
|
||||
func (c *Client) GetBuildingInfo(ctx context.Context, baseURL string) (BuildingInfo, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.GetBuildingInfo", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
))
|
||||
defer span.End()
|
||||
|
||||
var info buildingInfo
|
||||
var info BuildingInfo
|
||||
|
||||
if err := c.getXML(ctx, buildURL(baseURL, endpointBuildingInfo), &info); err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
return domain.BuildingInfo{}, fmt.Errorf("c.getXML: %w", err)
|
||||
return BuildingInfo{}, fmt.Errorf("c.getXML: %w", err)
|
||||
}
|
||||
|
||||
return info.toDomain(), nil
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetUnitInfo(ctx context.Context, baseURL string) (domain.UnitInfo, error) {
|
||||
func (c *Client) GetUnitInfo(ctx context.Context, baseURL string) (UnitInfo, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.GetUnitInfo", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
))
|
||||
defer span.End()
|
||||
|
||||
var info unitInfo
|
||||
var info UnitInfo
|
||||
|
||||
if err := c.getXML(ctx, buildURL(baseURL, endpointUnitInfo), &info); err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
return domain.UnitInfo{}, fmt.Errorf("c.getXML: %w", err)
|
||||
return UnitInfo{}, fmt.Errorf("c.getXML: %w", err)
|
||||
}
|
||||
|
||||
return info.toDomain(), nil
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetTribes(ctx context.Context, baseURL string) ([]domain.BaseTribe, error) {
|
||||
func (c *Client) GetTribes(ctx context.Context, baseURL string) ([]Tribe, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.GetTribes", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
))
|
||||
|
@ -220,7 +224,7 @@ func (c *Client) GetTribes(ctx context.Context, baseURL string) ([]domain.BaseTr
|
|||
return nil, fmt.Errorf("c.getCSV: %w", err)
|
||||
}
|
||||
|
||||
tribes := make([]domain.BaseTribe, 0, len(records))
|
||||
tribes := make([]Tribe, 0, len(records))
|
||||
for _, rec := range records {
|
||||
tribe, err := parseTribeRecord(rec, od, baseURL)
|
||||
if err != nil {
|
||||
|
@ -239,7 +243,7 @@ func (c *Client) GetTribes(ctx context.Context, baseURL string) ([]domain.BaseTr
|
|||
return tribes, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetPlayers(ctx context.Context, baseURL string) ([]domain.BasePlayer, error) {
|
||||
func (c *Client) GetPlayers(ctx context.Context, baseURL string) ([]Player, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.GetPlayers", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
))
|
||||
|
@ -259,7 +263,7 @@ func (c *Client) GetPlayers(ctx context.Context, baseURL string) ([]domain.BaseP
|
|||
return nil, fmt.Errorf("c.getCSV: %w", err)
|
||||
}
|
||||
|
||||
players := make([]domain.BasePlayer, 0, len(records))
|
||||
players := make([]Player, 0, len(records))
|
||||
for _, rec := range records {
|
||||
player, err := parsePlayerRecord(rec, od, baseURL)
|
||||
if err != nil {
|
||||
|
@ -278,14 +282,14 @@ func (c *Client) GetPlayers(ctx context.Context, baseURL string) ([]domain.BaseP
|
|||
return players, nil
|
||||
}
|
||||
|
||||
func (c *Client) getOD(ctx context.Context, baseURL string, tribe bool) (map[int64]domain.OpponentsDefeated, error) {
|
||||
func (c *Client) getOD(ctx context.Context, baseURL string, tribe bool) (map[int64]OpponentsDefeated, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.getOD", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
attribute.Bool("tribe", tribe),
|
||||
))
|
||||
defer span.End()
|
||||
|
||||
m := make(map[int64]domain.OpponentsDefeated)
|
||||
m := make(map[int64]OpponentsDefeated)
|
||||
urls := buildODURLs(baseURL, tribe)
|
||||
|
||||
for _, u := range urls {
|
||||
|
@ -332,7 +336,7 @@ func (c *Client) getOD(ctx context.Context, baseURL string, tribe bool) (map[int
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetVillages(ctx context.Context, baseURL string) ([]domain.BaseVillage, error) {
|
||||
func (c *Client) GetVillages(ctx context.Context, baseURL string) ([]Village, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.GetVillages", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
))
|
||||
|
@ -345,7 +349,7 @@ func (c *Client) GetVillages(ctx context.Context, baseURL string) ([]domain.Base
|
|||
return nil, fmt.Errorf("c.getCSV: %w", err)
|
||||
}
|
||||
|
||||
villages := make([]domain.BaseVillage, 0, len(records))
|
||||
villages := make([]Village, 0, len(records))
|
||||
for _, rec := range records {
|
||||
village, err := parseVillageRecord(rec, baseURL)
|
||||
if err != nil {
|
||||
|
@ -364,7 +368,7 @@ func (c *Client) GetVillages(ctx context.Context, baseURL string) ([]domain.Base
|
|||
return villages, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetEnnoblements(ctx context.Context, baseURL string, since time.Time) ([]domain.BaseEnnoblement, error) {
|
||||
func (c *Client) GetEnnoblements(ctx context.Context, baseURL string, since time.Time) ([]Ennoblement, error) {
|
||||
ctx, span := tracer.Start(ctx, "Client.GetEnnoblements", trace.WithAttributes(
|
||||
attribute.String("base_url", baseURL),
|
||||
attribute.Int64("since", since.Unix()),
|
||||
|
@ -396,7 +400,7 @@ func (c *Client) GetEnnoblements(ctx context.Context, baseURL string, since time
|
|||
cnt++
|
||||
}
|
||||
|
||||
ennoblements := make([]domain.BaseEnnoblement, 0, cnt)
|
||||
ennoblements := make([]Ennoblement, 0, cnt)
|
||||
for _, rec := range records {
|
||||
ennoblement, err := parseEnnoblementRecord(rec)
|
||||
if err != nil {
|
||||
|
@ -479,48 +483,48 @@ func (c *Client) get(ctx context.Context, url string) (*http.Response, error) {
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func parseTribeRecord(record []string, od map[int64]domain.OpponentsDefeated, baseURL string) (domain.BaseTribe, error) {
|
||||
func parseTribeRecord(record []string, od map[int64]OpponentsDefeated, baseURL string) (Tribe, error) {
|
||||
var err error
|
||||
var tribe domain.BaseTribe
|
||||
var tribe Tribe
|
||||
|
||||
tribe.ID, err = strconv.ParseInt(record[0], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseTribe{}, NewParseError(err, record, "tribe.ID")
|
||||
return Tribe{}, NewParseError(err, record, "tribe.ID")
|
||||
}
|
||||
|
||||
tribe.Name, err = url.QueryUnescape(record[1])
|
||||
if err != nil {
|
||||
return domain.BaseTribe{}, NewParseError(err, record, "tribe.Name")
|
||||
return Tribe{}, NewParseError(err, record, "tribe.Name")
|
||||
}
|
||||
|
||||
tribe.Tag, err = url.QueryUnescape(record[2])
|
||||
if err != nil {
|
||||
return domain.BaseTribe{}, NewParseError(err, record, "tribe.Tag")
|
||||
return Tribe{}, NewParseError(err, record, "tribe.Tag")
|
||||
}
|
||||
|
||||
tribe.NumMembers, err = strconv.ParseInt(record[3], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseTribe{}, NewParseError(err, record, "tribe.NumMembers")
|
||||
return Tribe{}, NewParseError(err, record, "tribe.NumMembers")
|
||||
}
|
||||
|
||||
tribe.NumVillages, err = strconv.ParseInt(record[4], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseTribe{}, NewParseError(err, record, "tribe.NumVillages")
|
||||
return Tribe{}, NewParseError(err, record, "tribe.NumVillages")
|
||||
}
|
||||
|
||||
tribe.Points, err = strconv.ParseInt(record[5], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseTribe{}, NewParseError(err, record, "tribe.Points")
|
||||
return Tribe{}, NewParseError(err, record, "tribe.Points")
|
||||
}
|
||||
|
||||
tribe.AllPoints, err = strconv.ParseInt(record[6], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseTribe{}, NewParseError(err, record, "tribe.AllPoints")
|
||||
return Tribe{}, NewParseError(err, record, "tribe.AllPoints")
|
||||
}
|
||||
|
||||
tribe.Rank, err = strconv.ParseInt(record[7], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseTribe{}, NewParseError(err, record, "tribe.Rank")
|
||||
return Tribe{}, NewParseError(err, record, "tribe.Rank")
|
||||
}
|
||||
|
||||
tribe.OpponentsDefeated = od[tribe.ID]
|
||||
|
@ -529,38 +533,38 @@ func parseTribeRecord(record []string, od map[int64]domain.OpponentsDefeated, ba
|
|||
return tribe, nil
|
||||
}
|
||||
|
||||
func parsePlayerRecord(record []string, od map[int64]domain.OpponentsDefeated, baseURL string) (domain.BasePlayer, error) {
|
||||
func parsePlayerRecord(record []string, od map[int64]OpponentsDefeated, baseURL string) (Player, error) {
|
||||
var err error
|
||||
var player domain.BasePlayer
|
||||
var player Player
|
||||
|
||||
player.ID, err = strconv.ParseInt(record[0], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BasePlayer{}, NewParseError(err, record, "player.ID")
|
||||
return Player{}, NewParseError(err, record, "player.ID")
|
||||
}
|
||||
|
||||
player.Name, err = url.QueryUnescape(record[1])
|
||||
if err != nil {
|
||||
return domain.BasePlayer{}, NewParseError(err, record, "player.Name")
|
||||
return Player{}, NewParseError(err, record, "player.Name")
|
||||
}
|
||||
|
||||
player.TribeID, err = strconv.ParseInt(record[2], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BasePlayer{}, NewParseError(err, record, "player.TribeID")
|
||||
return Player{}, NewParseError(err, record, "player.TribeID")
|
||||
}
|
||||
|
||||
player.NumVillages, err = strconv.ParseInt(record[3], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BasePlayer{}, NewParseError(err, record, "player.NumVillages")
|
||||
return Player{}, NewParseError(err, record, "player.NumVillages")
|
||||
}
|
||||
|
||||
player.Points, err = strconv.ParseInt(record[4], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BasePlayer{}, NewParseError(err, record, "player.Points")
|
||||
return Player{}, NewParseError(err, record, "player.Points")
|
||||
}
|
||||
|
||||
player.Rank, err = strconv.ParseInt(record[5], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BasePlayer{}, NewParseError(err, record, "player.Rank")
|
||||
return Player{}, NewParseError(err, record, "player.Rank")
|
||||
}
|
||||
|
||||
player.OpponentsDefeated = od[player.ID]
|
||||
|
@ -569,43 +573,43 @@ func parsePlayerRecord(record []string, od map[int64]domain.OpponentsDefeated, b
|
|||
return player, nil
|
||||
}
|
||||
|
||||
func parseVillageRecord(record []string, baseURL string) (domain.BaseVillage, error) {
|
||||
func parseVillageRecord(record []string, baseURL string) (Village, error) {
|
||||
var err error
|
||||
var village domain.BaseVillage
|
||||
var village Village
|
||||
|
||||
village.ID, err = strconv.ParseInt(record[0], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseVillage{}, NewParseError(err, record, "village.ID")
|
||||
return Village{}, NewParseError(err, record, "village.ID")
|
||||
}
|
||||
|
||||
village.Name, err = url.QueryUnescape(record[1])
|
||||
if err != nil {
|
||||
return domain.BaseVillage{}, NewParseError(err, record, "village.Name")
|
||||
return Village{}, NewParseError(err, record, "village.Name")
|
||||
}
|
||||
|
||||
village.X, err = strconv.ParseInt(record[2], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseVillage{}, NewParseError(err, record, "village.X")
|
||||
return Village{}, NewParseError(err, record, "village.X")
|
||||
}
|
||||
|
||||
village.Y, err = strconv.ParseInt(record[3], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseVillage{}, NewParseError(err, record, "village.Y")
|
||||
return Village{}, NewParseError(err, record, "village.Y")
|
||||
}
|
||||
|
||||
village.PlayerID, err = strconv.ParseInt(record[4], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseVillage{}, NewParseError(err, record, "village.PlayerID")
|
||||
return Village{}, NewParseError(err, record, "village.PlayerID")
|
||||
}
|
||||
|
||||
village.Points, err = strconv.ParseInt(record[5], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseVillage{}, NewParseError(err, record, "village.Points")
|
||||
return Village{}, NewParseError(err, record, "village.Points")
|
||||
}
|
||||
|
||||
village.Bonus, err = strconv.ParseInt(record[6], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseVillage{}, NewParseError(err, record, "village.Bonus")
|
||||
return Village{}, NewParseError(err, record, "village.Bonus")
|
||||
}
|
||||
|
||||
village.Continent = "K" + string(record[3][0]) + string(record[2][0])
|
||||
|
@ -642,43 +646,43 @@ func parseODRecord(record []string) (odRecord, error) {
|
|||
return rec, nil
|
||||
}
|
||||
|
||||
func parseEnnoblementRecord(record []string) (domain.BaseEnnoblement, error) {
|
||||
func parseEnnoblementRecord(record []string) (Ennoblement, error) {
|
||||
var err error
|
||||
var ennoblement domain.BaseEnnoblement
|
||||
var ennoblement Ennoblement
|
||||
|
||||
ennoblement.VillageID, err = strconv.ParseInt(record[0], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseEnnoblement{}, NewParseError(err, record, "ennoblement.VillageID")
|
||||
return Ennoblement{}, NewParseError(err, record, "ennoblement.VillageID")
|
||||
}
|
||||
|
||||
ennoblement.CreatedAt, err = parseTimestamp(record[1])
|
||||
if err != nil {
|
||||
return domain.BaseEnnoblement{}, NewParseError(err, record, "ennoblement.CreatedAt")
|
||||
return Ennoblement{}, NewParseError(err, record, "ennoblement.CreatedAt")
|
||||
}
|
||||
|
||||
ennoblement.NewOwnerID, err = strconv.ParseInt(record[2], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseEnnoblement{}, NewParseError(err, record, "ennoblement.NewOwnerID")
|
||||
return Ennoblement{}, NewParseError(err, record, "ennoblement.NewOwnerID")
|
||||
}
|
||||
|
||||
ennoblement.OldOwnerID, err = strconv.ParseInt(record[3], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseEnnoblement{}, NewParseError(err, record, "ennoblement.OldOwnerID")
|
||||
return Ennoblement{}, NewParseError(err, record, "ennoblement.OldOwnerID")
|
||||
}
|
||||
|
||||
ennoblement.OldTribeID, err = strconv.ParseInt(record[4], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseEnnoblement{}, NewParseError(err, record, "ennoblement.OldTribeID")
|
||||
return Ennoblement{}, NewParseError(err, record, "ennoblement.OldTribeID")
|
||||
}
|
||||
|
||||
ennoblement.NewTribeID, err = strconv.ParseInt(record[5], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseEnnoblement{}, NewParseError(err, record, "ennoblement.NewTribeID")
|
||||
return Ennoblement{}, NewParseError(err, record, "ennoblement.NewTribeID")
|
||||
}
|
||||
|
||||
ennoblement.Points, err = strconv.ParseInt(record[6], 10, 64)
|
||||
if err != nil {
|
||||
return domain.BaseEnnoblement{}, NewParseError(err, record, "ennoblement.Points")
|
||||
return Ennoblement{}, NewParseError(err, record, "ennoblement.Points")
|
||||
}
|
||||
|
||||
return ennoblement, nil
|
||||
|
|
|
@ -15,8 +15,6 @@ import (
|
|||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/tw"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -576,7 +574,7 @@ func TestClient_GetTribes(t *testing.T) {
|
|||
respODA string
|
||||
respODD string
|
||||
checkErr func(err error) bool
|
||||
expectedTribes []domain.BaseTribe
|
||||
expectedTribes []tw.Tribe
|
||||
}{
|
||||
{
|
||||
name: "OK",
|
||||
|
@ -584,7 +582,7 @@ func TestClient_GetTribes(t *testing.T) {
|
|||
respOD: "1,1,1\n2,2,2\n3,3,3",
|
||||
respODA: "1,1,1\n2,2,2\n3,3,3",
|
||||
respODD: "1,1,1\n2,2,2\n3,3,3",
|
||||
expectedTribes: []domain.BaseTribe{
|
||||
expectedTribes: []tw.Tribe{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "name 1",
|
||||
|
@ -594,7 +592,7 @@ func TestClient_GetTribes(t *testing.T) {
|
|||
Points: 102,
|
||||
AllPoints: 103,
|
||||
Rank: 104,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 1,
|
||||
RankDef: 1,
|
||||
|
@ -614,7 +612,7 @@ func TestClient_GetTribes(t *testing.T) {
|
|||
Points: 202,
|
||||
AllPoints: 203,
|
||||
Rank: 204,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 2,
|
||||
ScoreAtt: 2,
|
||||
RankDef: 2,
|
||||
|
@ -634,7 +632,7 @@ func TestClient_GetTribes(t *testing.T) {
|
|||
Points: 302,
|
||||
AllPoints: 303,
|
||||
Rank: 304,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 3,
|
||||
ScoreAtt: 3,
|
||||
RankDef: 3,
|
||||
|
@ -654,7 +652,7 @@ func TestClient_GetTribes(t *testing.T) {
|
|||
Points: 402,
|
||||
AllPoints: 403,
|
||||
Rank: 404,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{},
|
||||
OpponentsDefeated: tw.OpponentsDefeated{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -824,7 +822,7 @@ func TestClient_GetTribes(t *testing.T) {
|
|||
assert.Empty(t, cmp.Diff(
|
||||
tt.expectedTribes[i],
|
||||
tribe,
|
||||
cmpopts.IgnoreFields(domain.BaseTribe{}, "ProfileURL"),
|
||||
cmpopts.IgnoreFields(tw.Tribe{}, "ProfileURL"),
|
||||
))
|
||||
assert.Equal(
|
||||
t,
|
||||
|
@ -847,7 +845,7 @@ func TestClient_GetPlayers(t *testing.T) {
|
|||
respODD string
|
||||
respODS string
|
||||
checkErr func(err error) bool
|
||||
expectedPlayers []domain.BasePlayer
|
||||
expectedPlayers []tw.Player
|
||||
}{
|
||||
{
|
||||
name: "OK",
|
||||
|
@ -856,7 +854,7 @@ func TestClient_GetPlayers(t *testing.T) {
|
|||
respODA: "1,1,1000\n2,2,253\n3,3,100",
|
||||
respODD: "1,1,1002\n2,2,251\n3,3,155",
|
||||
respODS: "1,1,1003\n2,2,250\n3,3,166",
|
||||
expectedPlayers: []domain.BasePlayer{
|
||||
expectedPlayers: []tw.Player{
|
||||
{
|
||||
ID: 1,
|
||||
Name: "name 1",
|
||||
|
@ -864,7 +862,7 @@ func TestClient_GetPlayers(t *testing.T) {
|
|||
NumVillages: 124,
|
||||
Points: 125,
|
||||
Rank: 126,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 1,
|
||||
ScoreAtt: 1000,
|
||||
RankDef: 1,
|
||||
|
@ -882,7 +880,7 @@ func TestClient_GetPlayers(t *testing.T) {
|
|||
NumVillages: 257,
|
||||
Points: 258,
|
||||
Rank: 259,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 2,
|
||||
ScoreAtt: 253,
|
||||
RankDef: 2,
|
||||
|
@ -900,7 +898,7 @@ func TestClient_GetPlayers(t *testing.T) {
|
|||
NumVillages: 357,
|
||||
Points: 358,
|
||||
Rank: 359,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{
|
||||
OpponentsDefeated: tw.OpponentsDefeated{
|
||||
RankAtt: 3,
|
||||
ScoreAtt: 100,
|
||||
RankDef: 3,
|
||||
|
@ -918,7 +916,7 @@ func TestClient_GetPlayers(t *testing.T) {
|
|||
NumVillages: 457,
|
||||
Points: 458,
|
||||
Rank: 459,
|
||||
OpponentsDefeated: domain.OpponentsDefeated{},
|
||||
OpponentsDefeated: tw.OpponentsDefeated{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1105,7 +1103,7 @@ func TestClient_GetPlayers(t *testing.T) {
|
|||
assert.Empty(t, cmp.Diff(
|
||||
tt.expectedPlayers[i],
|
||||
player,
|
||||
cmpopts.IgnoreFields(domain.BasePlayer{}, "ProfileURL"),
|
||||
cmpopts.IgnoreFields(tw.Player{}, "ProfileURL"),
|
||||
))
|
||||
assert.Equal(
|
||||
t,
|
||||
|
@ -1124,12 +1122,12 @@ func TestClient_GetVillages(t *testing.T) {
|
|||
name string
|
||||
resp string
|
||||
checkErr func(err error) bool
|
||||
expectedVillages []domain.BaseVillage
|
||||
expectedVillages []tw.Village
|
||||
}{
|
||||
{
|
||||
name: "OK",
|
||||
resp: "123,village%201,500,501,502,503,504\n124,village 2,100,201,102,103,104",
|
||||
expectedVillages: []domain.BaseVillage{
|
||||
expectedVillages: []tw.Village{
|
||||
{
|
||||
ID: 123,
|
||||
Name: "village 1",
|
||||
|
@ -1243,7 +1241,7 @@ func TestClient_GetVillages(t *testing.T) {
|
|||
assert.Empty(t, cmp.Diff(
|
||||
tt.expectedVillages[i],
|
||||
village,
|
||||
cmpopts.IgnoreFields(domain.BaseVillage{}, "ProfileURL"),
|
||||
cmpopts.IgnoreFields(tw.Village{}, "ProfileURL"),
|
||||
))
|
||||
assert.Equal(
|
||||
t,
|
||||
|
@ -1264,14 +1262,14 @@ func TestClient_GetEnnoblements(t *testing.T) {
|
|||
since time.Time
|
||||
resp string
|
||||
checkErr func(err error) bool
|
||||
expectedEnnoblements []domain.BaseEnnoblement
|
||||
expectedEnnoblements []tw.Ennoblement
|
||||
}{
|
||||
{
|
||||
name: "OK: /map/conquer_extended.txt",
|
||||
since: time.Time{},
|
||||
resp: "1424,1657842406,698953084,699589674,0,122,380\n3150,1657882879,6461674,0,0,179,111\n1025,1657947400,9157005,698942601,0,52,461",
|
||||
checkErr: nil,
|
||||
expectedEnnoblements: []domain.BaseEnnoblement{
|
||||
expectedEnnoblements: []tw.Ennoblement{
|
||||
{
|
||||
VillageID: 1424,
|
||||
NewOwnerID: 698953084,
|
||||
|
@ -1311,7 +1309,7 @@ func TestClient_GetEnnoblements(t *testing.T) {
|
|||
now.Add(-15*time.Second).Unix(),
|
||||
),
|
||||
checkErr: nil,
|
||||
expectedEnnoblements: []domain.BaseEnnoblement{
|
||||
expectedEnnoblements: []tw.Ennoblement{
|
||||
{
|
||||
VillageID: 1424,
|
||||
NewOwnerID: 698953084,
|
||||
|
|
|
@ -2,68 +2,31 @@ package tw
|
|||
|
||||
import (
|
||||
"encoding/xml"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
)
|
||||
|
||||
type serverConfigBuild struct {
|
||||
Text string `xml:",chardata"`
|
||||
Destroy int8 `xml:"destroy"`
|
||||
type ServerConfigBuild struct {
|
||||
Destroy int8 `xml:"destroy"`
|
||||
}
|
||||
|
||||
func (b serverConfigBuild) toDomain() domain.ServerConfigBuild {
|
||||
return domain.ServerConfigBuild{
|
||||
Destroy: b.Destroy,
|
||||
}
|
||||
type ServerConfigMisc struct {
|
||||
KillRanking int8 `xml:"kill_ranking"`
|
||||
Tutorial int8 `xml:"tutorial"`
|
||||
TradeCancelTime int16 `xml:"trade_cancel_time"`
|
||||
}
|
||||
|
||||
type serverConfigMisc struct {
|
||||
Text string `xml:",chardata"`
|
||||
KillRanking int8 `xml:"kill_ranking"`
|
||||
Tutorial int8 `xml:"tutorial"`
|
||||
TradeCancelTime int16 `xml:"trade_cancel_time"`
|
||||
type ServerConfigCommands struct {
|
||||
MillisArrival int16 `xml:"millis_arrival"`
|
||||
CommandCancelTime int16 `xml:"command_cancel_time"`
|
||||
}
|
||||
|
||||
func (m serverConfigMisc) toDomain() domain.ServerConfigMisc {
|
||||
return domain.ServerConfigMisc{
|
||||
KillRanking: m.KillRanking,
|
||||
Tutorial: m.Tutorial,
|
||||
TradeCancelTime: m.TradeCancelTime,
|
||||
}
|
||||
type ServerConfigNewbie struct {
|
||||
Days int16 `xml:"days"`
|
||||
RatioDays int16 `xml:"ratio_days"`
|
||||
Ratio int16 `xml:"ratio"`
|
||||
RemoveNewbieVillages int8 `xml:"removeNewbieVillages"`
|
||||
}
|
||||
|
||||
type serverConfigCommands struct {
|
||||
Text string `xml:",chardata"`
|
||||
MillisArrival int16 `xml:"millis_arrival"`
|
||||
CommandCancelTime int16 `xml:"command_cancel_time"`
|
||||
}
|
||||
|
||||
func (c serverConfigCommands) toDomain() domain.ServerConfigCommands {
|
||||
return domain.ServerConfigCommands{
|
||||
MillisArrival: c.MillisArrival,
|
||||
CommandCancelTime: c.CommandCancelTime,
|
||||
}
|
||||
}
|
||||
|
||||
type serverConfigNewbie struct {
|
||||
Text string `xml:",chardata"`
|
||||
Days int16 `xml:"days"`
|
||||
RatioDays int16 `xml:"ratio_days"`
|
||||
Ratio int16 `xml:"ratio"`
|
||||
RemoveNewbieVillages int8 `xml:"removeNewbieVillages"`
|
||||
}
|
||||
|
||||
func (n serverConfigNewbie) toDomain() domain.ServerConfigNewbie {
|
||||
return domain.ServerConfigNewbie{
|
||||
Days: n.Days,
|
||||
RatioDays: n.RatioDays,
|
||||
Ratio: n.Ratio,
|
||||
RemoveNewbieVillages: n.RemoveNewbieVillages,
|
||||
}
|
||||
}
|
||||
|
||||
type serverConfigGame struct {
|
||||
Text string `xml:",chardata"`
|
||||
type ServerConfigGame struct {
|
||||
BuildtimeFormula int8 `xml:"buildtime_formula"`
|
||||
Knight int8 `xml:"knight"`
|
||||
KnightNewItems int8 `xml:"knight_new_items"`
|
||||
|
@ -85,77 +48,28 @@ type serverConfigGame struct {
|
|||
SuppressEvents int8 `xml:"suppress_events"`
|
||||
}
|
||||
|
||||
func (g serverConfigGame) toDomain() domain.ServerConfigGame {
|
||||
return domain.ServerConfigGame{
|
||||
BuildtimeFormula: g.BuildtimeFormula,
|
||||
Knight: g.Knight,
|
||||
KnightNewItems: g.KnightNewItems,
|
||||
Archer: g.Archer,
|
||||
Tech: g.Tech,
|
||||
FarmLimit: g.FarmLimit,
|
||||
Church: g.Church,
|
||||
Watchtower: g.Watchtower,
|
||||
Stronghold: g.Stronghold,
|
||||
FakeLimit: g.FakeLimit,
|
||||
BarbarianRise: g.BarbarianRise,
|
||||
BarbarianShrink: g.BarbarianShrink,
|
||||
BarbarianMaxPoints: g.BarbarianMaxPoints,
|
||||
Hauls: g.Hauls,
|
||||
HaulsBase: g.HaulsBase,
|
||||
HaulsMax: g.HaulsMax,
|
||||
BaseProduction: g.BaseProduction,
|
||||
Event: g.Event,
|
||||
SuppressEvents: g.SuppressEvents,
|
||||
}
|
||||
type ServerConfigBuildings struct {
|
||||
CustomMain int8 `xml:"custom_main"`
|
||||
CustomFarm int8 `xml:"custom_farm"`
|
||||
CustomStorage int8 `xml:"custom_storage"`
|
||||
CustomPlace int8 `xml:"custom_place"`
|
||||
CustomBarracks int8 `xml:"custom_barracks"`
|
||||
CustomChurch int8 `xml:"custom_church"`
|
||||
CustomSmith int8 `xml:"custom_smith"`
|
||||
CustomWood int8 `xml:"custom_wood"`
|
||||
CustomStone int8 `xml:"custom_stone"`
|
||||
CustomIron int8 `xml:"custom_iron"`
|
||||
CustomMarket int8 `xml:"custom_market"`
|
||||
CustomStable int8 `xml:"custom_stable"`
|
||||
CustomWall int8 `xml:"custom_wall"`
|
||||
CustomGarage int8 `xml:"custom_garage"`
|
||||
CustomHide int8 `xml:"custom_hide"`
|
||||
CustomSnob int8 `xml:"custom_snob"`
|
||||
CustomStatue int8 `xml:"custom_statue"`
|
||||
CustomWatchtower int8 `xml:"custom_watchtower"`
|
||||
}
|
||||
|
||||
type serverConfigBuildings struct {
|
||||
Text string `xml:",chardata"`
|
||||
CustomMain int8 `xml:"custom_main"`
|
||||
CustomFarm int8 `xml:"custom_farm"`
|
||||
CustomStorage int8 `xml:"custom_storage"`
|
||||
CustomPlace int8 `xml:"custom_place"`
|
||||
CustomBarracks int8 `xml:"custom_barracks"`
|
||||
CustomChurch int8 `xml:"custom_church"`
|
||||
CustomSmith int8 `xml:"custom_smith"`
|
||||
CustomWood int8 `xml:"custom_wood"`
|
||||
CustomStone int8 `xml:"custom_stone"`
|
||||
CustomIron int8 `xml:"custom_iron"`
|
||||
CustomMarket int8 `xml:"custom_market"`
|
||||
CustomStable int8 `xml:"custom_stable"`
|
||||
CustomWall int8 `xml:"custom_wall"`
|
||||
CustomGarage int8 `xml:"custom_garage"`
|
||||
CustomHide int8 `xml:"custom_hide"`
|
||||
CustomSnob int8 `xml:"custom_snob"`
|
||||
CustomStatue int8 `xml:"custom_statue"`
|
||||
CustomWatchtower int8 `xml:"custom_watchtower"`
|
||||
}
|
||||
|
||||
func (b serverConfigBuildings) toDomain() domain.ServerConfigBuildings {
|
||||
return domain.ServerConfigBuildings{
|
||||
CustomMain: b.CustomMain,
|
||||
CustomFarm: b.CustomFarm,
|
||||
CustomStorage: b.CustomStorage,
|
||||
CustomPlace: b.CustomPlace,
|
||||
CustomBarracks: b.CustomBarracks,
|
||||
CustomChurch: b.CustomChurch,
|
||||
CustomSmith: b.CustomSmith,
|
||||
CustomWood: b.CustomWood,
|
||||
CustomStone: b.CustomStone,
|
||||
CustomIron: b.CustomIron,
|
||||
CustomMarket: b.CustomMarket,
|
||||
CustomStable: b.CustomStable,
|
||||
CustomWall: b.CustomWall,
|
||||
CustomGarage: b.CustomGarage,
|
||||
CustomHide: b.CustomHide,
|
||||
CustomSnob: b.CustomSnob,
|
||||
CustomStatue: b.CustomStatue,
|
||||
CustomWatchtower: b.CustomWatchtower,
|
||||
}
|
||||
}
|
||||
|
||||
type serverConfigSnob struct {
|
||||
Text string `xml:",chardata"`
|
||||
type ServerConfigSnob struct {
|
||||
Gold int8 `xml:"gold"`
|
||||
CheapRebuild int8 `xml:"cheap_rebuild"`
|
||||
Rise int8 `xml:"rise"`
|
||||
|
@ -167,22 +81,7 @@ type serverConfigSnob struct {
|
|||
NoBarbConquer int8 `xml:"no_barb_conquer"`
|
||||
}
|
||||
|
||||
func (s serverConfigSnob) toDomain() domain.ServerConfigSnob {
|
||||
return domain.ServerConfigSnob{
|
||||
Gold: s.Gold,
|
||||
CheapRebuild: s.CheapRebuild,
|
||||
Rise: s.Rise,
|
||||
MaxDist: s.MaxDist,
|
||||
Factor: s.Factor,
|
||||
CoinWood: s.CoinWood,
|
||||
CoinStone: s.CoinStone,
|
||||
CoinIron: s.CoinIron,
|
||||
NoBarbConquer: s.NoBarbConquer,
|
||||
}
|
||||
}
|
||||
|
||||
type serverConfigAlly struct {
|
||||
Text string `xml:",chardata"`
|
||||
type ServerConfigAlly struct {
|
||||
NoHarm int8 `xml:"no_harm"`
|
||||
NoOtherSupport int8 `xml:"no_other_support"`
|
||||
NoOtherSupportType int8 `xml:"no_other_support_type"`
|
||||
|
@ -199,90 +98,34 @@ type serverConfigAlly struct {
|
|||
XpRequirements string `xml:"xp_requirements"`
|
||||
}
|
||||
|
||||
func (a serverConfigAlly) toDomain() domain.ServerConfigAlly {
|
||||
return domain.ServerConfigAlly{
|
||||
NoHarm: a.NoHarm,
|
||||
NoOtherSupport: a.NoOtherSupport,
|
||||
NoOtherSupportType: a.NoOtherSupportType,
|
||||
AllytimeSupport: a.AllytimeSupport,
|
||||
NoLeave: a.NoLeave,
|
||||
NoJoin: a.NoJoin,
|
||||
Limit: a.Limit,
|
||||
FixedAllies: a.FixedAllies,
|
||||
PointsMemberCount: a.PointsMemberCount,
|
||||
WarsMemberRequirement: a.WarsMemberRequirement,
|
||||
WarsPointsRequirement: a.WarsPointsRequirement,
|
||||
WarsAutoacceptDays: a.WarsAutoacceptDays,
|
||||
Levels: a.Levels,
|
||||
XpRequirements: a.XpRequirements,
|
||||
}
|
||||
type ServerConfigCoord struct {
|
||||
MapSize int16 `xml:"map_size"`
|
||||
Func int8 `xml:"func"`
|
||||
EmptyVillages int16 `xml:"empty_villages"`
|
||||
BonusVillages int16 `xml:"bonus_villages"`
|
||||
BonusNew int16 `xml:"bonus_new"`
|
||||
Inner int16 `xml:"inner"`
|
||||
SelectStart int8 `xml:"select_start"`
|
||||
VillageMoveWait int32 `xml:"village_move_wait"`
|
||||
NobleRestart int8 `xml:"noble_restart"`
|
||||
StartVillages int8 `xml:"start_villages"`
|
||||
}
|
||||
|
||||
type serverConfigCoord struct {
|
||||
Text string `xml:",chardata"`
|
||||
MapSize int16 `xml:"map_size"`
|
||||
Func int8 `xml:"func"`
|
||||
EmptyVillages int16 `xml:"empty_villages"`
|
||||
BonusVillages int16 `xml:"bonus_villages"`
|
||||
BonusNew int16 `xml:"bonus_new"`
|
||||
Inner int16 `xml:"inner"`
|
||||
SelectStart int8 `xml:"select_start"`
|
||||
VillageMoveWait int32 `xml:"village_move_wait"`
|
||||
NobleRestart int8 `xml:"noble_restart"`
|
||||
StartVillages int8 `xml:"start_villages"`
|
||||
type ServerConfigSitter struct {
|
||||
Allow int8 `xml:"allow"`
|
||||
}
|
||||
|
||||
func (c serverConfigCoord) toDomain() domain.ServerConfigCoord {
|
||||
return domain.ServerConfigCoord{
|
||||
MapSize: c.MapSize,
|
||||
Func: c.Func,
|
||||
EmptyVillages: c.EmptyVillages,
|
||||
BonusVillages: c.BonusVillages,
|
||||
BonusNew: c.BonusNew,
|
||||
Inner: c.Inner,
|
||||
SelectStart: c.SelectStart,
|
||||
VillageMoveWait: c.VillageMoveWait,
|
||||
NobleRestart: c.NobleRestart,
|
||||
StartVillages: c.StartVillages,
|
||||
}
|
||||
type ServerConfigSleep struct {
|
||||
Active int8 `xml:"active"`
|
||||
Delay int32 `xml:"delay"`
|
||||
Min int16 `xml:"min"`
|
||||
Max int16 `xml:"max"`
|
||||
MinAwake int16 `xml:"min_awake"`
|
||||
MaxAwake int16 `xml:"max_awake"`
|
||||
WarnTime int16 `xml:"warn_time"`
|
||||
}
|
||||
|
||||
type serverConfigSitter struct {
|
||||
Text string `xml:",chardata"`
|
||||
Allow int8 `xml:"allow"`
|
||||
}
|
||||
|
||||
func (s serverConfigSitter) toDomain() domain.ServerConfigSitter {
|
||||
return domain.ServerConfigSitter{
|
||||
Allow: s.Allow,
|
||||
}
|
||||
}
|
||||
|
||||
type serverConfigSleep struct {
|
||||
Text string `xml:",chardata"`
|
||||
Active int8 `xml:"active"`
|
||||
Delay int32 `xml:"delay"`
|
||||
Min int16 `xml:"min"`
|
||||
Max int16 `xml:"max"`
|
||||
MinAwake int16 `xml:"min_awake"`
|
||||
MaxAwake int16 `xml:"max_awake"`
|
||||
WarnTime int16 `xml:"warn_time"`
|
||||
}
|
||||
|
||||
func (s serverConfigSleep) toDomain() domain.ServerConfigSleep {
|
||||
return domain.ServerConfigSleep{
|
||||
Active: s.Active,
|
||||
Delay: s.Delay,
|
||||
Min: s.Min,
|
||||
Max: s.Max,
|
||||
MinAwake: s.MinAwake,
|
||||
MaxAwake: s.MaxAwake,
|
||||
WarnTime: s.WarnTime,
|
||||
}
|
||||
}
|
||||
|
||||
type serverConfigNight struct {
|
||||
Text string `xml:",chardata"`
|
||||
type ServerConfigNight struct {
|
||||
Active int8 `xml:"active"`
|
||||
StartHour int8 `xml:"start_hour"`
|
||||
EndHour int8 `xml:"end_hour"`
|
||||
|
@ -290,65 +133,27 @@ type serverConfigNight struct {
|
|||
Duration int8 `xml:"duration"`
|
||||
}
|
||||
|
||||
func (n serverConfigNight) toDomain() domain.ServerConfigNight {
|
||||
return domain.ServerConfigNight{
|
||||
Active: n.Active,
|
||||
StartHour: n.StartHour,
|
||||
EndHour: n.EndHour,
|
||||
DefFactor: n.DefFactor,
|
||||
Duration: n.Duration,
|
||||
}
|
||||
type ServerConfigWin struct {
|
||||
Check int16 `xml:"check"`
|
||||
}
|
||||
|
||||
type serverConfigWin struct {
|
||||
Text string `xml:",chardata"`
|
||||
Check int16 `xml:"check"`
|
||||
}
|
||||
|
||||
func (w serverConfigWin) toDomain() domain.ServerConfigWin {
|
||||
return domain.ServerConfigWin{
|
||||
Check: w.Check,
|
||||
}
|
||||
}
|
||||
|
||||
type serverConfig struct {
|
||||
type ServerConfig struct {
|
||||
XMLName xml.Name `xml:"config"`
|
||||
Text string `xml:",chardata"`
|
||||
Speed float64 `xml:"speed"`
|
||||
UnitSpeed float64 `xml:"unit_speed"`
|
||||
Moral int16 `xml:"moral"`
|
||||
Build serverConfigBuild `xml:"build"`
|
||||
Misc serverConfigMisc `xml:"misc"`
|
||||
Commands serverConfigCommands `xml:"commands"`
|
||||
Newbie serverConfigNewbie `xml:"newbie"`
|
||||
Game serverConfigGame `xml:"game"`
|
||||
Buildings serverConfigBuildings `xml:"buildings"`
|
||||
Snob serverConfigSnob `xml:"snob"`
|
||||
Ally serverConfigAlly `xml:"ally"`
|
||||
Coord serverConfigCoord `xml:"coord"`
|
||||
Sitter serverConfigSitter `xml:"sitter"`
|
||||
Sleep serverConfigSleep `xml:"sleep"`
|
||||
Night serverConfigNight `xml:"night"`
|
||||
Win serverConfigWin `xml:"win"`
|
||||
}
|
||||
|
||||
func (s serverConfig) toDomain() domain.ServerConfig {
|
||||
return domain.ServerConfig{
|
||||
Speed: s.Speed,
|
||||
UnitSpeed: s.UnitSpeed,
|
||||
Moral: s.Moral,
|
||||
Build: s.Build.toDomain(),
|
||||
Misc: s.Misc.toDomain(),
|
||||
Commands: s.Commands.toDomain(),
|
||||
Newbie: s.Newbie.toDomain(),
|
||||
Game: s.Game.toDomain(),
|
||||
Buildings: s.Buildings.toDomain(),
|
||||
Snob: s.Snob.toDomain(),
|
||||
Ally: s.Ally.toDomain(),
|
||||
Coord: s.Coord.toDomain(),
|
||||
Sitter: s.Sitter.toDomain(),
|
||||
Sleep: s.Sleep.toDomain(),
|
||||
Night: s.Night.toDomain(),
|
||||
Win: s.Win.toDomain(),
|
||||
}
|
||||
Build ServerConfigBuild `xml:"build"`
|
||||
Misc ServerConfigMisc `xml:"misc"`
|
||||
Commands ServerConfigCommands `xml:"commands"`
|
||||
Newbie ServerConfigNewbie `xml:"newbie"`
|
||||
Game ServerConfigGame `xml:"game"`
|
||||
Buildings ServerConfigBuildings `xml:"buildings"`
|
||||
Snob ServerConfigSnob `xml:"snob"`
|
||||
Ally ServerConfigAlly `xml:"ally"`
|
||||
Coord ServerConfigCoord `xml:"coord"`
|
||||
Sitter ServerConfigSitter `xml:"sitter"`
|
||||
Sleep ServerConfigSleep `xml:"sleep"`
|
||||
Night ServerConfigNight `xml:"night"`
|
||||
Win ServerConfigWin `xml:"win"`
|
||||
}
|
||||
|
|
|
@ -1,7 +1,70 @@
|
|||
package tw
|
||||
|
||||
import "go.opentelemetry.io/otel"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
)
|
||||
|
||||
var (
|
||||
tracer = otel.Tracer("gitea.dwysokinski.me/twhelp/core/internal/tw")
|
||||
)
|
||||
|
||||
type OpponentsDefeated struct {
|
||||
RankAtt int64
|
||||
ScoreAtt int64
|
||||
RankDef int64
|
||||
ScoreDef int64
|
||||
RankSup int64
|
||||
ScoreSup int64
|
||||
RankTotal int64
|
||||
ScoreTotal int64
|
||||
}
|
||||
|
||||
type Tribe struct {
|
||||
OpponentsDefeated
|
||||
|
||||
ID int64
|
||||
Name string
|
||||
Tag string
|
||||
NumMembers int64
|
||||
NumVillages int64
|
||||
Points int64
|
||||
AllPoints int64
|
||||
Rank int64
|
||||
ProfileURL string
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
OpponentsDefeated
|
||||
|
||||
ID int64
|
||||
Name string
|
||||
NumVillages int64
|
||||
Points int64
|
||||
Rank int64
|
||||
TribeID int64
|
||||
ProfileURL string
|
||||
}
|
||||
|
||||
type Village struct {
|
||||
ID int64
|
||||
Name string
|
||||
Points int64
|
||||
X int64
|
||||
Y int64
|
||||
Continent string
|
||||
Bonus int64
|
||||
PlayerID int64
|
||||
ProfileURL string
|
||||
}
|
||||
|
||||
type Ennoblement struct {
|
||||
VillageID int64
|
||||
NewOwnerID int64
|
||||
NewTribeID int64
|
||||
OldOwnerID int64
|
||||
OldTribeID int64
|
||||
Points int64
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
|
|
@ -2,12 +2,9 @@ package tw
|
|||
|
||||
import (
|
||||
"encoding/xml"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
)
|
||||
|
||||
type unit struct {
|
||||
Text string `xml:",chardata"`
|
||||
type Unit struct {
|
||||
BuildTime float64 `xml:"build_time"`
|
||||
Pop int16 `xml:"pop"`
|
||||
Speed float64 `xml:"speed"`
|
||||
|
@ -18,51 +15,20 @@ type unit struct {
|
|||
Carry int16 `xml:"carry"`
|
||||
}
|
||||
|
||||
func (u unit) toDomain() domain.Unit {
|
||||
return domain.Unit{
|
||||
BuildTime: u.BuildTime,
|
||||
Pop: u.Pop,
|
||||
Speed: u.Speed,
|
||||
Attack: u.Attack,
|
||||
Defense: u.Defense,
|
||||
DefenseCavalry: u.DefenseCavalry,
|
||||
DefenseArcher: u.DefenseArcher,
|
||||
Carry: u.Carry,
|
||||
}
|
||||
}
|
||||
|
||||
type unitInfo struct {
|
||||
type UnitInfo struct {
|
||||
XMLName xml.Name `xml:"config"`
|
||||
Text string `xml:",chardata"`
|
||||
Spear unit `xml:"spear"`
|
||||
Sword unit `xml:"sword"`
|
||||
Axe unit `xml:"axe"`
|
||||
Archer unit `xml:"archer"`
|
||||
Spy unit `xml:"spy"`
|
||||
Light unit `xml:"light"`
|
||||
Marcher unit `xml:"marcher"`
|
||||
Heavy unit `xml:"heavy"`
|
||||
Ram unit `xml:"ram"`
|
||||
Catapult unit `xml:"catapult"`
|
||||
Knight unit `xml:"knight"`
|
||||
Snob unit `xml:"snob"`
|
||||
Militia unit `xml:"militia"`
|
||||
}
|
||||
|
||||
func (u unitInfo) toDomain() domain.UnitInfo {
|
||||
return domain.UnitInfo{
|
||||
Spear: u.Spear.toDomain(),
|
||||
Sword: u.Sword.toDomain(),
|
||||
Axe: u.Axe.toDomain(),
|
||||
Archer: u.Archer.toDomain(),
|
||||
Spy: u.Spy.toDomain(),
|
||||
Light: u.Light.toDomain(),
|
||||
Marcher: u.Marcher.toDomain(),
|
||||
Heavy: u.Heavy.toDomain(),
|
||||
Ram: u.Ram.toDomain(),
|
||||
Catapult: u.Catapult.toDomain(),
|
||||
Knight: u.Knight.toDomain(),
|
||||
Snob: u.Snob.toDomain(),
|
||||
Militia: u.Militia.toDomain(),
|
||||
}
|
||||
Spear Unit `xml:"spear"`
|
||||
Sword Unit `xml:"sword"`
|
||||
Axe Unit `xml:"axe"`
|
||||
Archer Unit `xml:"archer"`
|
||||
Spy Unit `xml:"spy"`
|
||||
Light Unit `xml:"light"`
|
||||
Marcher Unit `xml:"marcher"`
|
||||
Heavy Unit `xml:"heavy"`
|
||||
Ram Unit `xml:"ram"`
|
||||
Catapult Unit `xml:"catapult"`
|
||||
Knight Unit `xml:"knight"`
|
||||
Snob Unit `xml:"snob"`
|
||||
Militia Unit `xml:"militia"`
|
||||
}
|
||||
|
|
Reference in New Issue
Block a user