| const DALLE3 = require('../DALLE3'); |
| const { ProxyAgent } = require('undici'); |
|
|
| jest.mock('tiktoken'); |
| const processFileURL = jest.fn(); |
|
|
| describe('DALLE3 Proxy Configuration', () => { |
| let originalEnv; |
|
|
| beforeAll(() => { |
| originalEnv = { ...process.env }; |
| }); |
|
|
| beforeEach(() => { |
| jest.resetModules(); |
| process.env = { ...originalEnv }; |
| }); |
|
|
| afterEach(() => { |
| process.env = originalEnv; |
| }); |
|
|
| it('should configure ProxyAgent in fetchOptions.dispatcher when PROXY env is set', () => { |
| |
| process.env.PROXY = 'http://proxy.example.com:8080'; |
| process.env.DALLE_API_KEY = 'test-api-key'; |
|
|
| |
| const dalleWithProxy = new DALLE3({ processFileURL }); |
|
|
| |
| expect(dalleWithProxy.openai).toBeDefined(); |
|
|
| |
| expect(dalleWithProxy.openai._options).toBeDefined(); |
| expect(dalleWithProxy.openai._options.fetchOptions).toBeDefined(); |
| expect(dalleWithProxy.openai._options.fetchOptions.dispatcher).toBeDefined(); |
| expect(dalleWithProxy.openai._options.fetchOptions.dispatcher).toBeInstanceOf(ProxyAgent); |
| }); |
|
|
| it('should not configure ProxyAgent when PROXY env is not set', () => { |
| |
| delete process.env.PROXY; |
| process.env.DALLE_API_KEY = 'test-api-key'; |
|
|
| |
| const dalleWithoutProxy = new DALLE3({ processFileURL }); |
|
|
| |
| expect(dalleWithoutProxy.openai).toBeDefined(); |
|
|
| |
| expect(dalleWithoutProxy.openai._options).toBeDefined(); |
|
|
| |
| if (dalleWithoutProxy.openai._options.fetchOptions) { |
| expect(dalleWithoutProxy.openai._options.fetchOptions.dispatcher).toBeUndefined(); |
| } |
| }); |
| }); |
|
|