package roomadmin

import "testing"

func TestNormalizeRoomListSortKeepsOnlyContributionSort(t *testing.T) {
	tests := []struct {
		name      string
		query     listQuery
		wantOrder string
	}{
		{
			name:      "default",
			query:     listQuery{},
			wantOrder: "rle.created_at_ms DESC, rle.room_id DESC",
		},
		{
			name:      "contribution_desc",
			query:     listQuery{SortBy: "room_contribution", SortDirection: "desc"},
			wantOrder: "rle.heat DESC, rle.created_at_ms DESC, rle.room_id DESC",
		},
		{
			name:      "contribution_asc",
			query:     listQuery{SortBy: "heat", SortDirection: "asc"},
			wantOrder: "rle.heat ASC, rle.created_at_ms DESC, rle.room_id DESC",
		},
		{
			name:      "unknown_falls_back",
			query:     listQuery{SortBy: "owner_user_id", SortDirection: "asc"},
			wantOrder: "rle.created_at_ms DESC, rle.room_id DESC",
		},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			query := normalizeListQuery(test.query)
			if got := roomListOrderBy(query); got != test.wantOrder {
				t.Fatalf("order by mismatch: got %q want %q", got, test.wantOrder)
			}
		})
	}
}
