mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 04:10:01 +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,
|
||||
@@ -11,42 +8,9 @@ const API_RESPONSE = {
|
||||
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', () => {
|
||||
nock('https://slack.com').post('/api/chat.delete').reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/message/delete.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(
|
||||
'POST',
|
||||
'/chat.delete',
|
||||
{ channel: 'C08514ZPKB8', ts: '1734322671.726339' },
|
||||
{},
|
||||
);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
@@ -11,42 +8,11 @@ const API_RESPONSE = {
|
||||
channel: 'C08514ZPKB8',
|
||||
};
|
||||
|
||||
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, message => getPermalink', () => {
|
||||
nock('https://slack.com')
|
||||
.get('/api/chat.getPermalink?channel=C08514ZPKB8&message_ts=1734322671.726339')
|
||||
.reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/message/getPermalink.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',
|
||||
'/chat.getPermalink',
|
||||
{},
|
||||
{ channel: 'C08514ZPKB8', message_ts: '1734322671.726339' },
|
||||
);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
@@ -50,51 +47,20 @@ const API_RESPONSE = {
|
||||
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 => post', () => {
|
||||
nock('https://slack.com')
|
||||
.post('/api/chat.postMessage', {
|
||||
channel: 'C08514ZPKB8',
|
||||
icon_emoji: '😁',
|
||||
includeLinkToWorkflow: false,
|
||||
link_names: true,
|
||||
mrkdwn: true,
|
||||
text: 'test message',
|
||||
unfurl_links: true,
|
||||
unfurl_media: true,
|
||||
})
|
||||
.reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/message/post.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(
|
||||
'POST',
|
||||
'/chat.postMessage',
|
||||
{
|
||||
channel: 'C08514ZPKB8',
|
||||
icon_emoji: '😁',
|
||||
includeLinkToWorkflow: false,
|
||||
link_names: true,
|
||||
mrkdwn: true,
|
||||
text: 'test message',
|
||||
unfurl_links: true,
|
||||
unfurl_media: true,
|
||||
},
|
||||
{},
|
||||
);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
@@ -203,42 +200,11 @@ const API_RESPONSE = {
|
||||
},
|
||||
};
|
||||
|
||||
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 => search', () => {
|
||||
nock('https://slack.com')
|
||||
.post('/api/search.messages?query=test%20in%3Atest-002&sort=timestamp&sort_dir=desc&count=2')
|
||||
.reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/message/search.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(
|
||||
'POST',
|
||||
'/search.messages',
|
||||
{},
|
||||
{ count: 2, query: 'test in:test-002', sort: 'timestamp', sort_dir: 'desc' },
|
||||
);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
@@ -54,48 +51,17 @@ const API_RESPONSE = {
|
||||
message_timestamp: '1734321960.507649',
|
||||
};
|
||||
|
||||
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 => update', () => {
|
||||
nock('https://slack.com')
|
||||
.post('/api/chat.update', {
|
||||
channel: 'C08514ZPKB8',
|
||||
link_names: true,
|
||||
parse: 'none',
|
||||
text: 'updated message',
|
||||
ts: '1734321960.507649',
|
||||
})
|
||||
.reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/message/update.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(
|
||||
'POST',
|
||||
'/chat.update',
|
||||
{
|
||||
channel: 'C08514ZPKB8',
|
||||
link_names: true,
|
||||
parse: 'none',
|
||||
text: 'updated message',
|
||||
ts: '1734321960.507649',
|
||||
},
|
||||
{},
|
||||
);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user