ai-switcher
Version:
A package which helps you switch between AI APIs using configurations, so that code changes are not required.
42 lines (34 loc) • 1.21 kB
text/typescript
// src/__tests__/AnthropicClient.test.ts
import { AnthropicClient } from '../clients/anthropic';
import { Message } from '../types';
jest.mock('@anthropic-ai/sdk', () => ({
Anthropic: jest.fn().mockImplementation(() => ({
messages: {
create: jest.fn()
}
}))
}));
describe('AnthropicClient', () => {
let client: AnthropicClient;
let mockAnthropic: any;
beforeEach(() => {
jest.clearAllMocks();
client = new AnthropicClient('test-key');
mockAnthropic = require('@anthropic-ai/sdk').Anthropic.mock.results[0].value;
});
describe('createCompletion', () => {
const messages: Message[] = [{ role: 'user' as const, content: 'test' }];
it('should return completion response', async () => {
mockAnthropic.messages.create.mockResolvedValue({
content: [{ type: 'text', text: 'test response' }]
});
const result = await client.createCompletion(messages);
expect(result).toBe('test response');
});
});
describe('createEmbedding', () => {
it('should throw an error for embeddings', async () => {
await expect(client.createEmbedding('test')).rejects.toThrow('Embeddings not supported by Anthropic');
});
});
});