MCPcopy Create free account
hub / github.com/simstudioai/sim / setupTx

Function setupTx

apps/sim/lib/billing/core/usage-log.test.ts:191–207  ·  view source on GitHub ↗
(existingRow: { id: string; cost: string } | null)

Source from the content-addressed store, hash-verified

189 })
190
191 const setupTx = (existingRow: { id: string; cost: string } | null) => {
192 const limit = vi.fn().mockResolvedValue(existingRow ? [existingRow] : [])
193 const where = vi.fn().mockReturnValue({ limit })
194 const from = vi.fn().mockReturnValue({ where })
195 const select = vi.fn().mockReturnValue({ from })
196 const updateWhere = vi.fn().mockResolvedValue(undefined)
197 const updateSet = vi.fn().mockReturnValue({ where: updateWhere })
198 mockUpdate.mockReturnValue({ set: updateSet })
199 const tx = {
200 execute: vi.fn().mockResolvedValue(undefined),
201 select,
202 update: mockUpdate,
203 insert: mockInsert, // recordUsage(tx) reuses the shared insert chain
204 }
205 mockTransaction.mockImplementation(async (fn: (t: typeof tx) => unknown) => fn(tx))
206 return { tx, select, updateSet }
207 }
208
209 /** True when any tx.execute call ran a sql`` template containing the substring. */
210 const executedSqlContaining = (tx: { execute: ReturnType<typeof vi.fn> }, substring: string) =>

Callers 1

usage-log.test.tsFile · 0.85

Calls 1

fnFunction · 0.50

Tested by

no test coverage detected