Skip to content

Commit ce97b87

Browse files
committed
fix tests
1 parent e3fce54 commit ce97b87

File tree

3 files changed

+69
-48
lines changed

3 files changed

+69
-48
lines changed

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

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,11 @@ describe('Function Execute API Route', () => {
276276
it.concurrent('should resolve tag variables with <tag_name> syntax', async () => {
277277
const req = createMockRequest('POST', {
278278
code: 'return <email>',
279-
params: {
280-
email: { id: '123', subject: 'Test Email' },
279+
blockData: {
280+
'block-123': { id: '123', subject: 'Test Email' },
281+
},
282+
blockNameMapping: {
283+
email: 'block-123',
281284
},
282285
})
283286

@@ -305,9 +308,13 @@ describe('Function Execute API Route', () => {
305308
it.concurrent('should only match valid variable names in angle brackets', async () => {
306309
const req = createMockRequest('POST', {
307310
code: 'return <validVar> + "<invalid@email.com>" + <another_valid>',
308-
params: {
309-
validVar: 'hello',
310-
another_valid: 'world',
311+
blockData: {
312+
'block-1': 'hello',
313+
'block-2': 'world',
314+
},
315+
blockNameMapping: {
316+
validVar: 'block-1',
317+
another_valid: 'block-2',
311318
},
312319
})
313320

@@ -321,28 +328,22 @@ describe('Function Execute API Route', () => {
321328
it.concurrent(
322329
'should handle Gmail webhook data with email addresses containing angle brackets',
323330
async () => {
324-
const gmailData = {
325-
email: {
326-
id: '123',
327-
from: 'Waleed Latif <waleed@sim.ai>',
328-
to: 'User <user@example.com>',
329-
subject: 'Test Email',
330-
bodyText: 'Hello world',
331-
},
332-
rawEmail: {
333-
id: '123',
334-
payload: {
335-
headers: [
336-
{ name: 'From', value: 'Waleed Latif <waleed@sim.ai>' },
337-
{ name: 'To', value: 'User <user@example.com>' },
338-
],
339-
},
340-
},
331+
const emailData = {
332+
id: '123',
333+
from: 'Waleed Latif <waleed@sim.ai>',
334+
to: 'User <user@example.com>',
335+
subject: 'Test Email',
336+
bodyText: 'Hello world',
341337
}
342338

343339
const req = createMockRequest('POST', {
344340
code: 'return <email>',
345-
params: gmailData,
341+
blockData: {
342+
'block-email': emailData,
343+
},
344+
blockNameMapping: {
345+
email: 'block-email',
346+
},
346347
})
347348

348349
const response = await POST(req)
@@ -356,17 +357,20 @@ describe('Function Execute API Route', () => {
356357
it.concurrent(
357358
'should properly serialize complex email objects with special characters',
358359
async () => {
359-
const complexEmailData = {
360-
email: {
361-
from: 'Test User <test@example.com>',
362-
bodyHtml: '<div>HTML content with "quotes" and \'apostrophes\'</div>',
363-
bodyText: 'Text with\nnewlines\tand\ttabs',
364-
},
360+
const emailData = {
361+
from: 'Test User <test@example.com>',
362+
bodyHtml: '<div>HTML content with "quotes" and \'apostrophes\'</div>',
363+
bodyText: 'Text with\nnewlines\tand\ttabs',
365364
}
366365

367366
const req = createMockRequest('POST', {
368367
code: 'return <email>',
369-
params: complexEmailData,
368+
blockData: {
369+
'block-email': emailData,
370+
},
371+
blockNameMapping: {
372+
email: 'block-email',
373+
},
370374
})
371375

372376
const response = await POST(req)
@@ -519,18 +523,23 @@ describe('Function Execute API Route', () => {
519523
})
520524

521525
it.concurrent('should handle JSON serialization edge cases', async () => {
526+
const complexData = {
527+
special: 'chars"with\'quotes',
528+
unicode: '🎉 Unicode content',
529+
nested: {
530+
deep: {
531+
value: 'test',
532+
},
533+
},
534+
}
535+
522536
const req = createMockRequest('POST', {
523537
code: 'return <complexData>',
524-
params: {
525-
complexData: {
526-
special: 'chars"with\'quotes',
527-
unicode: '🎉 Unicode content',
528-
nested: {
529-
deep: {
530-
value: 'test',
531-
},
532-
},
533-
},
538+
blockData: {
539+
'block-complex': complexData,
540+
},
541+
blockNameMapping: {
542+
complexData: 'block-complex',
534543
},
535544
})
536545

apps/sim/executor/variables/resolvers/block.test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import type { ResolutionContext } from './reference'
66

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

9+
vi.mock('@/lib/workflows/blocks/block-outputs', () => ({
10+
getBlockOutputs: vi.fn(() => ({})),
11+
}))
12+
913
function createTestWorkflow(
1014
blocks: Array<{
1115
id: string
@@ -140,16 +144,21 @@ describe('BlockResolver', () => {
140144
expect(resolver.resolve('<source.nonexistent>', ctx)).toBeUndefined()
141145
})
142146

143-
it.concurrent('should throw error for path not in output schema', () => {
147+
it.concurrent('should throw error for path not in output schema', async () => {
148+
const { getBlockOutputs } = await import('@/lib/workflows/blocks/block-outputs')
149+
const mockGetBlockOutputs = vi.mocked(getBlockOutputs)
150+
const customOutputs = {
151+
validField: { type: 'string', description: 'A valid field' },
152+
nested: {
153+
child: { type: 'number', description: 'Nested child' },
154+
},
155+
}
156+
mockGetBlockOutputs.mockReturnValue(customOutputs as any)
157+
144158
const workflow = createTestWorkflow([
145159
{
146160
id: 'source',
147-
outputs: {
148-
validField: { type: 'string', description: 'A valid field' },
149-
nested: {
150-
child: { type: 'number', description: 'Nested child' },
151-
},
152-
},
161+
outputs: customOutputs,
153162
},
154163
])
155164
const resolver = new BlockResolver(workflow)
@@ -161,6 +170,8 @@ describe('BlockResolver', () => {
161170
/"invalidField" doesn't exist on block "source"/
162171
)
163172
expect(() => resolver.resolve('<source.invalidField>', ctx)).toThrow(/Available fields:/)
173+
174+
mockGetBlockOutputs.mockReturnValue({})
164175
})
165176

166177
it.concurrent('should return undefined for path in schema but missing in data', () => {

apps/sim/stores/workflows/utils.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
createStarterBlock,
77
} from '@sim/testing'
88
import { describe, expect, it } from 'vitest'
9-
import { getUniqueBlockName, normalizeName } from './utils'
9+
import { normalizeName } from '@/executor/constants'
10+
import { getUniqueBlockName } from './utils'
1011

1112
describe('normalizeName', () => {
1213
it.concurrent('should convert to lowercase', () => {

0 commit comments

Comments
 (0)