mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 11:49:59 +00:00
fix(MySQL Node): Resolve expressions in v1 (#7464)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
60
packages/nodes-base/nodes/MySql/test/v1/executeQuery.test.ts
Normal file
60
packages/nodes-base/nodes/MySql/test/v1/executeQuery.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
|
||||
import nock from 'nock';
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
|
||||
const queryMock = jest.fn(async function () {
|
||||
return [{ success: true }];
|
||||
});
|
||||
|
||||
jest.mock('../../v1/GenericFunctions', () => {
|
||||
const originalModule = jest.requireActual('../../v1/GenericFunctions');
|
||||
return {
|
||||
...originalModule,
|
||||
createConnection: jest.fn(async function () {
|
||||
return {
|
||||
query: queryMock,
|
||||
end: jest.fn(),
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Test MySqlV1, executeQuery', () => {
|
||||
const workflows = ['nodes/MySql/test/v1/executeQuery.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.restore();
|
||||
jest.unmock('../../v1/GenericFunctions');
|
||||
});
|
||||
|
||||
const nodeTypes = setup(tests);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
|
||||
const { result } = await executeWorkflow(testData, types);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(queryMock).toHaveBeenCalledTimes(1);
|
||||
expect(queryMock).toHaveBeenCalledWith(
|
||||
"select * from family_parents where (parent_email = 'parent1@mail.com' or parent_email = 'parent2@mail.com') and parent_email <> '';",
|
||||
);
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => testNode(testData, nodeTypes));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user