Skip to content

Commit 15db692

Browse files
committed
fix tests
1 parent 7b43091 commit 15db692

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

apps/sim/lib/billing/credits/daily-refresh.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ vi.mock('@sim/db/schema', () => ({
2626
},
2727
}))
2828

29+
vi.mock('drizzle-orm', () => {
30+
const sqlTag = () => {
31+
const obj = { as: () => obj }
32+
return obj
33+
}
34+
sqlTag.as = sqlTag
35+
return {
36+
sql: Object.assign(sqlTag, { raw: sqlTag }),
37+
and: vi.fn(),
38+
gte: vi.fn(),
39+
lt: vi.fn(),
40+
inArray: vi.fn(),
41+
sum: () => ({ as: () => 'sum' }),
42+
}
43+
})
44+
2945
vi.mock('@sim/logger', () => loggerMock)
3046
vi.mock('@/lib/billing/constants', () => ({
3147
DAILY_REFRESH_RATE: 0.01,

apps/sim/providers/utils.test.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -769,27 +769,23 @@ describe('Cost Calculation', () => {
769769
})
770770

771771
describe('formatCost', () => {
772-
it.concurrent('should format costs >= $1 with two decimal places', () => {
773-
expect(formatCost(1.234)).toBe('$1.23')
774-
expect(formatCost(10.567)).toBe('$10.57')
772+
it.concurrent('should format dollar amounts as credits', () => {
773+
expect(formatCost(1.234)).toBe('247 credits')
774+
expect(formatCost(10.567)).toBe('2,113 credits')
775775
})
776776

777-
it.concurrent('should format costs between 1¢ and $1 with three decimal places', () => {
778-
expect(formatCost(0.0234)).toBe('$0.023')
779-
expect(formatCost(0.1567)).toBe('$0.157')
777+
it.concurrent('should show <1 credit for very small costs', () => {
778+
expect(formatCost(0.0024)).toBe('<1 credit')
779+
expect(formatCost(0.001)).toBe('<1 credit')
780780
})
781781

782-
it.concurrent('should format costs between 0.1¢ and 1¢ with four decimal places', () => {
783-
expect(formatCost(0.00234)).toBe('$0.0023')
784-
expect(formatCost(0.00567)).toBe('$0.0057')
785-
})
786-
787-
it.concurrent('should format very small costs with appropriate precision', () => {
788-
expect(formatCost(0.000234)).toContain('$0.000234')
782+
it.concurrent('should show credit count for small costs that round to at least 1', () => {
783+
expect(formatCost(0.0234)).toBe('5 credits')
784+
expect(formatCost(0.1567)).toBe('31 credits')
789785
})
790786

791787
it.concurrent('should handle zero cost', () => {
792-
expect(formatCost(0)).toBe('$0')
788+
expect(formatCost(0)).toBe('0 credits')
793789
})
794790

795791
it.concurrent('should handle undefined/null costs', () => {

0 commit comments

Comments
 (0)