Documentation
    Preparing search index...
    • 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.

      Type Parameters

      Parameters

      • title: string

        Descriptive title used in error messages when sorting fails

      • getter: (sortable: Sortable) => Promise<T[]>

        API function that fetches sorted data

      Returns (
          ...fields: Fields[],
      ) => (
          comp: (x: T, y: T) => number,
          filter?: (elem: T) => boolean,
      ) => (direction: "+" | "-", trace?: boolean) => Promise<void>

      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
      }
      );

      Error when API results are not properly sorted according to specification