diff --git a/src/lib/bounty-query.test.ts b/src/lib/bounty-query.test.ts index 9288c63..eb580e0 100644 --- a/src/lib/bounty-query.test.ts +++ b/src/lib/bounty-query.test.ts @@ -14,6 +14,7 @@ import { filterBounties, isFilterActive, parseBountyQuery, + SORT_LABELS, } from "./bounty-query"; import type { Bounty } from "@/types"; @@ -124,6 +125,15 @@ describe("filterBounties", () => { }); }); +describe("SORT_LABELS", () => { + it("doesn't label the unordered default sort as a real chronological sort (#702)", () => { + // `sortBounties`'s "default" case leaves the array unchanged, and Bounty + // has no createdAt (or equivalent) field to sort by — the label must not + // claim an ordering ("Newest", "Oldest", ...) that doesn't exist. + expect(SORT_LABELS.default.toLowerCase()).not.toMatch(/newest|oldest|recent/); + }); +}); + describe("applyBountyQuery", () => { const bounties = Array.from({ length: 25 }, (_, i) => bounty({ id: `b${i}`, reward: i, deadline: null }), diff --git a/src/lib/bounty-query.ts b/src/lib/bounty-query.ts index 8551bb7..24eff9a 100644 --- a/src/lib/bounty-query.ts +++ b/src/lib/bounty-query.ts @@ -36,7 +36,15 @@ export const SORT_VALUES = ["default", "reward-desc", "reward-asc", "deadline-as export type SortOption = (typeof SORT_VALUES)[number]; export const SORT_LABELS: Record = { - default: "Newest", + // Labelled "Newest" despite sortBounties leaving "default" unordered: there + // is no `createdAt` (or equivalent) field anywhere on `Bounty`, and the + // backend's listing query has no ORDER BY, so order is whatever Postgres's + // heap happens to return and can change between requests (#702). Fixing + // the label alone rather than sorting by a field that doesn't exist on + // this type — introducing one would be guessing at a backend contract this + // repo doesn't control. A real "Newest" sort needs a `createdAt` field + // exposed end-to-end first. + default: "Default order", "reward-desc": "Reward: high to low", "reward-asc": "Reward: low to high", "deadline-asc": "Deadline: soonest",