// Test article pagination
const expectedArticles = await db.articles.findAll({
order: "created_at DESC",
});
const actualArticles = await api.functional.getArticles({
page: 1,
limit: 10,
});
TestValidator.index(
"article pagination order",
expectedArticles,
actualArticles,
true, // enable trace logging
);
// Test user search results
const manuallyFilteredUsers = allUsers.filter((u) =>
u.name.includes("John"),
);
const apiSearchResults = await api.functional.searchUsers({
query: "John",
});
TestValidator.index(
"user search results",
manuallyFilteredUsers,
apiSearchResults,
);
Error when entity order differs between expected and actual results over their common prefix, or when exactly one of them is empty
contracts/common.md#principled-implementation A page holds the first entities of the expected list, so the two id lists are compared over their common prefix, and one side being empty while the other is not is a difference because there is no prefix to compare; ids are compared as strings.
contracts/common.md#clear-and-simple-design One function over the id lists produced by a private helper, with an optional trace flag.
Validates pagination index API results against expected entity order.
Compares the order of entities returned by a pagination API with manually sorted expected results. Validates that entity IDs appear in the correct sequence. Commonly used for testing database queries, search results, and any paginated data APIs.
A page holds the first entities, so only the common prefix of the two lists is compared. An empty result against expected entities, or the reverse, fails.
Processing cost: Only the common prefix of P entities is sliced, converted to id strings and compared, giving O(P) entries and temporary storage; string conversion and comparison add their text costs.