Dawid Wysokiński
75aba22cf8
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#149
154 lines
3.1 KiB
Go
154 lines
3.1 KiB
Go
package domain_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
|
)
|
|
|
|
func TestUpdateServerParams_IsZero(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
params domain.UpdateServerParams
|
|
output bool
|
|
}{
|
|
{
|
|
name: "OK: Config",
|
|
params: domain.UpdateServerParams{
|
|
Config: domain.NullServerConfig{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: BuildingInfo",
|
|
params: domain.UpdateServerParams{
|
|
BuildingInfo: domain.NullBuildingInfo{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: UnitInfo",
|
|
params: domain.UpdateServerParams{
|
|
UnitInfo: domain.NullUnitInfo{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: NumPlayers",
|
|
params: domain.UpdateServerParams{
|
|
NumPlayers: domain.NullInt64{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: PlayerDataUpdatedAt",
|
|
params: domain.UpdateServerParams{
|
|
PlayerDataUpdatedAt: time.Now(),
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: NumTribes",
|
|
params: domain.UpdateServerParams{
|
|
NumTribes: domain.NullInt64{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: TribeDataUpdatedAt",
|
|
params: domain.UpdateServerParams{
|
|
TribeDataUpdatedAt: time.Now(),
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: NumVillages",
|
|
params: domain.UpdateServerParams{
|
|
NumVillages: domain.NullInt64{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: NumPlayerVillages",
|
|
params: domain.UpdateServerParams{
|
|
NumPlayerVillages: domain.NullInt64{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: NumBarbarianVillages",
|
|
params: domain.UpdateServerParams{
|
|
NumBarbarianVillages: domain.NullInt64{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: NumBonusVillages",
|
|
params: domain.UpdateServerParams{
|
|
NumBonusVillages: domain.NullInt64{Valid: true},
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: VillageDataUpdatedAt",
|
|
params: domain.UpdateServerParams{
|
|
VillageDataUpdatedAt: time.Now(),
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: PlayerSnapshotsCreatedAt",
|
|
params: domain.UpdateServerParams{
|
|
PlayerSnapshotsCreatedAt: time.Now(),
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: TribeSnapshotsCreatedAt",
|
|
params: domain.UpdateServerParams{
|
|
TribeSnapshotsCreatedAt: time.Now(),
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: EnnoblementDataUpdatedAt",
|
|
params: domain.UpdateServerParams{
|
|
EnnoblementDataUpdatedAt: time.Now(),
|
|
},
|
|
output: false,
|
|
},
|
|
{
|
|
name: "OK: empty struct",
|
|
params: domain.UpdateServerParams{},
|
|
output: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.Equal(t, tt.output, tt.params.IsZero())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServerNotFoundError(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := domain.ServerNotFoundError{
|
|
Key: "pl151",
|
|
}
|
|
var _ domain.UserError = err
|
|
assert.Equal(t, "server (key=pl151) not found", err.Error())
|
|
assert.Equal(t, err.Error(), err.UserError())
|
|
assert.Equal(t, domain.ErrorCodeEntityNotFound, err.Code())
|
|
}
|