Dawid Wysokiński
4e44a25acb
All checks were successful
continuous-integration/drone/push Build is passing
111 lines
2.2 KiB
Go
111 lines
2.2 KiB
Go
package domain_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewPlayerSort(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
by string
|
|
dir string
|
|
output domain.PlayerSort
|
|
expectedErr error
|
|
}{
|
|
{
|
|
by: "id",
|
|
dir: "asc",
|
|
output: domain.PlayerSort{
|
|
By: domain.PlayerSortByID,
|
|
Direction: domain.SortDirectionASC,
|
|
},
|
|
},
|
|
{
|
|
by: "scoreAtt",
|
|
dir: "desc",
|
|
output: domain.PlayerSort{
|
|
By: domain.PlayerSortByScoreAtt,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
{
|
|
by: "scoreDef",
|
|
dir: "desc",
|
|
output: domain.PlayerSort{
|
|
By: domain.PlayerSortByScoreDef,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
{
|
|
by: "scoreSup",
|
|
dir: "asc",
|
|
output: domain.PlayerSort{
|
|
By: domain.PlayerSortByScoreSup,
|
|
Direction: domain.SortDirectionASC,
|
|
},
|
|
},
|
|
{
|
|
by: "scoreTotal",
|
|
dir: "asc",
|
|
output: domain.PlayerSort{
|
|
By: domain.PlayerSortByScoreTotal,
|
|
Direction: domain.SortDirectionASC,
|
|
},
|
|
},
|
|
{
|
|
by: "points",
|
|
dir: "desc",
|
|
output: domain.PlayerSort{
|
|
By: domain.PlayerSortByPoints,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
{
|
|
by: "deletedAt",
|
|
dir: "asc",
|
|
output: domain.PlayerSort{
|
|
By: domain.PlayerSortByDeletedAt,
|
|
Direction: domain.SortDirectionASC,
|
|
},
|
|
},
|
|
{
|
|
by: "unsupported",
|
|
dir: "asc",
|
|
expectedErr: domain.ErrUnsupportedSortBy,
|
|
},
|
|
{
|
|
by: "deletedAt",
|
|
dir: "unsupported",
|
|
expectedErr: domain.ErrUnsupportedSortDirection,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
|
|
t.Run(tt.by+":"+tt.dir, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
res, err := domain.NewPlayerSort(tt.by, tt.dir)
|
|
assert.ErrorIs(t, err, tt.expectedErr)
|
|
assert.Equal(t, tt.output, res)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPlayerNotFoundError(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := domain.PlayerNotFoundError{
|
|
ID: 1234,
|
|
}
|
|
var _ domain.Error = err
|
|
assert.Equal(t, "player (id=1234) not found", err.Error())
|
|
assert.Equal(t, err.Error(), err.UserError())
|
|
assert.Equal(t, domain.ErrorCodeEntityNotFound, err.Code())
|
|
}
|