init push
This commit is contained in:
31
internal/service/sort_helper_test.go
Normal file
31
internal/service/sort_helper_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeSortByRules(t *testing.T) {
|
||||
t.Run("field asc and desc", func(t *testing.T) {
|
||||
if got := normalizeSortByRules("name", sortField("name")); got != "name ASC" {
|
||||
t.Fatalf("unexpected asc sort: %q", got)
|
||||
}
|
||||
if got := normalizeSortByRules("-name", sortField("name")); got != "name DESC" {
|
||||
t.Fatalf("unexpected desc sort: %q", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("alias and custom expression", func(t *testing.T) {
|
||||
got := normalizeSortByRules("sort_order", sortExpr("sort_order ASC, created_at DESC", "sort_order DESC, created_at DESC", "sort_order"))
|
||||
if got != "sort_order ASC, created_at DESC" {
|
||||
t.Fatalf("unexpected custom sort: %q", got)
|
||||
}
|
||||
got = normalizeSortByRules("-hospital_name", sortField("hospital_name", "name", "hospital_name"))
|
||||
if got != "hospital_name DESC" {
|
||||
t.Fatalf("unexpected alias sort: %q", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unknown", func(t *testing.T) {
|
||||
if got := normalizeSortByRules("unknown", sortField("name")); got != "" {
|
||||
t.Fatalf("expected empty for unknown, got %q", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user