A currying function chain: field names, comparator, then direction
// Test single field sorting with GaffComparator
const sortValidator = TestValidator.sort(
"article sorting",
(sortable) => api.getArticles({ sort: sortable })
)("created_at")(
GaffComparator.dates((a) => a.created_at)
);
await sortValidator("+"); // ascending
await sortValidator("-"); // descending
// Test multi-field sorting with GaffComparator
const userSortValidator = TestValidator.sort(
"user sorting",
(sortable) => api.getUsers({ sort: sortable })
)("lastName", "firstName")(
GaffComparator.strings((user) => [user.lastName, user.firstName]),
(user) => user.isActive // only test active users
);
await userSortValidator("+", true); // ascending with trace logging
// Custom comparator for complex logic
const customSortValidator = TestValidator.sort(
"custom sorting",
(sortable) => api.getProducts({ sort: sortable })
)("price", "rating")(
(a, b) => {
const priceDiff = a.price - b.price;
return priceDiff !== 0 ? priceDiff : b.rating - a.rating; // price asc, rating desc
}
);
Validates sorting functionality of pagination APIs.
Tests sorting operations by calling the API with sort parameters and validating that results are correctly ordered. Supports multiple fields, ascending/descending order, and optional filtering. Provides detailed error reporting for sorting failures.