♻️(engine): extract custom header parsing and update OpenAiEngine

- export parseCustomHeaders from src/utils/engine.ts
- use parseCustomHeaders in OpenAiEngine for config.customHeaders
- remove try/catch and inline JSON.parse logic
- update config test to expect headers as object and drop JSON.parse

Centralize header parsing for reuse and simplify engine code
Update tests to match new header format for clarity
This commit is contained in:
EmilienMottet
2025-04-30 21:43:44 +02:00
parent 71a44fac28
commit 6aae1c7bd7
3 changed files with 8 additions and 14 deletions
+3 -3
View File
@@ -138,10 +138,10 @@ describe('config', () => {
});
expect(config).not.toEqual(null);
expect(config.OCO_API_CUSTOM_HEADERS).toEqual('{"Authorization": "Bearer token123", "X-Custom-Header": "test-value"}');
expect(config.OCO_API_CUSTOM_HEADERS).toEqual({"Authorization": "Bearer token123", "X-Custom-Header": "test-value"});
// Verify that the JSON can be parsed correctly
const parsedHeaders = JSON.parse(config.OCO_API_CUSTOM_HEADERS);
// No need to parse JSON again since it's already an object
const parsedHeaders = config.OCO_API_CUSTOM_HEADERS;
expect(parsedHeaders).toHaveProperty('Authorization', 'Bearer token123');
expect(parsedHeaders).toHaveProperty('X-Custom-Header', 'test-value');
expect(parsedHeaders).not.toHaveProperty('X-Global-Header');