24 lines
883 B
TypeScript
24 lines
883 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { sortDetailBreakdown } from "./detail-sort";
|
|
|
|
describe("sortDetailBreakdown", () => {
|
|
const rows = [
|
|
{ name: "beta", calls: 2, total_tokens: 100, quota: 500 },
|
|
{ name: "alpha", calls: 5, total_tokens: 100, quota: 300 },
|
|
{ name: "gamma", calls: 1, total_tokens: 300, quota: 100 },
|
|
];
|
|
|
|
test("sorts by the selected numeric field without mutating the source rows", () => {
|
|
const sorted = sortDetailBreakdown(rows, "quota", false);
|
|
|
|
expect(sorted.map((row) => row.name)).toEqual(["beta", "alpha", "gamma"]);
|
|
expect(rows.map((row) => row.name)).toEqual(["beta", "alpha", "gamma"]);
|
|
});
|
|
|
|
test("uses name as a stable tie-breaker", () => {
|
|
const sorted = sortDetailBreakdown(rows, "total_tokens", false);
|
|
|
|
expect(sorted.map((row) => row.name)).toEqual(["gamma", "alpha", "beta"]);
|
|
});
|
|
});
|