package admin

import "testing"

func TestBuildUserOrderBy(t *testing.T) {
	tests := []struct {
		sort string
		want string
	}{
		{"", "ORDER BY created_at DESC"},
		{"-email", "ORDER BY LOWER(email) DESC"},
		{"name", "ORDER BY LOWER(name) ASC"},
		{"invalid", "ORDER BY created_at DESC"},
	}
	for _, tt := range tests {
		if got := buildUserOrderBy(tt.sort); got != tt.want {
			t.Fatalf("buildUserOrderBy(%q) = %q, want %q", tt.sort, got, tt.want)
		}
	}
}

func TestParseSortField(t *testing.T) {
	field, desc := parseSortField("-created_at")
	if field != "created_at" || !desc {
		t.Fatalf("parseSortField = %q %v", field, desc)
	}
	field, desc = parseSortField("email")
	if field != "email" || desc {
		t.Fatalf("parseSortField = %q %v", field, desc)
	}
}
