feat: add OpenAI OAuth, strict model overrides, and Gmail pull mode
This commit is contained in:
@@ -1,23 +1,38 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { OpenAIClient } from './openai.js';
|
||||
|
||||
// Shared mock function so we can override per-test
|
||||
const mockCreate = vi.fn().mockResolvedValue({
|
||||
choices: [{ message: { content: 'Hello from GPT!' }, finish_reason: 'stop' }],
|
||||
usage: { prompt_tokens: 10, completion_tokens: 5 },
|
||||
});
|
||||
|
||||
vi.mock('openai', () => ({
|
||||
default: vi.fn().mockImplementation(() => ({
|
||||
const { mockCreate, mockOpenAIConstructor } = vi.hoisted(() => {
|
||||
const mockCreate = vi.fn().mockResolvedValue({
|
||||
choices: [{ message: { content: 'Hello from GPT!' }, finish_reason: 'stop' }],
|
||||
usage: { prompt_tokens: 10, completion_tokens: 5 },
|
||||
});
|
||||
const mockOpenAIConstructor = vi.fn().mockImplementation(() => ({
|
||||
chat: {
|
||||
completions: {
|
||||
create: mockCreate,
|
||||
},
|
||||
},
|
||||
})),
|
||||
}));
|
||||
return { mockCreate, mockOpenAIConstructor };
|
||||
});
|
||||
|
||||
vi.mock('openai', () => ({
|
||||
default: mockOpenAIConstructor,
|
||||
}));
|
||||
|
||||
describe('OpenAIClient', () => {
|
||||
it('sets request timeout and disables SDK retries', () => {
|
||||
new OpenAIClient({
|
||||
apiKey: 'test-key',
|
||||
model: 'gpt-4o',
|
||||
});
|
||||
|
||||
expect(mockOpenAIConstructor).toHaveBeenCalledWith(expect.objectContaining({
|
||||
timeout: 20_000,
|
||||
maxRetries: 0,
|
||||
}));
|
||||
});
|
||||
|
||||
it('sends messages and returns response', async () => {
|
||||
const client = new OpenAIClient({
|
||||
apiKey: 'test-key',
|
||||
|
||||
Reference in New Issue
Block a user