Dawid Wysokiński
8b4823fb28
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#118
94 lines
2.4 KiB
Go
94 lines
2.4 KiB
Go
package service_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
|
"gitea.dwysokinski.me/twhelp/core/internal/service"
|
|
"gitea.dwysokinski.me/twhelp/core/internal/service/internal/mock"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTribeSnapshot_Create(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tribeSvc := &mock.FakeTribeLister{}
|
|
tribes := []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(),
|
|
},
|
|
{
|
|
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: "pl151",
|
|
Dominance: 12.55,
|
|
CreatedAt: time.Now().Add(-5000 * time.Hour),
|
|
DeletedAt: time.Now(),
|
|
},
|
|
}
|
|
tribeSvc.ListReturns(tribes, 0, nil)
|
|
|
|
repo := &mock.FakeTribeSnapshotRepository{}
|
|
repo.CreateReturns(nil)
|
|
|
|
date := time.Now()
|
|
assert.NoError(t, service.NewTribeSnapshot(repo, tribeSvc).Create(context.Background(), "pl151", date))
|
|
|
|
require.Equal(t, 1, repo.CreateCallCount())
|
|
_, params := repo.CreateArgsForCall(0)
|
|
assert.Len(t, params, len(tribes))
|
|
for i, tribe := range tribes {
|
|
assert.Equal(t, tribe.OpponentsDefeated, params[i].OpponentsDefeated)
|
|
assert.Equal(t, tribe.ID, params[i].TribeID)
|
|
assert.Equal(t, tribe.NumVillages, params[i].NumVillages)
|
|
assert.Equal(t, tribe.NumMembers, params[i].NumMembers)
|
|
assert.Equal(t, tribe.Points, params[i].Points)
|
|
assert.Equal(t, tribe.AllPoints, params[i].AllPoints)
|
|
assert.Equal(t, tribe.Rank, params[i].Rank)
|
|
assert.Equal(t, tribe.Dominance, params[i].Dominance)
|
|
assert.Equal(t, tribe.ServerKey, params[i].ServerKey)
|
|
assert.Equal(t, date, params[i].Date)
|
|
}
|
|
}
|