Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib/bounty-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
filterBounties,
isFilterActive,
parseBountyQuery,
SORT_LABELS,
} from "./bounty-query";
import type { Bounty } from "@/types";

Expand Down Expand Up @@ -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 }),
Expand Down
10 changes: 9 additions & 1 deletion src/lib/bounty-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SortOption, string> = {
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",
Expand Down