Skip to content

Commit 89a658b

Browse files
committed
fix(workflows): validate cancellation terminal writes
1 parent c1983de commit 89a658b

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

apps/sim/lib/execution/cancel-workflow-execution.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,16 +1613,19 @@ describe('cancelWorkflowExecution', () => {
16131613
})
16141614

16151615
it('updates execution log status in DB when durably recorded', async () => {
1616-
const mockWhere = vi.fn().mockResolvedValue(undefined)
1616+
const mockReturning = vi.fn().mockResolvedValue([{ status: 'cancelled' }])
1617+
const mockWhere = vi.fn(() => ({ returning: mockReturning }))
16171618
const mockSet = vi.fn(() => ({ where: mockWhere }))
16181619
databaseMock.db.update.mockReturnValueOnce({ set: mockSet })
16191620
mockMarkExecutionCancelled.mockResolvedValue({
16201621
durablyRecorded: true,
16211622
reason: 'recorded',
16221623
})
16231624

1624-
await POST(makeRequest(), makeParams())
1625+
const response = await POST(makeRequest(), makeParams())
16251626

1627+
expect(response.status).toBe(200)
1628+
await expect(response.json()).resolves.toMatchObject({ success: true, reason: 'recorded' })
16261629
expect(databaseMock.db.update).toHaveBeenCalled()
16271630
expect(mockSet).toHaveBeenCalledWith({
16281631
status: 'cancelled',
@@ -1633,7 +1636,8 @@ describe('cancelWorkflowExecution', () => {
16331636
})
16341637

16351638
it('updates execution log status in DB when locally aborted', async () => {
1636-
const mockWhere = vi.fn().mockResolvedValue(undefined)
1639+
const mockReturning = vi.fn().mockResolvedValue([{ status: 'cancelled' }])
1640+
const mockWhere = vi.fn(() => ({ returning: mockReturning }))
16371641
const mockSet = vi.fn(() => ({ where: mockWhere }))
16381642
databaseMock.db.update.mockReturnValueOnce({ set: mockSet })
16391643
mockMarkExecutionCancelled.mockResolvedValue({
@@ -1642,8 +1646,13 @@ describe('cancelWorkflowExecution', () => {
16421646
})
16431647
mockAbortManualExecution.mockReturnValue(true)
16441648

1645-
await POST(makeRequest(), makeParams())
1649+
const response = await POST(makeRequest(), makeParams())
16461650

1651+
expect(response.status).toBe(200)
1652+
await expect(response.json()).resolves.toMatchObject({
1653+
success: true,
1654+
reason: 'redis_unavailable',
1655+
})
16471656
expect(databaseMock.db.update).toHaveBeenCalled()
16481657
expect(mockSet).toHaveBeenCalledWith({
16491658
status: 'cancelled',

0 commit comments

Comments
 (0)