mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +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,29 +1,14 @@
|
||||
import type { IHttpRequestMethods } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { equalityTest, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
const API_RESPONSE = {
|
||||
ok: true,
|
||||
};
|
||||
|
||||
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, channel => append', () => {
|
||||
const workflows = ['nodes/Slack/test/v2/node/channel/archive.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
const nodeTypes = setup(tests);
|
||||
nock('https://slack.com').post('/api/conversations.archive').reply(200, API_RESPONSE);
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await equalityTest(testData, nodeTypes));
|
||||
}
|
||||
const workflows = ['nodes/Slack/test/v2/node/channel/archive.workflow.json'];
|
||||
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,
|
||||
@@ -48,42 +45,9 @@ 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, channel => create', () => {
|
||||
nock('https://slack.com').post('/api/conversations.create').reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/channel/create.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',
|
||||
'/conversations.create',
|
||||
{ is_private: false, name: 'test-003' },
|
||||
{},
|
||||
);
|
||||
};
|
||||
|
||||
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,
|
||||
@@ -47,42 +44,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, channel => get', () => {
|
||||
nock('https://slack.com')
|
||||
.post('/api/conversations.info?channel=C085WNEHP4Y')
|
||||
.reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/channel/get.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',
|
||||
'/conversations.info',
|
||||
{},
|
||||
{ channel: 'C085WNEHP4Y' },
|
||||
);
|
||||
};
|
||||
|
||||
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,
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -1,208 +1,176 @@
|
||||
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
|
||||
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
|
||||
import * as genericFunctions from '../../../../V2/GenericFunctions';
|
||||
|
||||
const API_RESPONSE = [
|
||||
{
|
||||
user: 'U0362BXQYJW',
|
||||
type: 'message',
|
||||
ts: '1734322597.935429',
|
||||
bot_id: 'B0382SHFM46',
|
||||
app_id: 'A037UTP0Z39',
|
||||
text: 'test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_',
|
||||
team: 'T0364MSFHV2',
|
||||
bot_profile: {
|
||||
id: 'B0382SHFM46',
|
||||
deleted: false,
|
||||
name: 'blocks-test',
|
||||
updated: 1648028754,
|
||||
const API_RESPONSE = {
|
||||
ok: true,
|
||||
messages: [
|
||||
{
|
||||
user: 'U0362BXQYJW',
|
||||
type: 'message',
|
||||
ts: '1734322597.935429',
|
||||
bot_id: 'B0382SHFM46',
|
||||
app_id: 'A037UTP0Z39',
|
||||
icons: {
|
||||
image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png',
|
||||
image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png',
|
||||
image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png',
|
||||
text: 'test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_',
|
||||
team: 'T0364MSFHV2',
|
||||
bot_profile: {
|
||||
id: 'B0382SHFM46',
|
||||
deleted: false,
|
||||
name: 'blocks-test',
|
||||
updated: 1648028754,
|
||||
app_id: 'A037UTP0Z39',
|
||||
icons: {
|
||||
image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png',
|
||||
image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png',
|
||||
image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png',
|
||||
},
|
||||
team_id: 'T0364MSFHV2',
|
||||
},
|
||||
team_id: 'T0364MSFHV2',
|
||||
blocks: [
|
||||
{
|
||||
type: 'rich_text',
|
||||
block_id: 'piR',
|
||||
elements: [
|
||||
{
|
||||
type: 'rich_text_section',
|
||||
elements: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'test message\n',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Automated with this ',
|
||||
style: {
|
||||
italic: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'link',
|
||||
url: 'http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd',
|
||||
text: 'n8n workflow',
|
||||
style: {
|
||||
italic: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
blocks: [
|
||||
{
|
||||
type: 'rich_text',
|
||||
block_id: 'piR',
|
||||
elements: [
|
||||
{
|
||||
type: 'rich_text_section',
|
||||
elements: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'test message\n',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Automated with this ',
|
||||
style: {
|
||||
italic: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'link',
|
||||
url: 'http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd',
|
||||
text: 'n8n workflow',
|
||||
style: {
|
||||
italic: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
user: 'U0362BXQYJW',
|
||||
type: 'message',
|
||||
ts: '1734322341.161179',
|
||||
bot_id: 'B0382SHFM46',
|
||||
app_id: 'A037UTP0Z39',
|
||||
text: 'test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_',
|
||||
team: 'T0364MSFHV2',
|
||||
bot_profile: {
|
||||
id: 'B0382SHFM46',
|
||||
{
|
||||
user: 'U0362BXQYJW',
|
||||
type: 'message',
|
||||
ts: '1734322341.161179',
|
||||
bot_id: 'B0382SHFM46',
|
||||
app_id: 'A037UTP0Z39',
|
||||
name: 'blocks-test',
|
||||
icons: {
|
||||
image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png',
|
||||
image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png',
|
||||
image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png',
|
||||
text: 'test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_',
|
||||
team: 'T0364MSFHV2',
|
||||
bot_profile: {
|
||||
id: 'B0382SHFM46',
|
||||
app_id: 'A037UTP0Z39',
|
||||
name: 'blocks-test',
|
||||
icons: {
|
||||
image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png',
|
||||
image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png',
|
||||
image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png',
|
||||
},
|
||||
deleted: false,
|
||||
updated: 1648028754,
|
||||
team_id: 'T0364MSFHV2',
|
||||
},
|
||||
deleted: false,
|
||||
updated: 1648028754,
|
||||
team_id: 'T0364MSFHV2',
|
||||
blocks: [
|
||||
{
|
||||
type: 'rich_text',
|
||||
block_id: '2BN',
|
||||
elements: [
|
||||
{
|
||||
type: 'rich_text_section',
|
||||
elements: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'test message\n',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Automated with this ',
|
||||
style: {
|
||||
italic: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'link',
|
||||
url: 'http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd',
|
||||
text: 'n8n workflow',
|
||||
style: {
|
||||
italic: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
blocks: [
|
||||
{
|
||||
type: 'rich_text',
|
||||
block_id: '2BN',
|
||||
elements: [
|
||||
{
|
||||
type: 'rich_text_section',
|
||||
elements: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'test message\n',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Automated with this ',
|
||||
style: {
|
||||
italic: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'link',
|
||||
url: 'http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd',
|
||||
text: 'n8n workflow',
|
||||
style: {
|
||||
italic: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
{
|
||||
user: 'U0362BXQYJW',
|
||||
type: 'message',
|
||||
ts: '1734321960.507649',
|
||||
edited: {
|
||||
user: 'B0382SHFM46',
|
||||
ts: '1734324905.000000',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
user: 'U0362BXQYJW',
|
||||
type: 'message',
|
||||
ts: '1734321960.507649',
|
||||
edited: {
|
||||
user: 'B0382SHFM46',
|
||||
ts: '1734324905.000000',
|
||||
},
|
||||
bot_id: 'B0382SHFM46',
|
||||
app_id: 'A037UTP0Z39',
|
||||
text: 'updated message',
|
||||
team: 'T0364MSFHV2',
|
||||
bot_profile: {
|
||||
id: 'B0382SHFM46',
|
||||
bot_id: 'B0382SHFM46',
|
||||
app_id: 'A037UTP0Z39',
|
||||
name: 'blocks-test',
|
||||
icons: {
|
||||
image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png',
|
||||
image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png',
|
||||
image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png',
|
||||
text: 'updated message',
|
||||
team: 'T0364MSFHV2',
|
||||
bot_profile: {
|
||||
id: 'B0382SHFM46',
|
||||
app_id: 'A037UTP0Z39',
|
||||
name: 'blocks-test',
|
||||
icons: {
|
||||
image_36: 'https://a.slack-edge.com/80588/img/plugins/app/bot_36.png',
|
||||
image_48: 'https://a.slack-edge.com/80588/img/plugins/app/bot_48.png',
|
||||
image_72: 'https://a.slack-edge.com/80588/img/plugins/app/service_72.png',
|
||||
},
|
||||
deleted: false,
|
||||
updated: 1648028754,
|
||||
team_id: 'T0364MSFHV2',
|
||||
},
|
||||
deleted: false,
|
||||
updated: 1648028754,
|
||||
team_id: 'T0364MSFHV2',
|
||||
blocks: [
|
||||
{
|
||||
type: 'rich_text',
|
||||
block_id: 'wR+',
|
||||
elements: [
|
||||
{
|
||||
type: 'rich_text_section',
|
||||
elements: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'updated message',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
blocks: [
|
||||
{
|
||||
type: 'rich_text',
|
||||
block_id: 'wR+',
|
||||
elements: [
|
||||
{
|
||||
type: 'rich_text_section',
|
||||
elements: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'updated message',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
subtype: 'channel_join',
|
||||
user: 'U0362BXQYJW',
|
||||
text: '<@U0362BXQYJW> has joined the channel',
|
||||
type: 'message',
|
||||
ts: '1734321942.689159',
|
||||
},
|
||||
];
|
||||
|
||||
jest.mock('../../../../V2/GenericFunctions', () => {
|
||||
const originalModule = jest.requireActual('../../../../V2/GenericFunctions');
|
||||
return {
|
||||
...originalModule,
|
||||
slackApiRequestAllItems: jest.fn(async function (_: string, method: IHttpRequestMethods) {
|
||||
if (method === 'GET') {
|
||||
return API_RESPONSE;
|
||||
}
|
||||
}),
|
||||
};
|
||||
});
|
||||
{
|
||||
subtype: 'channel_join',
|
||||
user: 'U0362BXQYJW',
|
||||
text: '<@U0362BXQYJW> has joined the channel',
|
||||
type: 'message',
|
||||
ts: '1734321942.689159',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe('Test SlackV2, channel => history', () => {
|
||||
nock('https://slack.com')
|
||||
.get('/api/conversations.history?channel=C08514ZPKB8&inclusive=true&page=1&limit=100')
|
||||
.reply(200, API_RESPONSE);
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/channel/history.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.slackApiRequestAllItems).toHaveBeenCalledTimes(1);
|
||||
expect(genericFunctions.slackApiRequestAllItems).toHaveBeenCalledWith(
|
||||
'messages',
|
||||
'GET',
|
||||
'/conversations.history',
|
||||
{},
|
||||
{ channel: 'C08514ZPKB8', inclusive: true },
|
||||
);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -1,72 +1,16 @@
|
||||
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 = { files: { test: 'OK' } };
|
||||
|
||||
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;
|
||||
}
|
||||
if (method === 'GET') {
|
||||
return { upload_url: 'https://slack.com/api/files.upload' };
|
||||
}
|
||||
}),
|
||||
};
|
||||
});
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test SlackV2, file => upload', () => {
|
||||
nock('https://slack.com')
|
||||
.get('/api/files.getUploadURLExternal?filename=test%20_name.txt&length=25')
|
||||
.reply(200, { ok: true, upload_url: 'https://slack.com/api/files.upload' })
|
||||
.post('/api/files.upload', () => true)
|
||||
.reply(200, { ok: true, file: { id: 'file_id' } })
|
||||
.post('/api/files.completeUploadExternal')
|
||||
.reply(200, { ok: true, files: [{ id: 'file_id' }] });
|
||||
|
||||
const workflows = ['nodes/Slack/test/v2/node/file/upload.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(3);
|
||||
expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/files.getUploadURLExternal',
|
||||
{},
|
||||
{ filename: 'test _name.txt', length: 25 },
|
||||
);
|
||||
|
||||
expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'https://slack.com/api/files.upload',
|
||||
{},
|
||||
{},
|
||||
{ 'Content-Type': 'multipart/form-data' },
|
||||
expect.objectContaining({
|
||||
formData: expect.any(Object),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(genericFunctions.slackApiRequest).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/files.completeUploadExternal',
|
||||
{
|
||||
files: [{ id: undefined, title: 'Test Title' }],
|
||||
initial_comment: 'test inline',
|
||||
thread_ts: '1734322671.726339',
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
"No Operation, do nothing": [
|
||||
{
|
||||
"json": {
|
||||
"test": "OK"
|
||||
"id": "file_id"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -1,60 +1,26 @@
|
||||
import type { 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 = { profile: { test: 'OK' } };
|
||||
|
||||
jest.mock('../../../../V2/GenericFunctions', () => {
|
||||
const originalModule = jest.requireActual('../../../../V2/GenericFunctions');
|
||||
return {
|
||||
...originalModule,
|
||||
slackApiRequest: jest.fn(async function () {
|
||||
return API_RESPONSE;
|
||||
}),
|
||||
};
|
||||
});
|
||||
import { testWorkflows } from '@test/nodes/Helpers';
|
||||
|
||||
describe('Test SlackV2, user => updateProfile', () => {
|
||||
const workflows = ['nodes/Slack/test/v2/node/user/updateProfile.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',
|
||||
'/users.profile.set',
|
||||
{
|
||||
profile: {
|
||||
customFieldUi: {
|
||||
customFieldValues: [{ alt: '', id: 'Xf05SGHVUDKM', value: 'TEST title' }],
|
||||
},
|
||||
email: 'some@email.com',
|
||||
fields: { Xf05SGHVUDKM: { alt: '', value: 'TEST title' } },
|
||||
first_name: 'first',
|
||||
last_name: 'last',
|
||||
status_emoji: '👶',
|
||||
status_expiration: 1734670800,
|
||||
status_text: 'test status',
|
||||
nock('https://slack.com')
|
||||
.post('/api/users.profile.set', {
|
||||
profile: {
|
||||
customFieldUi: {
|
||||
customFieldValues: [{ alt: '', id: 'Xf05SGHVUDKM', value: 'TEST title' }],
|
||||
},
|
||||
user: 'id-new',
|
||||
email: 'some@email.com',
|
||||
fields: { Xf05SGHVUDKM: { alt: '', value: 'TEST title' } },
|
||||
first_name: 'first',
|
||||
last_name: 'last',
|
||||
status_emoji: '👶',
|
||||
status_expiration: 1734670800,
|
||||
status_text: 'test status',
|
||||
},
|
||||
{},
|
||||
);
|
||||
};
|
||||
user: 'id-new',
|
||||
})
|
||||
.reply(200, { profile: { test: 'OK' } });
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => await testNode(testData, nodeTypes));
|
||||
}
|
||||
const workflows = ['nodes/Slack/test/v2/node/user/updateProfile.workflow.json'];
|
||||
testWorkflows(workflows);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user