feat: initial release v0.3.0
This commit is contained in:
23
tests/helpers/assertions.ts
Normal file
23
tests/helpers/assertions.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { expect } from 'vitest'
|
||||
import { prisma } from './prisma'
|
||||
import { toMoneyNumber } from '@/lib/billing/money'
|
||||
|
||||
export async function expectBalance(userId: string, params: {
|
||||
balance: number
|
||||
frozenAmount: number
|
||||
totalSpent: number
|
||||
}) {
|
||||
const row = await prisma.userBalance.findUnique({ where: { userId } })
|
||||
expect(row).toBeTruthy()
|
||||
expect(toMoneyNumber(row!.balance)).toBeCloseTo(params.balance, 8)
|
||||
expect(toMoneyNumber(row!.frozenAmount)).toBeCloseTo(params.frozenAmount, 8)
|
||||
expect(toMoneyNumber(row!.totalSpent)).toBeCloseTo(params.totalSpent, 8)
|
||||
}
|
||||
|
||||
export async function expectNoNegativeLedger(userId: string) {
|
||||
const row = await prisma.userBalance.findUnique({ where: { userId } })
|
||||
expect(row).toBeTruthy()
|
||||
expect(toMoneyNumber(row!.balance)).toBeGreaterThanOrEqual(0)
|
||||
expect(toMoneyNumber(row!.frozenAmount)).toBeGreaterThanOrEqual(0)
|
||||
expect(toMoneyNumber(row!.totalSpent)).toBeGreaterThanOrEqual(0)
|
||||
}
|
||||
Reference in New Issue
Block a user