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
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import type { MockProxy } from 'jest-mock-extended';
|
|
import { mock } from 'jest-mock-extended';
|
|
import type { IBinaryData, IExecuteSingleFunctions } from 'n8n-workflow';
|
|
|
|
import { downloadFilePostReceive, escapeFilterValue } from '../../helpers/utils';
|
|
|
|
describe('Microsoft SharePoint Node', () => {
|
|
let executeSingleFunctions: MockProxy<IExecuteSingleFunctions>;
|
|
|
|
beforeEach(() => {
|
|
executeSingleFunctions = mock<IExecuteSingleFunctions>();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('should download file post receive', async () => {
|
|
const mockResponse = {
|
|
body: '',
|
|
statusCode: 200,
|
|
headers: {
|
|
'content-disposition': "attachment; filename*=UTF-8''encoded%20name.pdf",
|
|
'content-type': 'application/pdf',
|
|
},
|
|
};
|
|
const mockPrepareBinaryData = jest.fn().mockReturnValueOnce({
|
|
data: '',
|
|
mimeType: 'application/pdf',
|
|
fileName: 'encoded name.pdf',
|
|
} as IBinaryData);
|
|
executeSingleFunctions.helpers.prepareBinaryData = mockPrepareBinaryData;
|
|
|
|
const result = await downloadFilePostReceive.call(executeSingleFunctions, [], mockResponse);
|
|
|
|
expect(mockPrepareBinaryData).toHaveBeenCalledWith(
|
|
mockResponse.body,
|
|
'encoded name.pdf',
|
|
'application/pdf',
|
|
);
|
|
expect(result).toEqual([
|
|
{
|
|
json: {},
|
|
binary: {
|
|
data: {
|
|
data: '',
|
|
mimeType: 'application/pdf',
|
|
fileName: 'encoded name.pdf',
|
|
},
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
describe('escapeFilterValue', () => {
|
|
it('should escape single quotes', () => {
|
|
expect(escapeFilterValue("hello' there ''")).toEqual("hello'' there ''''");
|
|
});
|
|
it('should not escape double quotes', () => {
|
|
expect(escapeFilterValue('hello " there ""')).toEqual('hello " there ""');
|
|
});
|
|
});
|
|
});
|