Skip to content

Commit bd81f6c

Browse files
committed
removed all other usages of deprecated 'state' column from workflows table, updated tests
1 parent 1617880 commit bd81f6c

File tree

8 files changed

+175
-147
lines changed

8 files changed

+175
-147
lines changed

apps/sim/app/api/webhooks/trigger/[path]/route.test.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import { NextRequest } from 'next/server'
55
* @vitest-environment node
66
*/
77
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
8-
import {
9-
createMockRequest,
10-
mockExecutionDependencies,
11-
sampleWorkflowState,
12-
} from '@/app/api/__test-utils__/utils'
8+
import { createMockRequest, mockExecutionDependencies } from '@/app/api/__test-utils__/utils'
139

1410
// Define mock functions at the top level to be used in mocks
1511
const hasProcessedMessageMock = vi.fn().mockResolvedValue(false)
@@ -148,10 +144,8 @@ describe('Webhook Trigger API Route', () => {
148144
vi.resetAllMocks()
149145
vi.clearAllTimers()
150146

151-
// Mock all dependencies
152147
mockExecutionDependencies()
153148

154-
// Mock the normalized tables helper
155149
vi.doMock('@/lib/workflows/db-helpers', () => ({
156150
loadWorkflowFromNormalizedTables: vi.fn().mockResolvedValue({
157151
blocks: {},
@@ -162,20 +156,17 @@ describe('Webhook Trigger API Route', () => {
162156
}),
163157
}))
164158

165-
// Reset mock behaviors to default for each test
166159
hasProcessedMessageMock.mockResolvedValue(false)
167160
markMessageAsProcessedMock.mockResolvedValue(true)
168161
acquireLockMock.mockResolvedValue(true)
169162
handleWhatsAppVerificationMock.mockResolvedValue(null)
170163
processGenericDeduplicationMock.mockResolvedValue(null)
171164
processWebhookMock.mockResolvedValue(new Response('Webhook processed', { status: 200 }))
172165

173-
// Restore original crypto.randomUUID if it was mocked
174166
if ((global as any).crypto?.randomUUID) {
175167
vi.spyOn(crypto, 'randomUUID').mockRestore()
176168
}
177169

178-
// Mock crypto.randomUUID to return predictable values
179170
vi.spyOn(crypto, 'randomUUID').mockReturnValue('mock-uuid-12345')
180171
})
181172

@@ -274,7 +265,6 @@ describe('Webhook Trigger API Route', () => {
274265
workflow: {
275266
id: 'workflow-id',
276267
userId: 'user-id',
277-
state: sampleWorkflowState,
278268
},
279269
},
280270
])
@@ -366,7 +356,6 @@ describe('Webhook Trigger API Route', () => {
366356
workflow: {
367357
id: 'workflow-id',
368358
userId: 'user-id',
369-
state: sampleWorkflowState,
370359
},
371360
},
372361
])
@@ -420,7 +409,6 @@ describe('Webhook Trigger API Route', () => {
420409
workflow: {
421410
id: 'workflow-id',
422411
userId: 'user-id',
423-
state: sampleWorkflowState,
424412
},
425413
},
426414
])
@@ -493,7 +481,6 @@ describe('Webhook Trigger API Route', () => {
493481
workflow: {
494482
id: 'workflow-id',
495483
userId: 'user-id',
496-
state: sampleWorkflowState,
497484
},
498485
},
499486
])
@@ -564,7 +551,6 @@ describe('Webhook Trigger API Route', () => {
564551
workflow: {
565552
id: 'workflow-id',
566553
userId: 'user-id',
567-
state: sampleWorkflowState,
568554
},
569555
},
570556
])

apps/sim/app/api/workflows/[id]/deploy/route.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ describe('Workflow Deployment API Route', () => {
3131
}),
3232
}))
3333

34+
vi.doMock('@/lib/workflows/db-helpers', () => ({
35+
loadWorkflowFromNormalizedTables: vi.fn().mockResolvedValue({
36+
blocks: {
37+
'block-1': {
38+
id: 'block-1',
39+
type: 'starter',
40+
name: 'Start',
41+
position: { x: 100, y: 100 },
42+
enabled: true,
43+
subBlocks: {},
44+
outputs: {},
45+
data: {},
46+
},
47+
},
48+
edges: [],
49+
loops: {},
50+
parallels: {},
51+
isFromNormalizedTables: true,
52+
}),
53+
}))
54+
3455
vi.doMock('../../middleware', () => ({
3556
validateWorkflowAccess: vi.fn().mockResolvedValue({
3657
workflow: {
@@ -74,6 +95,7 @@ describe('Workflow Deployment API Route', () => {
7495
isDeployed: false,
7596
deployedAt: null,
7697
userId: 'user-id',
98+
deployedState: null,
7799
},
78100
]),
79101
}),
@@ -129,7 +151,6 @@ describe('Workflow Deployment API Route', () => {
129151
}),
130152
}),
131153
})
132-
// Mock normalized table queries (blocks, edges, subflows)
133154
.mockReturnValueOnce({
134155
from: vi.fn().mockReturnValue({
135156
where: vi.fn().mockResolvedValue([
@@ -216,7 +237,6 @@ describe('Workflow Deployment API Route', () => {
216237
}),
217238
}),
218239
})
219-
// Mock normalized table queries (blocks, edges, subflows)
220240
.mockReturnValueOnce({
221241
from: vi.fn().mockReturnValue({
222242
where: vi.fn().mockResolvedValue([

apps/sim/app/api/workflows/[id]/deploy/route.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
3232
isDeployed: workflow.isDeployed,
3333
deployedAt: workflow.deployedAt,
3434
userId: workflow.userId,
35-
state: workflow.state,
3635
deployedState: workflow.deployedState,
3736
})
3837
.from(workflow)
@@ -93,11 +92,25 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
9392
// Check if the workflow has meaningful changes that would require redeployment
9493
let needsRedeployment = false
9594
if (workflowData.deployedState) {
96-
const { hasWorkflowChanged } = await import('@/lib/workflows/utils')
97-
needsRedeployment = hasWorkflowChanged(
98-
workflowData.state as any,
99-
workflowData.deployedState as any
100-
)
95+
// Load current state from normalized tables for comparison
96+
const { loadWorkflowFromNormalizedTables } = await import('@/lib/workflows/db-helpers')
97+
const normalizedData = await loadWorkflowFromNormalizedTables(id)
98+
99+
if (normalizedData) {
100+
// Convert normalized data to WorkflowState format for comparison
101+
const currentState = {
102+
blocks: normalizedData.blocks,
103+
edges: normalizedData.edges,
104+
loops: normalizedData.loops,
105+
parallels: normalizedData.parallels,
106+
}
107+
108+
const { hasWorkflowChanged } = await import('@/lib/workflows/utils')
109+
needsRedeployment = hasWorkflowChanged(
110+
currentState as any,
111+
workflowData.deployedState as any
112+
)
113+
}
101114
}
102115

103116
logger.info(`[${requestId}] Successfully retrieved deployment info: ${id}`)
@@ -126,11 +139,10 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
126139
return createErrorResponse(validation.error.message, validation.error.status)
127140
}
128141

129-
// Get the workflow to find the user
142+
// Get the workflow to find the user (removed deprecated state column)
130143
const workflowData = await db
131144
.select({
132145
userId: workflow.userId,
133-
state: workflow.state,
134146
})
135147
.from(workflow)
136148
.where(eq(workflow.id, id))

0 commit comments

Comments
 (0)