Dawid Wysokiński
4e44a25acb
All checks were successful
continuous-integration/drone/push Build is passing
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package domain_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewEnnoblementSort(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
by string
|
|
dir string
|
|
output domain.EnnoblementSort
|
|
expectedErr error
|
|
}{
|
|
{
|
|
by: "createdAt",
|
|
dir: "asc",
|
|
output: domain.EnnoblementSort{
|
|
By: domain.EnnoblementSortByCreatedAt,
|
|
Direction: domain.SortDirectionASC,
|
|
},
|
|
},
|
|
{
|
|
by: "createdAt",
|
|
dir: "desc",
|
|
output: domain.EnnoblementSort{
|
|
By: domain.EnnoblementSortByCreatedAt,
|
|
Direction: domain.SortDirectionDESC,
|
|
},
|
|
},
|
|
{
|
|
by: "unsupported",
|
|
dir: "asc",
|
|
expectedErr: domain.ErrUnsupportedSortBy,
|
|
},
|
|
{
|
|
by: "createdAt",
|
|
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.NewEnnoblementSort(tt.by, tt.dir)
|
|
assert.ErrorIs(t, err, tt.expectedErr)
|
|
assert.Equal(t, tt.output, res)
|
|
})
|
|
}
|
|
}
|