Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

usageBreakdown.test.ts

31 lines891 Bytes

1import type { ModelTotals } from "@t3tools/shared/usageMerge";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { sortModelsByTokens } from "./usageBreakdown";
5​
6const model = (name: string, totalTokens: number, costUsd: number): ModelTotals => ({
7 model: name,
8 provider: "codex",
9 costUsd,
10 totalTokens,
11 records: 1,
12 unpricedRecords: 0,
13 costShare: 0,
14});
15​
16describe("sortModelsByTokens", () => {
17 it("sorts by tokens, breaks ties by cost, and leaves the input alone", () => {
18 const models = [
19 model("lower-cost", 100, 1),
20 model("more-tokens", 200, 2),
21 model("higher-cost", 100, 3),
22 ];
23​
24 expect(sortModelsByTokens(models).map((item) => item.model)).toEqual([
25 "more-tokens",
26 "higher-cost",
27 "lower-cost",
28 ]);
29 expect(models.map((item) => item.model)).toEqual(["lower-cost", "more-tokens", "higher-cost"]);
30 });
31});