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/tribe_change_test.go
2023-01-15 08:11:02 +00: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 TestNewTribeChangeSort(t *testing.T) {
t.Parallel()
tests := []struct {
by string
dir string
output domain.TribeChangeSort
expectedErr error
}{
{
by: "id",
dir: "desc",
output: domain.TribeChangeSort{
By: domain.TribeChangeSortByID,
Direction: domain.SortDirectionDESC,
},
},
{
by: "createdAt",
dir: "asc",
output: domain.TribeChangeSort{
By: domain.TribeChangeSortByCreatedAt,
Direction: domain.SortDirectionASC,
},
},
{
by: "unsupported",
dir: "asc",
expectedErr: domain.ErrUnsupportedSortBy,
},
{
by: "id",
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.NewTribeChangeSort(tt.by, tt.dir)
assert.ErrorIs(t, err, tt.expectedErr)
assert.Equal(t, tt.output, res)
})
}
}