Files
alighasami 3d5eaf9445
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

88 lines
2.2 KiB
TypeScript

import { formatResponse } from '../methods/responseFormatter';
describe('responseFormatter', () => {
describe('formatResponse', () => {
it('should format string responses', () => {
const result = formatResponse('Test response', true);
expect(result).toEqual({
text: 'Test response',
});
});
it('should trim string responses', () => {
const result = formatResponse(' Test response with whitespace ', true);
expect(result).toEqual({
text: 'Test response with whitespace',
});
});
it('should handle array responses', () => {
const testArray = [{ item: 1 }, { item: 2 }];
const result = formatResponse(testArray, true);
expect(result).toEqual({ data: testArray });
});
it('should handle object responses when unwrapping is enabled', () => {
const testObject = { key: 'value', nested: { key: 'value' } };
const result = formatResponse(testObject, true);
expect(result).toEqual(testObject);
});
it('should stringify object responses when unwrapping is disabled', () => {
const testObject = { key: 'value', nested: { key: 'value' } };
const result = formatResponse(testObject, false);
expect(result).toEqual({
text: JSON.stringify(testObject),
});
});
it('should handle primitive non-string responses', () => {
const testNumber = 42;
const result = formatResponse(testNumber, true);
expect(result).toEqual({
response: {
text: 42,
},
});
});
it('should handle complex object structures when unwrapping is enabled', () => {
const complexObject = {
person: {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
},
},
items: [1, 2, 3],
active: true,
};
const result = formatResponse(complexObject, true);
expect(result).toEqual(complexObject);
});
it('should stringify complex object structures when unwrapping is disabled', () => {
const complexObject = {
person: {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
},
},
items: [1, 2, 3],
active: true,
};
const result = formatResponse(complexObject, false);
expect(result).toEqual({
text: JSON.stringify(complexObject),
});
});
});
});