Dawid Wysokiński
3b4f42e344
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#186
701 lines
17 KiB
Go
701 lines
17 KiB
Go
package bundb_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/jackc/pgerrcode"
|
|
"github.com/uptrace/bun/driver/pgdriver"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/bundb/bundbtest"
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/bundb"
|
|
)
|
|
|
|
func TestTribe_CreateOrUpdate(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if testing.Short() {
|
|
t.Skip("skipping long-running test")
|
|
}
|
|
|
|
db := bundbtest.NewDB(t)
|
|
_ = loadFixtures(t, db)
|
|
repo := bundb.NewTribe(db)
|
|
|
|
t.Run("OK", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
serverKey := "pl169"
|
|
createParams := []domain.CreateTribeParams{
|
|
{
|
|
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,
|
|
BestRank: 111,
|
|
BestRankAt: time.Now().Add(-5 * time.Minute),
|
|
MostPoints: 222,
|
|
MostPointsAt: time.Now().Add(-1 * time.Minute),
|
|
MostVillages: 333,
|
|
MostVillagesAt: time.Now().Add(-12 * time.Minute),
|
|
ProfileURL: "profile-999",
|
|
ServerKey: serverKey,
|
|
},
|
|
{
|
|
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,
|
|
BestRank: 333,
|
|
BestRankAt: time.Now().Add(-51 * time.Minute),
|
|
MostPoints: 111,
|
|
MostPointsAt: time.Now().Add(-11 * time.Minute),
|
|
MostVillages: 222,
|
|
MostVillagesAt: time.Now().Add(-15 * time.Minute),
|
|
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{
|
|
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,
|
|
BestRank: p.BestRank - 1,
|
|
BestRankAt: p.BestRankAt.Add(time.Minute),
|
|
MostPoints: p.MostPoints + 1,
|
|
MostPointsAt: p.MostPointsAt.Add(time.Minute),
|
|
MostVillages: p.MostVillages + 1,
|
|
MostVillagesAt: p.MostVillagesAt.Add(time.Minute),
|
|
ProfileURL: p.ProfileURL + "Update",
|
|
ServerKey: p.ServerKey,
|
|
})
|
|
ids = append(ids, p.ID)
|
|
}
|
|
listParams := domain.ListTribesParams{
|
|
IDs: ids,
|
|
ServerKeys: []string{serverKey},
|
|
}
|
|
ctx := context.Background()
|
|
|
|
assert.NoError(t, repo.CreateOrUpdate(ctx, createParams...))
|
|
createdTribes, err := repo.List(ctx, listParams)
|
|
assert.NoError(t, err)
|
|
assertCreatedTribes(t, createParams, createdTribes)
|
|
|
|
assert.NoError(t, repo.CreateOrUpdate(ctx, updateParams...))
|
|
updatedTribes, err := repo.List(ctx, listParams)
|
|
assert.NoError(t, err)
|
|
assertCreatedTribes(t, updateParams, updatedTribes)
|
|
})
|
|
|
|
t.Run("OK: len(params) == 0", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.NoError(t, repo.CreateOrUpdate(context.Background()))
|
|
})
|
|
|
|
t.Run("ERR: server must exist", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := repo.CreateOrUpdate(context.Background(), domain.CreateTribeParams{
|
|
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,
|
|
ServerKey: "pl999",
|
|
})
|
|
var pgErr pgdriver.Error
|
|
assert.ErrorAs(t, err, &pgErr)
|
|
assert.Equal(t, pgerrcode.ForeignKeyViolation, pgErr.Field('C'))
|
|
assert.Equal(t, "tribes_server_key_fkey", pgErr.Field('n'))
|
|
})
|
|
}
|
|
|
|
func TestTribe_Delete(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if testing.Short() {
|
|
t.Skip("skipping long-running test")
|
|
}
|
|
|
|
db := bundbtest.NewDB(t)
|
|
fixture := loadFixtures(t, db)
|
|
repo := bundb.NewTribe(db)
|
|
|
|
t.Run("OK", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tribeCSA := fixture.Tribe(t, "pl169-csa")
|
|
require.Zero(t, tribeCSA.DeletedAt)
|
|
tribeCSAJR := fixture.Tribe(t, "pl169-csa-jr")
|
|
require.Zero(t, tribeCSAJR.DeletedAt)
|
|
|
|
assert.NoError(t, repo.Delete(context.Background(), "pl169", tribeCSA.ID, tribeCSAJR.ID))
|
|
tribes, err := repo.List(context.Background(), domain.ListTribesParams{
|
|
IDs: []int64{tribeCSA.ID, tribeCSAJR.ID},
|
|
ServerKeys: []string{tribeCSA.ServerKey},
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, tribes, 2)
|
|
for _, tribe := range tribes {
|
|
assert.WithinDuration(t, time.Now(), tribe.DeletedAt, 1*time.Second)
|
|
}
|
|
})
|
|
|
|
t.Run("OK: len(ids) == 0", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.NoError(t, repo.Delete(context.Background(), "pl169"))
|
|
})
|
|
}
|
|
|
|
func TestTribe_List_ListCount(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if testing.Short() {
|
|
t.Skip("skipping long-running test")
|
|
}
|
|
|
|
db := bundbtest.NewDB(t)
|
|
fixture := loadFixtures(t, db)
|
|
repo := bundb.NewTribe(db)
|
|
tribes := fixture.Tribes(t)
|
|
|
|
type expectedTribe struct {
|
|
id int64
|
|
serverKey string
|
|
}
|
|
|
|
allTribes := make([]expectedTribe, 0, len(tribes))
|
|
for _, tribe := range tribes {
|
|
allTribes = append(allTribes, expectedTribe{
|
|
id: tribe.ID,
|
|
serverKey: tribe.ServerKey,
|
|
})
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
params domain.ListTribesParams
|
|
expectedTribes []expectedTribe
|
|
expectedCount int64
|
|
expectedErr error
|
|
}{
|
|
{
|
|
name: "Empty struct",
|
|
params: domain.ListTribesParams{},
|
|
expectedTribes: allTribes,
|
|
expectedCount: int64(len(allTribes)),
|
|
},
|
|
{
|
|
name: "IDs=[30, 31]",
|
|
params: domain.ListTribesParams{IDs: []int64{30, 31}},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 30,
|
|
serverKey: "it70",
|
|
},
|
|
{
|
|
id: 31,
|
|
serverKey: "it70",
|
|
},
|
|
},
|
|
expectedCount: 2,
|
|
},
|
|
{
|
|
name: "IDs=[1]",
|
|
params: domain.ListTribesParams{IDs: []int64{1}},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 1,
|
|
serverKey: "pl169",
|
|
},
|
|
{
|
|
id: 1,
|
|
serverKey: "it70",
|
|
},
|
|
},
|
|
expectedCount: 2,
|
|
},
|
|
{
|
|
name: "IDs=[1],ServerKeys=[pl169]",
|
|
params: domain.ListTribesParams{IDs: []int64{1}, ServerKeys: []string{"pl169"}},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 1,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 1,
|
|
},
|
|
{
|
|
name: "Tags=[CSA.,KUZYNI],ServerKeys=[pl169]",
|
|
params: domain.ListTribesParams{
|
|
Tags: []string{"CSA.", "KUZYNI"},
|
|
ServerKeys: []string{"pl169"},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 28,
|
|
serverKey: "pl169",
|
|
},
|
|
{
|
|
id: 27,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 2,
|
|
},
|
|
{
|
|
name: "Deleted=true,ServerKeys=[en113]",
|
|
params: domain.ListTribesParams{
|
|
Deleted: domain.NullBool{Bool: true, Valid: true},
|
|
ServerKeys: []string{"en113"},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 1337,
|
|
serverKey: "en113",
|
|
},
|
|
{
|
|
id: 1115,
|
|
serverKey: "en113",
|
|
},
|
|
},
|
|
expectedCount: 2,
|
|
},
|
|
{
|
|
name: "ServerKeys=[pl169],IDs=[1,2,27,28],IDGT=2",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"pl169"},
|
|
IDs: []int64{1, 2, 27, 28},
|
|
IDGT: domain.NullInt64{
|
|
Int64: 2,
|
|
Valid: true,
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 27,
|
|
serverKey: "pl169",
|
|
},
|
|
{
|
|
id: 28,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 2,
|
|
},
|
|
{
|
|
name: "ServerKeys=[en113],Deleted=false,IDs=[1115,1337,2544]",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"en113"},
|
|
IDs: []int64{1115, 1337, 2544},
|
|
Deleted: domain.NullBool{Valid: true, Bool: false},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 2544,
|
|
serverKey: "en113",
|
|
},
|
|
},
|
|
expectedCount: 1,
|
|
},
|
|
{
|
|
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=ID,Direction=DESC}],Offset=1",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"pl169"},
|
|
IDs: []int64{1, 2, 27, 28},
|
|
Pagination: domain.Pagination{
|
|
Offset: 1,
|
|
},
|
|
Sort: []domain.TribeSort{
|
|
{By: domain.TribeSortByID, Direction: domain.SortDirectionDESC},
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 1,
|
|
serverKey: "pl169",
|
|
},
|
|
{
|
|
id: 2,
|
|
serverKey: "pl169",
|
|
},
|
|
{
|
|
id: 27,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 4,
|
|
},
|
|
{
|
|
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=ID,Direction=ASC}],Offset=2,Limit=1",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"pl169"},
|
|
IDs: []int64{1, 2, 27, 28},
|
|
Pagination: domain.Pagination{
|
|
Offset: 2,
|
|
Limit: 1,
|
|
},
|
|
Sort: []domain.TribeSort{
|
|
{By: domain.TribeSortByID, Direction: domain.SortDirectionASC},
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 27,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 4,
|
|
},
|
|
{
|
|
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=Points,Direction=ASC}],Limit=1",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"pl169"},
|
|
IDs: []int64{1, 2, 27, 28},
|
|
Pagination: domain.Pagination{
|
|
Limit: 1,
|
|
},
|
|
Sort: []domain.TribeSort{
|
|
{
|
|
By: domain.TribeSortByPoints,
|
|
Direction: domain.SortDirectionASC,
|
|
},
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 1,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 4,
|
|
},
|
|
{
|
|
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=ScoreAtt,Direction=DESC}],Limit=1,Offset=1",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"pl169"},
|
|
IDs: []int64{1, 2, 27, 28},
|
|
Pagination: domain.Pagination{
|
|
Limit: 1,
|
|
Offset: 1,
|
|
},
|
|
Sort: []domain.TribeSort{
|
|
{
|
|
By: domain.TribeSortByScoreAtt,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 27,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 4,
|
|
},
|
|
{
|
|
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=ScoreDef,Direction=DESC}],Limit=1",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"pl169"},
|
|
IDs: []int64{1, 2, 27, 28},
|
|
Pagination: domain.Pagination{
|
|
Limit: 1,
|
|
},
|
|
Sort: []domain.TribeSort{
|
|
{
|
|
By: domain.TribeSortByScoreDef,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 1,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 4,
|
|
},
|
|
{
|
|
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=ScoreTotal,Direction=DESC}],Limit=1",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"pl169"},
|
|
IDs: []int64{1, 2, 27, 28},
|
|
Pagination: domain.Pagination{
|
|
Limit: 1,
|
|
},
|
|
Sort: []domain.TribeSort{
|
|
{
|
|
By: domain.TribeSortByScoreTotal,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 1,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 4,
|
|
},
|
|
{
|
|
name: "ServerKeys=[pl169],IDs=[1,2,27,28],Sort=[{By=Dominance,Direction=DESC}],Limit=1,Offset=1",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"pl169"},
|
|
IDs: []int64{1, 2, 27, 28},
|
|
Pagination: domain.Pagination{
|
|
Limit: 1,
|
|
Offset: 1,
|
|
},
|
|
Sort: []domain.TribeSort{
|
|
{
|
|
By: domain.TribeSortByDominance,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 2,
|
|
serverKey: "pl169",
|
|
},
|
|
},
|
|
expectedCount: 4,
|
|
},
|
|
{
|
|
name: "ServerKeys=[en113],Deleted=true,IDs=[1115,1337,2544],Sort=[{By=DeletedAt,Direction=DESC}],Limit=1,Offset=1",
|
|
params: domain.ListTribesParams{
|
|
ServerKeys: []string{"en113"},
|
|
IDs: []int64{1115, 1337, 2544},
|
|
Deleted: domain.NullBool{Valid: true, Bool: true},
|
|
Pagination: domain.Pagination{
|
|
Limit: 1,
|
|
Offset: 1,
|
|
},
|
|
Sort: []domain.TribeSort{
|
|
{
|
|
By: domain.TribeSortByDeletedAt,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
},
|
|
expectedTribes: []expectedTribe{
|
|
{
|
|
id: 1337,
|
|
serverKey: "en113",
|
|
},
|
|
},
|
|
expectedCount: 2,
|
|
},
|
|
{
|
|
name: "ERR: unsupported sort by",
|
|
params: domain.ListTribesParams{
|
|
Sort: []domain.TribeSort{
|
|
{By: 100, Direction: domain.SortDirectionDESC},
|
|
},
|
|
},
|
|
expectedTribes: nil,
|
|
expectedCount: 0,
|
|
expectedErr: domain.ErrUnsupportedSortBy,
|
|
},
|
|
{
|
|
name: "ERR: unsupported sort direction",
|
|
params: domain.ListTribesParams{
|
|
Sort: []domain.TribeSort{
|
|
{By: domain.TribeSortByScoreAtt, Direction: 100},
|
|
},
|
|
},
|
|
expectedTribes: nil,
|
|
expectedCount: 0,
|
|
expectedErr: domain.ErrUnsupportedSortDirection,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
resListCount, count, err := repo.ListCount(context.Background(), tt.params)
|
|
assert.ErrorIs(t, err, tt.expectedErr)
|
|
assert.Equal(t, tt.expectedCount, count)
|
|
assert.Len(t, resListCount, len(tt.expectedTribes))
|
|
for _, expTribe := range tt.expectedTribes {
|
|
found := false
|
|
for _, tribe := range resListCount {
|
|
if tribe.ID == expTribe.id && tribe.ServerKey == expTribe.serverKey {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found, "tribe (id=%d,serverkey=%s) not found", expTribe.id, expTribe.serverKey)
|
|
}
|
|
|
|
resList, err := repo.List(context.Background(), tt.params)
|
|
assert.ErrorIs(t, err, tt.expectedErr)
|
|
assert.Equal(t, resListCount, resList)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestTribe_UpdateDominance(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if testing.Short() {
|
|
t.Skip("skipping long-running test")
|
|
}
|
|
|
|
db := bundbtest.NewDB(t)
|
|
fixture := loadFixtures(t, db)
|
|
repo := bundb.NewTribe(db)
|
|
serverDE188 := fixture.Server(t, "de188")
|
|
serverPL169 := fixture.Server(t, "pl169")
|
|
|
|
tests := []struct {
|
|
name string
|
|
serverKey string
|
|
numPlayerVillages int64
|
|
}{
|
|
{
|
|
name: "numPlayerVillages=0",
|
|
serverKey: serverDE188.Key,
|
|
numPlayerVillages: 0,
|
|
},
|
|
{
|
|
name: "numPlayerVillages=35000",
|
|
serverKey: serverPL169.Key,
|
|
numPlayerVillages: 35000,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
require.NoError(t, repo.UpdateDominance(context.Background(), tt.serverKey, tt.numPlayerVillages))
|
|
tribes, err := repo.List(
|
|
context.Background(),
|
|
domain.ListTribesParams{ServerKeys: []string{tt.serverKey}},
|
|
)
|
|
assert.NoError(t, err)
|
|
assert.Greater(t, len(tribes), 0)
|
|
for _, tribe := range tribes {
|
|
if tt.numPlayerVillages == 0 {
|
|
assert.Equal(t, 0.0, tribe.Dominance)
|
|
continue
|
|
}
|
|
assert.Equal(t, float64(tribe.NumVillages)/float64(tt.numPlayerVillages)*100, tribe.Dominance)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func assertCreatedTribes(tb testing.TB, params []domain.CreateTribeParams, tribes []domain.Tribe) {
|
|
tb.Helper()
|
|
|
|
assert.Len(tb, tribes, len(params))
|
|
for _, p := range params {
|
|
var tribe domain.Tribe
|
|
for _, t := range tribes {
|
|
if t.ID == p.ID && t.ServerKey == p.ServerKey {
|
|
tribe = t
|
|
break
|
|
}
|
|
}
|
|
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.WithinDuration(tb, p.BestRankAt, tribe.BestRankAt, time.Second)
|
|
assert.Equal(tb, p.MostPoints, tribe.MostPoints)
|
|
assert.WithinDuration(tb, p.MostPointsAt, tribe.MostPointsAt, time.Second)
|
|
assert.Equal(tb, p.MostVillages, tribe.MostVillages)
|
|
assert.WithinDuration(tb, p.MostVillagesAt, tribe.MostVillagesAt, time.Second)
|
|
assert.Equal(tb, p.ServerKey, tribe.ServerKey)
|
|
assert.Equal(tb, 0.0, tribe.Dominance)
|
|
assert.Zero(tb, tribe.DeletedAt)
|
|
assert.WithinDuration(tb, tribe.CreatedAt, time.Now(), 1*time.Second)
|
|
}
|
|
}
|