Skip to content

Commit dd6d37e

Browse files
committed
fix: update cost tests to match new calculateApiCost signature
Both calculateApiCostAnthropic and calculateApiCostOpenAI now return a number directly (the total cost) instead of an object with totalCost, totalInputTokens, and totalOutputTokens properties.
1 parent 1c1ed4e commit dd6d37e

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

src/utils/__tests__/cost.spec.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ describe("Cost Utility", () => {
131131
// Input cost: (3.0 / 1_000_000) * 1000 = 0.003
132132
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
133133
// Total: 0.003 + 0.0075 = 0.0105
134-
expect(result.totalCost).toBe(0.0105)
135-
expect(result.totalInputTokens).toBe(1000)
136-
expect(result.totalOutputTokens).toBe(500)
134+
expect(result).toBe(0.0105)
137135
})
138136

139137
it("should handle cache writes cost", () => {
@@ -143,9 +141,7 @@ describe("Cost Utility", () => {
143141
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
144142
// Cache writes: (3.75 / 1_000_000) * 2000 = 0.0075
145143
// Total: 0.003 + 0.0075 + 0.0075 = 0.018
146-
expect(result.totalCost).toBeCloseTo(0.018, 6)
147-
expect(result.totalInputTokens).toBe(3000) // Total already includes cache
148-
expect(result.totalOutputTokens).toBe(500)
144+
expect(result).toBeCloseTo(0.018, 6)
149145
})
150146

151147
it("should handle cache reads cost", () => {
@@ -155,9 +151,7 @@ describe("Cost Utility", () => {
155151
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
156152
// Cache reads: (0.3 / 1_000_000) * 3000 = 0.0009
157153
// Total: 0.003 + 0.0075 + 0.0009 = 0.0114
158-
expect(result.totalCost).toBe(0.0114)
159-
expect(result.totalInputTokens).toBe(4000) // Total already includes cache
160-
expect(result.totalOutputTokens).toBe(500)
154+
expect(result).toBe(0.0114)
161155
})
162156

163157
it("should handle all cost components together", () => {
@@ -168,9 +162,7 @@ describe("Cost Utility", () => {
168162
// Cache writes: (3.75 / 1_000_000) * 2000 = 0.0075
169163
// Cache reads: (0.3 / 1_000_000) * 3000 = 0.0009
170164
// Total: 0.003 + 0.0075 + 0.0075 + 0.0009 = 0.0189
171-
expect(result.totalCost).toBe(0.0189)
172-
expect(result.totalInputTokens).toBe(6000) // Total already includes cache
173-
expect(result.totalOutputTokens).toBe(500)
165+
expect(result).toBe(0.0189)
174166
})
175167

176168
it("should handle missing prices gracefully", () => {
@@ -181,16 +173,12 @@ describe("Cost Utility", () => {
181173
}
182174

183175
const result = calculateApiCostOpenAI(modelWithoutPrices, 1000, 500, 2000, 3000)
184-
expect(result.totalCost).toBe(0)
185-
expect(result.totalInputTokens).toBe(1000) // Total already includes cache
186-
expect(result.totalOutputTokens).toBe(500)
176+
expect(result).toBe(0)
187177
})
188178

189179
it("should handle zero tokens", () => {
190180
const result = calculateApiCostOpenAI(mockModelInfo, 0, 0, 0, 0)
191-
expect(result.totalCost).toBe(0)
192-
expect(result.totalInputTokens).toBe(0)
193-
expect(result.totalOutputTokens).toBe(0)
181+
expect(result).toBe(0)
194182
})
195183

196184
it("should handle undefined cache values", () => {
@@ -199,9 +187,7 @@ describe("Cost Utility", () => {
199187
// Input cost: (3.0 / 1_000_000) * 1000 = 0.003
200188
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
201189
// Total: 0.003 + 0.0075 = 0.0105
202-
expect(result.totalCost).toBe(0.0105)
203-
expect(result.totalInputTokens).toBe(1000)
204-
expect(result.totalOutputTokens).toBe(500)
190+
expect(result).toBe(0.0105)
205191
})
206192

207193
it("should handle missing cache prices", () => {
@@ -217,9 +203,7 @@ describe("Cost Utility", () => {
217203
// Input cost: (3.0 / 1_000_000) * (6000 - 2000 - 3000) = 0.003
218204
// Output cost: (15.0 / 1_000_000) * 500 = 0.0075
219205
// Total: 0.003 + 0.0075 = 0.0105
220-
expect(result.totalCost).toBe(0.0105)
221-
expect(result.totalInputTokens).toBe(6000) // Total already includes cache
222-
expect(result.totalOutputTokens).toBe(500)
206+
expect(result).toBe(0.0105)
223207
})
224208
})
225209
})

0 commit comments

Comments
 (0)