Skip to content

Commit ed468d7

Browse files
author
Theodore Li
committed
Fix test
1 parent 5b858b3 commit ed468d7

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

apps/sim/tools/index.test.ts

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@ import {
1616
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1717

1818
// Hoisted mock state - these are available to vi.mock factories
19-
const { mockIsHosted, mockEnv, mockGetBYOKKey, mockGetToolAsync, mockRateLimiterFns } = vi.hoisted(
20-
() => ({
21-
mockIsHosted: { value: false },
22-
mockEnv: { NEXT_PUBLIC_APP_URL: 'http://localhost:3000' } as Record<string, string | undefined>,
23-
mockGetBYOKKey: vi.fn(),
24-
mockGetToolAsync: vi.fn(),
25-
mockRateLimiterFns: {
26-
acquireKey: vi.fn(),
27-
preConsumeCapacity: vi.fn(),
28-
consumeCapacity: vi.fn(),
29-
},
30-
})
31-
)
19+
const {
20+
mockIsHosted,
21+
mockEnv,
22+
mockGetBYOKKey,
23+
mockGetToolAsync,
24+
mockRateLimiterFns,
25+
mockGetCustomToolById,
26+
mockListCustomTools,
27+
} = vi.hoisted(() => ({
28+
mockIsHosted: { value: false },
29+
mockEnv: { NEXT_PUBLIC_APP_URL: 'http://localhost:3000' } as Record<string, string | undefined>,
30+
mockGetBYOKKey: vi.fn(),
31+
mockGetToolAsync: vi.fn(),
32+
mockRateLimiterFns: {
33+
acquireKey: vi.fn(),
34+
preConsumeCapacity: vi.fn(),
35+
consumeCapacity: vi.fn(),
36+
},
37+
mockGetCustomToolById: vi.fn(),
38+
mockListCustomTools: vi.fn(),
39+
}))
3240

3341
// Mock feature flags
3442
vi.mock('@/lib/core/config/feature-flags', () => ({
@@ -214,6 +222,11 @@ vi.mock('@/hooks/queries/utils/custom-tool-cache', () => {
214222
}
215223
})
216224

225+
vi.mock('@/lib/workflows/custom-tools/operations', () => ({
226+
getCustomToolById: mockGetCustomToolById,
227+
listCustomTools: mockListCustomTools,
228+
}))
229+
217230
vi.mock('@/tools/utils.server', async (importOriginal) => {
218231
const actual = await importOriginal<typeof import('@/tools/utils.server')>()
219232
mockGetToolAsync.mockImplementation(actual.getToolAsync)
@@ -307,30 +320,23 @@ describe('Custom Tools', () => {
307320
})
308321

309322
it('resolves custom tools through the async helper', async () => {
310-
setupFetchMock({
311-
json: {
312-
data: [
313-
{
314-
id: 'remote-tool-123',
315-
title: 'Custom Weather Tool',
316-
schema: {
317-
function: {
318-
name: 'weather_tool',
319-
description: 'Get weather information',
320-
parameters: {
321-
type: 'object',
322-
properties: {
323-
location: { type: 'string', description: 'City name' },
324-
},
325-
required: ['location'],
326-
},
327-
},
323+
mockGetCustomToolById.mockResolvedValue({
324+
id: 'remote-tool-123',
325+
title: 'Custom Weather Tool',
326+
schema: {
327+
function: {
328+
name: 'weather_tool',
329+
description: 'Get weather information',
330+
parameters: {
331+
type: 'object',
332+
properties: {
333+
location: { type: 'string', description: 'City name' },
328334
},
335+
required: ['location'],
329336
},
330-
],
337+
},
331338
},
332-
status: 200,
333-
headers: { 'content-type': 'application/json' },
339+
code: '',
334340
})
335341

336342
const customTool = await getToolAsync('custom_remote-tool-123', {

0 commit comments

Comments
 (0)