This repository has been archived on 2024-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
core-old/internal/domain/ennoblement_test.go
Dawid Wysokiński 4e44a25acb
All checks were successful
continuous-integration/drone/push Build is passing
refactor: sorts - new constructors
2023-01-13 06:28:44 +01:00

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)
})
}
}