Skip to content

Commit

Permalink
fix: mock fetch to prevent actual API calls
Browse files Browse the repository at this point in the history
Co-Authored-By: Han Xiao <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and hanxiao committed Feb 13, 2025
1 parent 56c55d1 commit cde7781
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/tools/__tests__/evaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ jest.mock('@ai-sdk/google', () => ({
GoogleChatLanguageModel: jest.fn()
}));

// Mock fetch to prevent actual API calls
const mockFetch = jest.fn().mockResolvedValue({
ok: true,
json: () => Promise.resolve({
choices: [{
message: {
function_call: {
arguments: JSON.stringify(mockEvalResponse)
}
}
}]
})
});

global.fetch = mockFetch;

// Mock OpenAI API
jest.mock('@ai-sdk/openai', () => ({
OpenAIChatLanguageModel: jest.fn().mockImplementation(() => ({
Expand All @@ -76,14 +92,6 @@ jest.mock('@ai-sdk/openai', () => ({
}))
}));

// Mock response handler to prevent API calls
jest.mock('@ai-sdk/provider-utils/src/response-handler', () => ({
handleResponse: jest.fn().mockImplementation(() => ({
object: mockEvalResponse,
usage: { totalTokens: 0 }
}))
}));

jest.mock('../../utils/token-tracker');

// Mock readUrl to prevent actual API calls
Expand Down

0 comments on commit cde7781

Please sign in to comment.