mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 20:00:02 +00:00
refactor: Overhaul nodes-testing setup - Part 1 (no-changelog) (#14303)
This commit is contained in:
committed by
GitHub
parent
f85b851851
commit
73e8d76e13
@@ -1,9 +1,6 @@
|
||||
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
|
||||
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
|
||||
import * as genericFunctions from '../../../../V2/GenericFunctions';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
const API_RESPONSE = {
|
||||
ok: true,
|
||||
@@ -110,42 +107,13 @@ const API_RESPONSE = {
|
||||
},
|
||||
};
|
||||
|
||||
jest.mock('../../../../V2/GenericFunctions', () => {
|
||||
const originalModule = jest.requireActual('../../../../V2/GenericFunctions');
|
||||
return {
|
||||
...originalModule,
|
||||
slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) {
|
||||
if (method === 'GET') {
|
||||
return API_RESPONSE;
|
||||
}
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Test SlackV2, channel => getAll', () => {
|
||||
nock('https://slack.com')
|
||||
.get(
|
||||
'/api/conversations.list?types=public_channel%2Cprivate_channel%2Cim%2Cmpim&exclude_archived=true&limit=2',
|
||||
)
|
||||
.reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/channel/getAll.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1);
|
||||
expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/conversations.list',
|
||||
{},
|
||||
{ exclude_archived: true, limit: 2, types: 'public_channel,private_channel,im,mpim' },
|
||||
);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user