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/snapshot_test.go
Dawid Wysokiński c6be9a6012
All checks were successful
continuous-integration/drone/push Build is passing
feat: new rest endpoint - /versions/{code}/servers/{key}/tribes/{id}/history (#180)
Reviewed-on: twhelp/core#180
2023-02-08 05:50:54 +00:00

109 lines
2.1 KiB
Go

package domain_test
import (
"testing"
"gitea.dwysokinski.me/twhelp/core/internal/domain"
"github.com/stretchr/testify/assert"
)
func TestNewPlayerSnapshotSort(t *testing.T) {
t.Parallel()
tests := []struct {
by string
dir string
output domain.PlayerSnapshotSort
expectedErr error
}{
{
by: "id",
dir: "desc",
output: domain.PlayerSnapshotSort{
By: domain.PlayerSnapshotSortByID,
Direction: domain.SortDirectionDESC,
},
},
{
by: "date",
dir: "asc",
output: domain.PlayerSnapshotSort{
By: domain.PlayerSnapshotSortByDate,
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.NewPlayerSnapshotSort(tt.by, tt.dir)
assert.ErrorIs(t, err, tt.expectedErr)
assert.Equal(t, tt.output, res)
})
}
}
func TestNewTribeSnapshotSort(t *testing.T) {
t.Parallel()
tests := []struct {
by string
dir string
output domain.TribeSnapshotSort
expectedErr error
}{
{
by: "id",
dir: "desc",
output: domain.TribeSnapshotSort{
By: domain.TribeSnapshotSortByID,
Direction: domain.SortDirectionDESC,
},
},
{
by: "date",
dir: "asc",
output: domain.TribeSnapshotSort{
By: domain.TribeSnapshotSortByDate,
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.NewTribeSnapshotSort(tt.by, tt.dir)
assert.ErrorIs(t, err, tt.expectedErr)
assert.Equal(t, tt.output, res)
})
}
}