MCPcopy
hub / github.com/simstudioai/sim / setupCleanupMocks

Function setupCleanupMocks

apps/sim/lib/logs/execution/snapshot/service.test.ts:503–523  ·  view source on GitHub ↗
(selectBatches: Array<Array<{ id: string }>>)

Source from the content-addressed store, hash-verified

501
502 describe('cleanupOrphanedSnapshots', () => {
503 function setupCleanupMocks(selectBatches: Array<Array<{ id: string }>>) {
504 const limitFn = vi.fn()
505 for (const batch of selectBatches) limitFn.mockResolvedValueOnce(batch)
506 limitFn.mockResolvedValue([])
507 const whereSelect = vi.fn().mockReturnValue({ limit: limitFn })
508 const fromFn = vi.fn().mockReturnValue({ where: whereSelect })
509 databaseMock.db.select = vi.fn().mockReturnValue({ from: fromFn })
510
511 const returningFn = vi.fn().mockImplementation(() => Promise.resolve([]))
512 const whereDelete = vi.fn().mockReturnValue({ returning: returningFn })
513 let batchIdx = 0
514 const deleteFn = vi.fn().mockImplementation(() => {
515 const batch = selectBatches[batchIdx] ?? []
516 batchIdx++
517 returningFn.mockImplementationOnce(() => Promise.resolve(batch.map((r) => ({ id: r.id }))))
518 return { where: whereDelete }
519 })
520 databaseMock.db.delete = deleteFn
521
522 return { deleteFn }
523 }
524
525 it('returns 0 and skips delete when nothing is orphaned', async () => {
526 const service = new SnapshotService()

Callers 1

service.test.tsFile · 0.85

Calls 1

resolveMethod · 0.65

Tested by

no test coverage detected