mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
refactor: Overhaul nodes-testing setup - Part 3 (no-changelog) (#14967)
This commit is contained in:
committed by
GitHub
parent
3e43f9f8bc
commit
979f9e6327
@@ -1,9 +1,6 @@
|
||||
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { Connection, QueryResult } from 'mysql2/promise';
|
||||
import type { WorkflowTestData } from 'n8n-workflow';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import { getResultNodeData, workflowToTests } from '@test/nodes/Helpers';
|
||||
|
||||
const mockConnection = mock<Connection>();
|
||||
const createConnection = jest.fn().mockReturnValue(mockConnection);
|
||||
@@ -12,27 +9,13 @@ jest.mock('mysql2/promise', () => ({ createConnection }));
|
||||
describe('Test MySqlV1, executeQuery', () => {
|
||||
mockConnection.query.mockResolvedValue([{ success: true } as unknown as QueryResult, []]);
|
||||
|
||||
const workflows = ['nodes/MySql/test/v1/executeQuery.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
|
||||
const testNode = async (testData: WorkflowTestData) => {
|
||||
const { result } = await executeWorkflow(testData);
|
||||
|
||||
const resultNodeData = getResultNodeData(result, testData);
|
||||
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
return expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(mockConnection.query).toHaveBeenCalledTimes(1);
|
||||
expect(mockConnection.query).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 () => await testNode(testData));
|
||||
}
|
||||
new NodeTestHarness().setupTests({
|
||||
workflowFiles: ['executeQuery.workflow.json'],
|
||||
customAssertions() {
|
||||
expect(mockConnection.query).toHaveBeenCalledTimes(1);
|
||||
expect(mockConnection.query).toHaveBeenCalledWith(
|
||||
"select * from family_parents where (parent_email = 'parent1@mail.com' or parent_email = 'parent2@mail.com') and parent_email <> '';",
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user