Skip to content

Commit f40a68a

Browse files
committed
fix tests
1 parent 8e6ea11 commit f40a68a

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

apps/sim/app/api/schedules/execute/route.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('Scheduled Workflow Execution API Route', () => {
5757
not: vi.fn((condition) => ({ type: 'not', condition })),
5858
isNull: vi.fn((field) => ({ type: 'isNull', field })),
5959
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
60+
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
6061
}))
6162

6263
vi.doMock('@sim/db', () => {
@@ -92,6 +93,12 @@ describe('Scheduled Workflow Execution API Route', () => {
9293
status: 'status',
9394
nextRunAt: 'nextRunAt',
9495
lastQueuedAt: 'lastQueuedAt',
96+
deploymentVersionId: 'deploymentVersionId',
97+
},
98+
workflowDeploymentVersion: {
99+
id: 'id',
100+
workflowId: 'workflowId',
101+
isActive: 'isActive',
95102
},
96103
workflow: {
97104
id: 'id',
@@ -139,6 +146,7 @@ describe('Scheduled Workflow Execution API Route', () => {
139146
not: vi.fn((condition) => ({ type: 'not', condition })),
140147
isNull: vi.fn((field) => ({ type: 'isNull', field })),
141148
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
149+
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
142150
}))
143151

144152
vi.doMock('@sim/db', () => {
@@ -174,6 +182,12 @@ describe('Scheduled Workflow Execution API Route', () => {
174182
status: 'status',
175183
nextRunAt: 'nextRunAt',
176184
lastQueuedAt: 'lastQueuedAt',
185+
deploymentVersionId: 'deploymentVersionId',
186+
},
187+
workflowDeploymentVersion: {
188+
id: 'id',
189+
workflowId: 'workflowId',
190+
isActive: 'isActive',
177191
},
178192
workflow: {
179193
id: 'id',
@@ -216,6 +230,7 @@ describe('Scheduled Workflow Execution API Route', () => {
216230
not: vi.fn((condition) => ({ type: 'not', condition })),
217231
isNull: vi.fn((field) => ({ type: 'isNull', field })),
218232
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
233+
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
219234
}))
220235

221236
vi.doMock('@sim/db', () => {
@@ -238,6 +253,12 @@ describe('Scheduled Workflow Execution API Route', () => {
238253
status: 'status',
239254
nextRunAt: 'nextRunAt',
240255
lastQueuedAt: 'lastQueuedAt',
256+
deploymentVersionId: 'deploymentVersionId',
257+
},
258+
workflowDeploymentVersion: {
259+
id: 'id',
260+
workflowId: 'workflowId',
261+
isActive: 'isActive',
241262
},
242263
workflow: {
243264
id: 'id',
@@ -280,6 +301,7 @@ describe('Scheduled Workflow Execution API Route', () => {
280301
not: vi.fn((condition) => ({ type: 'not', condition })),
281302
isNull: vi.fn((field) => ({ type: 'isNull', field })),
282303
or: vi.fn((...conditions) => ({ type: 'or', conditions })),
304+
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
283305
}))
284306

285307
vi.doMock('@sim/db', () => {
@@ -325,6 +347,12 @@ describe('Scheduled Workflow Execution API Route', () => {
325347
status: 'status',
326348
nextRunAt: 'nextRunAt',
327349
lastQueuedAt: 'lastQueuedAt',
350+
deploymentVersionId: 'deploymentVersionId',
351+
},
352+
workflowDeploymentVersion: {
353+
id: 'id',
354+
workflowId: 'workflowId',
355+
isActive: 'isActive',
328356
},
329357
workflow: {
330358
id: 'id',

apps/sim/app/api/schedules/route.test.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,23 @@ vi.mock('@sim/db', () => ({
2929

3030
vi.mock('@sim/db/schema', () => ({
3131
workflow: { id: 'id', userId: 'userId', workspaceId: 'workspaceId' },
32-
workflowSchedule: { workflowId: 'workflowId', blockId: 'blockId' },
32+
workflowSchedule: {
33+
workflowId: 'workflowId',
34+
blockId: 'blockId',
35+
deploymentVersionId: 'deploymentVersionId',
36+
},
37+
workflowDeploymentVersion: {
38+
id: 'id',
39+
workflowId: 'workflowId',
40+
isActive: 'isActive',
41+
},
3342
}))
3443

3544
vi.mock('drizzle-orm', () => ({
3645
eq: vi.fn(),
3746
and: vi.fn(),
47+
or: vi.fn(),
48+
isNull: vi.fn(),
3849
}))
3950

4051
vi.mock('@/lib/core/utils/request', () => ({
@@ -56,6 +67,11 @@ function mockDbChain(results: any[]) {
5667
where: () => ({
5768
limit: () => results[callIndex++] || [],
5869
}),
70+
leftJoin: () => ({
71+
where: () => ({
72+
limit: () => results[callIndex++] || [],
73+
}),
74+
}),
5975
}),
6076
}))
6177
}
@@ -74,7 +90,16 @@ describe('Schedule GET API', () => {
7490
it('returns schedule data for authorized user', async () => {
7591
mockDbChain([
7692
[{ userId: 'user-1', workspaceId: null }],
77-
[{ id: 'sched-1', cronExpression: '0 9 * * *', status: 'active', failedCount: 0 }],
93+
[
94+
{
95+
schedule: {
96+
id: 'sched-1',
97+
cronExpression: '0 9 * * *',
98+
status: 'active',
99+
failedCount: 0,
100+
},
101+
},
102+
],
78103
])
79104

80105
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))
@@ -128,7 +153,7 @@ describe('Schedule GET API', () => {
128153
it('allows workspace members to view', async () => {
129154
mockDbChain([
130155
[{ userId: 'other-user', workspaceId: 'ws-1' }],
131-
[{ id: 'sched-1', status: 'active', failedCount: 0 }],
156+
[{ schedule: { id: 'sched-1', status: 'active', failedCount: 0 } }],
132157
])
133158

134159
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))
@@ -139,7 +164,7 @@ describe('Schedule GET API', () => {
139164
it('indicates disabled schedule with failures', async () => {
140165
mockDbChain([
141166
[{ userId: 'user-1', workspaceId: null }],
142-
[{ id: 'sched-1', status: 'disabled', failedCount: 100 }],
167+
[{ schedule: { id: 'sched-1', status: 'disabled', failedCount: 100 } }],
143168
])
144169

145170
const res = await GET(createRequest('http://test/api/schedules?workflowId=wf-1'))

apps/sim/lib/workflows/schedules/deploy.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ vi.mock('@sim/db', () => ({
3535
workflowSchedule: {
3636
workflowId: 'workflow_id',
3737
blockId: 'block_id',
38+
deploymentVersionId: 'deployment_version_id',
3839
},
3940
}))
4041

4142
vi.mock('drizzle-orm', () => ({
4243
eq: vi.fn((...args) => ({ type: 'eq', args })),
44+
and: vi.fn((...args) => ({ type: 'and', args })),
45+
sql: vi.fn((strings, ...values) => ({ type: 'sql', strings, values })),
46+
}))
47+
48+
vi.mock('@/lib/webhooks/deploy', () => ({
49+
cleanupWebhooksForWorkflow: vi.fn().mockResolvedValue(undefined),
4350
}))
4451

4552
vi.mock('@sim/logger', () => loggerMock)

0 commit comments

Comments
 (0)