| 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) => |