mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
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';
|
|
|
|
const API_RESPONSE = {
|
|
ok: true,
|
|
channel: 'C08514ZPKB8',
|
|
message_timestamp: '1734322671.726339',
|
|
};
|
|
|
|
jest.mock('../../../../V2/GenericFunctions', () => {
|
|
const originalModule = jest.requireActual('../../../../V2/GenericFunctions');
|
|
return {
|
|
...originalModule,
|
|
slackApiRequest: jest.fn(async function (method: IHttpRequestMethods) {
|
|
if (method === 'POST') {
|
|
return API_RESPONSE;
|
|
}
|
|
}),
|
|
};
|
|
});
|
|
|
|
describe('Test SlackV2, message => delete', () => {
|
|
const workflows = ['nodes/Slack/test/v2/node/message/delete.workflow.json'];
|
|
const tests = workflowToTests(workflows);
|
|
|
|
beforeAll(() => {
|
|
nock.disableNetConnect();
|
|
});
|
|
|
|
afterAll(() => {
|
|
nock.restore();
|
|
jest.unmock('../../../../V2/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(genericFunctions.slackApiRequest).toHaveBeenCalledTimes(1);
|
|
expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith(
|
|
'POST',
|
|
'/chat.delete',
|
|
{ channel: 'C08514ZPKB8', ts: '1734322671.726339' },
|
|
{},
|
|
);
|
|
};
|
|
|
|
for (const testData of tests) {
|
|
test(testData.description, async () => await testNode(testData, nodeTypes));
|
|
}
|
|
});
|