Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { isUsagePriceEdit, parseUsagePriceForm, usagePriceForm } from "./usagePriceForm.ts";
4
5describe("model price entry", () => {
6 it("keeps free cache tokens distinct from blank cache prices", () => {
7 const parsed = parseUsagePriceForm({
8 ...usagePriceForm(),
9 model: "example-model",
10 inputCostPerMillionTokens: "2",
11 outputCostPerMillionTokens: "8",
12 cacheReadCostPerMillionTokens: "0",
13 cacheWriteCostPerMillionTokens: " ",
14 });
15 expect(parsed?.price).toEqual({
16 inputCostPerMillionTokens: 2,
17 outputCostPerMillionTokens: 8,
18 cacheReadCostPerMillionTokens: 0,
19 });
20 });
21
22 it("preserves all prices when editing, including small fractional prices", () => {
23 const price = {
24 inputCostPerMillionTokens: 0,
25 outputCostPerMillionTokens: 8,
26 cacheReadCostPerMillionTokens: 0.0000001,
27 cacheWriteCostPerMillionTokens: 3.5,
28 };
29 expect(parseUsagePriceForm(usagePriceForm("example-model", price))).toEqual({
30 model: "example-model",
31 price,
32 });
33 });
34
35 it.each(["", " ", "-1", "Infinity", "NaN", "1e999", "$2", "0x10"])(
36 "rejects invalid required prices: %j",
37 (inputCostPerMillionTokens) => {
38 expect(
39 parseUsagePriceForm({
40 ...usagePriceForm("example-model", {
41 inputCostPerMillionTokens: 2,
42 outputCostPerMillionTokens: 8,
43 }),
44 inputCostPerMillionTokens,
45 }),
46 ).toBeNull();
47 },
48 );
49
50 it("never blocks deleting part of a price, but blocks replacing it with a non-number", () => {
51 expect(isUsagePriceEdit("1e-7", "e-7")).toBe(true);
52 expect(isUsagePriceEdit("1e-7", "1-7")).toBe(true);
53 expect(isUsagePriceEdit("1e-7", "a7")).toBe(false);
54 expect(isUsagePriceEdit("2.5", "x")).toBe(false);
55 expect(isUsagePriceEdit("123456", "1.2.3")).toBe(false);
56 });
57});