fix(Slack Node): Tests (no-changelog) (#12239)

This commit is contained in:
Michael Kret 2024-12-16 11:40:35 +02:00 committed by GitHub
parent 4ae6049d82
commit 1fc9c59a57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 3110 additions and 2 deletions

View file

@ -94,7 +94,7 @@ export const fileFields: INodeProperties[] = [
show: {
operation: ['upload'],
resource: ['file'],
'@version': [2.2],
'@version': [{ _cnd: { gte: 2.2 } }],
},
},
placeholder: '',
@ -139,7 +139,7 @@ export const fileFields: INodeProperties[] = [
},
displayOptions: {
show: {
'@version': [2.2],
'@version': [{ _cnd: { gte: 2.2 } }],
},
},
default: [],

View file

@ -0,0 +1,39 @@
import nock from 'nock';
import type { IHttpRequestMethods } from 'n8n-workflow';
import { equalityTest, setup, workflowToTests } 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);
beforeAll(() => {
nock.disableNetConnect();
});
afterAll(() => {
nock.restore();
jest.unmock('../../../../V2/GenericFunctions');
});
const nodeTypes = setup(tests);
for (const testData of tests) {
test(testData.description, async () => await equalityTest(testData, nodeTypes));
}
});

View file

@ -0,0 +1,89 @@
{
"name": "slack tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"resource": "channel",
"operation": "archive",
"channelId": {
"__rl": true,
"value": "C084ZURRQPL",
"mode": "list",
"cachedResultName": "test-001"
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"ok": true
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "13de7d28-7e93-4602-a4d1-5389e8ccc4dc",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,98 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
const API_RESPONSE = {
ok: true,
channel: {
id: 'C085WNEHP4Y',
name: 'test-003',
is_channel: true,
is_group: false,
is_im: false,
is_mpim: false,
is_private: false,
created: 1734325731,
is_archived: false,
is_general: false,
unlinked: 0,
name_normalized: 'test-003',
is_shared: false,
is_org_shared: false,
is_pending_ext_shared: false,
pending_shared: [],
context_team_id: 'T0364MSFHV2',
updated: 1734325731240,
parent_conversation: null,
creator: 'U0362BXQYJW',
is_ext_shared: false,
shared_team_ids: ['T0364MSFHV2'],
pending_connected_team_ids: [],
is_member: true,
last_read: '0000000000.000000',
topic: {
value: '',
creator: '',
last_set: 0,
},
purpose: {
value: '',
creator: '',
last_set: 0,
},
previous_names: [],
priority: 0,
},
};
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', () => {
const workflows = ['nodes/Slack/test/v2/node/channel/create.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',
'/conversations.create',
{ is_private: false, name: 'test-003' },
{},
);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View file

@ -0,0 +1,119 @@
{
"name": "slack tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"resource": "channel",
"channelId": "test-003"
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"id": "C085WNEHP4Y",
"name": "test-003",
"is_channel": true,
"is_group": false,
"is_im": false,
"is_mpim": false,
"is_private": false,
"created": 1734325731,
"is_archived": false,
"is_general": false,
"unlinked": 0,
"name_normalized": "test-003",
"is_shared": false,
"is_org_shared": false,
"is_pending_ext_shared": false,
"pending_shared": [],
"context_team_id": "T0364MSFHV2",
"updated": 1734325731240,
"parent_conversation": null,
"creator": "U0362BXQYJW",
"is_ext_shared": false,
"shared_team_ids": ["T0364MSFHV2"],
"pending_connected_team_ids": [],
"is_member": true,
"last_read": "0000000000.000000",
"topic": {
"value": "",
"creator": "",
"last_set": 0
},
"purpose": {
"value": "",
"creator": "",
"last_set": 0
},
"previous_names": [],
"priority": 0
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "297d0c4b-32e6-4b08-8818-af5e64762521",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,97 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
const API_RESPONSE = {
ok: true,
channel: {
id: 'C085WNEHP4Y',
name: 'test-003',
is_channel: true,
is_group: false,
is_im: false,
is_mpim: false,
is_private: false,
created: 1734325731,
is_archived: false,
is_general: false,
unlinked: 0,
name_normalized: 'test-003',
is_shared: false,
is_org_shared: false,
is_pending_ext_shared: false,
pending_shared: [],
context_team_id: 'T0364MSFHV2',
updated: 1734325731240,
parent_conversation: null,
creator: 'U0362BXQYJW',
is_ext_shared: false,
shared_team_ids: ['T0364MSFHV2'],
pending_connected_team_ids: [],
is_member: true,
last_read: '0000000000.000000',
topic: {
value: '',
creator: '',
last_set: 0,
},
purpose: {
value: '',
creator: '',
last_set: 0,
},
previous_names: [],
},
};
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', () => {
const workflows = ['nodes/Slack/test/v2/node/channel/get.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',
'/conversations.info',
{},
{ channel: 'C085WNEHP4Y' },
);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View file

@ -0,0 +1,127 @@
{
"name": "slack tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"resource": "channel",
"operation": "get",
"channelId": {
"__rl": true,
"value": "C085WNEHP4Y",
"mode": "list",
"cachedResultName": "test-003"
},
"options": {
"includeNumMembers": true
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"id": "C085WNEHP4Y",
"name": "test-003",
"is_channel": true,
"is_group": false,
"is_im": false,
"is_mpim": false,
"is_private": false,
"created": 1734325731,
"is_archived": false,
"is_general": false,
"unlinked": 0,
"name_normalized": "test-003",
"is_shared": false,
"is_org_shared": false,
"is_pending_ext_shared": false,
"pending_shared": [],
"context_team_id": "T0364MSFHV2",
"updated": 1734325731240,
"parent_conversation": null,
"creator": "U0362BXQYJW",
"is_ext_shared": false,
"shared_team_ids": ["T0364MSFHV2"],
"pending_connected_team_ids": [],
"is_member": true,
"last_read": "0000000000.000000",
"topic": {
"value": "",
"creator": "",
"last_set": 0
},
"purpose": {
"value": "",
"creator": "",
"last_set": 0
},
"previous_names": []
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "753332eb-25d1-443a-acef-92993e89751a",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,160 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
const API_RESPONSE = {
ok: true,
channels: [
{
id: 'C0362BX17TM',
name: 'general',
is_channel: true,
is_group: false,
is_im: false,
is_mpim: false,
is_private: false,
created: 1646724991,
is_archived: false,
is_general: true,
unlinked: 0,
name_normalized: 'general',
is_shared: false,
is_org_shared: false,
is_pending_ext_shared: false,
pending_shared: [],
context_team_id: 'T0364MSFHV2',
updated: 1734075560630,
parent_conversation: null,
creator: 'U0362BXQYJW',
is_ext_shared: false,
shared_team_ids: ['T0364MSFHV2'],
pending_connected_team_ids: [],
is_member: true,
topic: {
value: '',
creator: '',
last_set: 0,
},
purpose: {
value:
'This is the one channel that will always include everyone. Its a great spot for announcements and team-wide conversations.',
creator: 'U0362BXQYJW',
last_set: 1646724991,
},
properties: {
use_case: 'welcome',
},
previous_names: [],
num_members: 1,
},
{
id: 'C0362BXRZQA',
name: 'random',
is_channel: true,
is_group: false,
is_im: false,
is_mpim: false,
is_private: false,
created: 1646724991,
is_archived: false,
is_general: false,
unlinked: 0,
name_normalized: 'random',
is_shared: false,
is_org_shared: false,
is_pending_ext_shared: false,
pending_shared: [],
context_team_id: 'T0364MSFHV2',
updated: 1725415586388,
parent_conversation: null,
creator: 'U0362BXQYJW',
is_ext_shared: false,
shared_team_ids: ['T0364MSFHV2'],
pending_connected_team_ids: [],
is_member: true,
topic: {
value: '',
creator: '',
last_set: 0,
},
purpose: {
value:
'This channel is for... well, everything else. Its a place for team jokes, spur-of-the-moment ideas, and funny GIFs. Go wild!',
creator: 'U0362BXQYJW',
last_set: 1646724991,
},
properties: {
tabs: [
{
id: 'files',
label: '',
type: 'files',
},
],
tabz: [
{
type: 'files',
},
],
use_case: 'random',
},
previous_names: [],
num_members: 2,
},
],
response_metadata: {
next_cursor: 'dGVhbTpDMDM2MkMyM1RSOA==',
},
};
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', () => {
const workflows = ['nodes/Slack/test/v2/node/channel/getAll.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(
'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));
}
});

View file

@ -0,0 +1,181 @@
{
"name": "slack new tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"resource": "channel",
"operation": "getAll",
"limit": 2,
"filters": {
"excludeArchived": true,
"types": ["public_channel", "private_channel", "im", "mpim"]
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"id": "C0362BX17TM",
"name": "general",
"is_channel": true,
"is_group": false,
"is_im": false,
"is_mpim": false,
"is_private": false,
"created": 1646724991,
"is_archived": false,
"is_general": true,
"unlinked": 0,
"name_normalized": "general",
"is_shared": false,
"is_org_shared": false,
"is_pending_ext_shared": false,
"pending_shared": [],
"context_team_id": "T0364MSFHV2",
"updated": 1734075560630,
"parent_conversation": null,
"creator": "U0362BXQYJW",
"is_ext_shared": false,
"shared_team_ids": ["T0364MSFHV2"],
"pending_connected_team_ids": [],
"is_member": true,
"topic": {
"value": "",
"creator": "",
"last_set": 0
},
"purpose": {
"value": "This is the one channel that will always include everyone. Its a great spot for announcements and team-wide conversations.",
"creator": "U0362BXQYJW",
"last_set": 1646724991
},
"properties": {
"use_case": "welcome"
},
"previous_names": [],
"num_members": 1
}
},
{
"json": {
"id": "C0362BXRZQA",
"name": "random",
"is_channel": true,
"is_group": false,
"is_im": false,
"is_mpim": false,
"is_private": false,
"created": 1646724991,
"is_archived": false,
"is_general": false,
"unlinked": 0,
"name_normalized": "random",
"is_shared": false,
"is_org_shared": false,
"is_pending_ext_shared": false,
"pending_shared": [],
"context_team_id": "T0364MSFHV2",
"updated": 1725415586388,
"parent_conversation": null,
"creator": "U0362BXQYJW",
"is_ext_shared": false,
"shared_team_ids": ["T0364MSFHV2"],
"pending_connected_team_ids": [],
"is_member": true,
"topic": {
"value": "",
"creator": "",
"last_set": 0
},
"purpose": {
"value": "This channel is for... well, everything else. Its a place for team jokes, spur-of-the-moment ideas, and funny GIFs. Go wild!",
"creator": "U0362BXQYJW",
"last_set": 1646724991
},
"properties": {
"tabs": [
{
"id": "files",
"label": "",
"type": "files"
}
],
"tabz": [
{
"type": "files"
}
],
"use_case": "random"
},
"previous_names": [],
"num_members": 2
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "f74e9c2c-83f4-4ef8-b436-704e1a27a9ef",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,217 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
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&amp;utm_medium=powered_by&amp;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',
},
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&amp;utm_medium=powered_by&amp;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&amp;utm_medium=powered_by&amp;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',
},
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&amp;utm_medium=powered_by&amp;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',
},
bot_id: 'B0382SHFM46',
app_id: 'A037UTP0Z39',
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',
},
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;
}
}),
};
});
describe('Test SlackV2, channel => history', () => {
const workflows = ['nodes/Slack/test/v2/node/channel/history.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.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));
}
});

View file

@ -0,0 +1,254 @@
{
"name": "slack new tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"resource": "channel",
"operation": "history",
"channelId": {
"__rl": true,
"value": "C08514ZPKB8",
"mode": "list",
"cachedResultName": "test-002"
},
"returnAll": true,
"filters": {
"inclusive": true
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"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&amp;utm_medium=powered_by&amp;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"
},
"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&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd",
"text": "n8n workflow",
"style": {
"italic": true
}
}
]
}
]
}
]
}
},
{
"json": {
"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&amp;utm_medium=powered_by&amp;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"
},
"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&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd",
"text": "n8n workflow",
"style": {
"italic": true
}
}
]
}
]
}
]
}
},
{
"json": {
"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",
"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"
},
"blocks": [
{
"type": "rich_text",
"block_id": "wR+",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "updated message"
}
]
}
]
}
]
}
},
{
"json": {
"subtype": "channel_join",
"user": "U0362BXQYJW",
"text": "<@U0362BXQYJW> has joined the channel",
"type": "message",
"ts": "1734321942.689159"
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "6b7102c7-d3c5-4b88-b67d-4ee6ae51b581",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,81 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
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' };
}
}),
};
});
describe('Test SlackV2, file => upload', () => {
const workflows = ['nodes/Slack/test/v2/node/file/upload.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(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));
}
});

View file

@ -0,0 +1,147 @@
{
"name": "slack new tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [440, 360]
},
{
"parameters": {
"resource": "file",
"options": {
"fileName": "test _name.txt",
"initialComment": "test inline",
"threadTs": "1734322671.726339",
"title": "Test Title"
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1100, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1320, 360]
},
{
"parameters": {
"operation": "toJson",
"options": {}
},
"id": "76e317ed-7f2b-46b9-8c9b-f91a0b5d0fdd",
"name": "Convert to File",
"type": "n8n-nodes-base.convertToFile",
"typeVersion": 1.1,
"position": [860, 360]
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "a60db675-c351-49fc-bbad-555a70ee5d6d",
"name": "f1",
"value": "123",
"type": "string"
},
{
"id": "b96e7f11-a0ea-4a7f-b803-5ab3238af054",
"name": "f2",
"value": "456",
"type": "string"
}
]
},
"options": {}
},
"id": "773453a7-2bdc-4d50-a3e6-be5e1b86d820",
"name": "Edit Fields",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [660, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"test": "OK"
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"Convert to File": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "Convert to File",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "3a19732a-4416-487c-9f76-1291c610b5d1",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,61 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
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));
}
});

View file

@ -0,0 +1,92 @@
{
"name": "slack tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"operation": "delete",
"select": "channel",
"channelId": {
"__rl": true,
"value": "C08514ZPKB8",
"mode": "list",
"cachedResultName": "test-002"
},
"timestamp": 1734322671.726339
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"ok": true,
"channel": "C08514ZPKB8",
"message_timestamp": "1734322671.726339"
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "cf10cd01-6650-48ca-b4a2-ec07be9d026c",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,61 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
const API_RESPONSE = {
ok: true,
permalink: 'https://myspace-qhg7381.slack.com/archives/C08514ZPKB8/p1734322671726339',
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', () => {
const workflows = ['nodes/Slack/test/v2/node/message/getPermalink.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(
'GET',
'/chat.getPermalink',
{},
{ channel: 'C08514ZPKB8', message_ts: '1734322671.726339' },
);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View file

@ -0,0 +1,91 @@
{
"name": "slack tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"operation": "getPermalink",
"channelId": {
"__rl": true,
"value": "C08514ZPKB8",
"mode": "list",
"cachedResultName": "test-002"
},
"timestamp": 1734322671.726339
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"ok": true,
"permalink": "https://myspace-qhg7381.slack.com/archives/C08514ZPKB8/p1734322671726339",
"channel": "C08514ZPKB8"
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "64c251c3-afe5-4636-a3fc-de769f8a9ea0",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,109 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
const API_RESPONSE = {
ok: true,
channel: 'C08514ZPKB8',
message: {
user: 'U0362BXQYJW',
type: 'message',
ts: '1734322671.726339',
bot_id: 'B0382SHFM46',
app_id: 'A037UTP0Z39',
text: 'test 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',
},
blocks: [
{
type: 'rich_text',
block_id: 't02Ox',
elements: [
{
type: 'rich_text_section',
elements: [
{
type: 'text',
text: 'test message',
},
],
},
],
},
],
},
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', () => {
const workflows = ['nodes/Slack/test/v2/node/message/post.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.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));
}
});

View file

@ -0,0 +1,143 @@
{
"name": "slack tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"select": "channel",
"channelId": {
"__rl": true,
"value": "C08514ZPKB8",
"mode": "list",
"cachedResultName": "test-002"
},
"text": "test message",
"otherOptions": {
"includeLinkToWorkflow": false,
"botProfile": {
"imageValues": {
"profilePhotoType": "emoji",
"icon_emoji": "😁"
}
},
"link_names": true,
"mrkdwn": true,
"unfurl_links": true,
"unfurl_media": true
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"ok": true,
"channel": "C08514ZPKB8",
"message": {
"user": "U0362BXQYJW",
"type": "message",
"ts": "1734322671.726339",
"bot_id": "B0382SHFM46",
"app_id": "A037UTP0Z39",
"text": "test 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"
},
"blocks": [
{
"type": "rich_text",
"block_id": "t02Ox",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "test message"
}
]
}
]
}
]
},
"message_timestamp": "1734322671.726339"
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "2bc19572-58f0-4cb9-91c3-78b4b3e0cd95",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,253 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
const API_RESPONSE = {
ok: true,
query: 'test in:test-002',
messages: {
total: 3,
pagination: {
total_count: 3,
page: 1,
per_page: 2,
page_count: 1,
first: 1,
last: 3,
},
paging: {
count: 2,
total: 3,
page: 1,
pages: 1,
},
matches: [
{
iid: 'a60ff37e-5653-4c53-8a44-783ea4315476',
team: 'T0364MSFHV2',
score: 0,
channel: {
id: 'C08514ZPKB8',
is_channel: true,
is_group: false,
is_im: false,
is_mpim: false,
is_shared: false,
is_org_shared: false,
is_ext_shared: false,
is_private: false,
name: 'test-002',
pending_shared: [],
is_pending_ext_shared: false,
},
type: 'message',
user: 'U0362BXQYJW',
username: 'michael.k',
ts: '1734322597.935429',
blocks: [
{
type: 'rich_text',
block_id: '+bc',
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&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd',
text: 'n8n workflow',
style: {
italic: true,
},
},
],
},
],
},
],
text: 'test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_',
permalink: 'https://myspace-qhg7381.slack.com/archives/C08514ZPKB8/p1734322597935429',
no_reactions: true,
},
{
iid: '96ee0d2e-1a7d-40bf-b4b2-71ee15f004a8',
team: 'T0364MSFHV2',
score: 0,
channel: {
id: 'C08514ZPKB8',
is_channel: true,
is_group: false,
is_im: false,
is_mpim: false,
is_shared: false,
is_org_shared: false,
is_ext_shared: false,
is_private: false,
name: 'test-002',
pending_shared: [],
is_pending_ext_shared: false,
},
type: 'message',
user: 'U0362BXQYJW',
username: 'michael.k',
ts: '1734322341.161179',
blocks: [
{
type: 'rich_text',
block_id: 'FGAKN',
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&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd',
text: 'n8n workflow',
style: {
italic: true,
},
},
],
},
],
},
],
text: 'test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_',
permalink: 'https://myspace-qhg7381.slack.com/archives/C08514ZPKB8/p1734322341161179',
no_reactions: true,
},
{
iid: '72f79902-65f7-4bf3-b64b-3fd0b0c3746c',
team: 'T0364MSFHV2',
score: 0,
channel: {
id: 'C08514ZPKB8',
is_channel: true,
is_group: false,
is_im: false,
is_mpim: false,
is_shared: false,
is_org_shared: false,
is_ext_shared: false,
is_private: false,
name: 'test-002',
pending_shared: [],
is_pending_ext_shared: false,
},
type: 'message',
user: 'U0362BXQYJW',
username: 'michael.k',
ts: '1734321960.507649',
blocks: [
{
type: 'rich_text',
block_id: 'fnjm',
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&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd',
text: 'n8n workflow',
style: {
italic: true,
},
},
],
},
],
},
],
text: 'test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_',
permalink: 'https://myspace-qhg7381.slack.com/archives/C08514ZPKB8/p1734321960507649',
no_reactions: 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, message => search', () => {
const workflows = ['nodes/Slack/test/v2/node/message/search.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',
'/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));
}
});

View file

@ -0,0 +1,262 @@
{
"name": "slack tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"operation": "search",
"query": "test",
"limit": 2,
"options": {
"searchChannel": ["test-002"]
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"iid": "a60ff37e-5653-4c53-8a44-783ea4315476",
"team": "T0364MSFHV2",
"score": 0,
"channel": {
"id": "C08514ZPKB8",
"is_channel": true,
"is_group": false,
"is_im": false,
"is_mpim": false,
"is_shared": false,
"is_org_shared": false,
"is_ext_shared": false,
"is_private": false,
"name": "test-002",
"pending_shared": [],
"is_pending_ext_shared": false
},
"type": "message",
"user": "U0362BXQYJW",
"username": "michael.k",
"ts": "1734322597.935429",
"blocks": [
{
"type": "rich_text",
"block_id": "+bc",
"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&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd",
"text": "n8n workflow",
"style": {
"italic": true
}
}
]
}
]
}
],
"text": "test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_",
"permalink": "https://myspace-qhg7381.slack.com/archives/C08514ZPKB8/p1734322597935429",
"no_reactions": true
}
},
{
"json": {
"iid": "96ee0d2e-1a7d-40bf-b4b2-71ee15f004a8",
"team": "T0364MSFHV2",
"score": 0,
"channel": {
"id": "C08514ZPKB8",
"is_channel": true,
"is_group": false,
"is_im": false,
"is_mpim": false,
"is_shared": false,
"is_org_shared": false,
"is_ext_shared": false,
"is_private": false,
"name": "test-002",
"pending_shared": [],
"is_pending_ext_shared": false
},
"type": "message",
"user": "U0362BXQYJW",
"username": "michael.k",
"ts": "1734322341.161179",
"blocks": [
{
"type": "rich_text",
"block_id": "FGAKN",
"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&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd",
"text": "n8n workflow",
"style": {
"italic": true
}
}
]
}
]
}
],
"text": "test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_",
"permalink": "https://myspace-qhg7381.slack.com/archives/C08514ZPKB8/p1734322341161179",
"no_reactions": true
}
},
{
"json": {
"iid": "72f79902-65f7-4bf3-b64b-3fd0b0c3746c",
"team": "T0364MSFHV2",
"score": 0,
"channel": {
"id": "C08514ZPKB8",
"is_channel": true,
"is_group": false,
"is_im": false,
"is_mpim": false,
"is_shared": false,
"is_org_shared": false,
"is_ext_shared": false,
"is_private": false,
"name": "test-002",
"pending_shared": [],
"is_pending_ext_shared": false
},
"type": "message",
"user": "U0362BXQYJW",
"username": "michael.k",
"ts": "1734321960.507649",
"blocks": [
{
"type": "rich_text",
"block_id": "fnjm",
"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&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd",
"text": "n8n workflow",
"style": {
"italic": true
}
}
]
}
]
}
],
"text": "test message\n_Automated with this <http://localhost:5678/workflow/qJdEfiBgYLdfYOTs?utm_source=n8n-internal&amp;utm_medium=powered_by&amp;utm_campaign=n8n-nodes-base.slack_be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd|n8n workflow>_",
"permalink": "https://myspace-qhg7381.slack.com/archives/C08514ZPKB8/p1734321960507649",
"no_reactions": true
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "0ea58133-0522-40ae-ab51-ec3c1eced057",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,110 @@
import nock from 'nock';
import type { IHttpRequestMethods, INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
const API_RESPONSE = {
ok: true,
channel: 'C08514ZPKB8',
text: 'updated message',
message: {
user: 'U0362BXQYJW',
type: 'message',
edited: {
user: 'B0382SHFM46',
ts: '1734324905.000000',
},
bot_id: 'B0382SHFM46',
app_id: 'A037UTP0Z39',
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',
},
blocks: [
{
type: 'rich_text',
block_id: 'Akc',
elements: [
{
type: 'rich_text_section',
elements: [
{
type: 'text',
text: 'updated message',
},
],
},
],
},
],
},
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', () => {
const workflows = ['nodes/Slack/test/v2/node/message/update.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.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));
}
});

View file

@ -0,0 +1,142 @@
{
"name": "slack tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"operation": "update",
"channelId": {
"__rl": true,
"value": "C08514ZPKB8",
"mode": "list",
"cachedResultName": "test-002"
},
"ts": 1734321960.507649,
"text": "updated message",
"updateFields": {
"link_names": true,
"parse": "none"
},
"otherOptions": {
"includeLinkToWorkflow": false
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"ok": true,
"channel": "C08514ZPKB8",
"text": "updated message",
"message": {
"user": "U0362BXQYJW",
"type": "message",
"edited": {
"user": "B0382SHFM46",
"ts": "1734324905.000000"
},
"bot_id": "B0382SHFM46",
"app_id": "A037UTP0Z39",
"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"
},
"blocks": [
{
"type": "rich_text",
"block_id": "Akc",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "updated message"
}
]
}
]
}
]
},
"message_timestamp": "1734321960.507649"
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "27133240-8ff6-4115-b330-9cbc9aa95b25",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}

View file

@ -0,0 +1,69 @@
import nock from 'nock';
import type { INodeTypes, WorkflowTestData } from 'n8n-workflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import * as genericFunctions from '../../../../V2/GenericFunctions';
import { executeWorkflow } from '../../../../../../test/nodes/ExecuteWorkflow';
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;
}),
};
});
describe('Test SlackV2, user => updateProfile', () => {
const workflows = ['nodes/Slack/test/v2/node/user/updateProfile.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',
'/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',
},
user: 'id-new',
},
{},
);
};
for (const testData of tests) {
test(testData.description, async () => await testNode(testData, nodeTypes));
}
});

View file

@ -0,0 +1,106 @@
{
"name": "slack new tests",
"nodes": [
{
"parameters": {},
"id": "e679c883-1839-47dc-9511-8f7dc370e6b0",
"name": "When clicking Test workflow",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [820, 360]
},
{
"parameters": {
"resource": "user",
"operation": "updateProfile",
"options": {
"customFieldUi": {
"customFieldValues": [
{
"id": "Xf05SGHVUDKM",
"value": "TEST title"
}
]
},
"email": "some@email.com",
"first_name": "first",
"last_name": "last",
"status": {
"set_status": [
{
"status_emoji": "👶",
"status_expiration": "2024-12-20T00:00:00",
"status_text": "test status"
}
]
},
"user": "id-new"
}
},
"id": "2e1937a6-4c8f-4cd1-ae42-11b2bd12cc4c",
"name": "Slack",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.3,
"position": [1040, 360],
"webhookId": "04c5e584-45f4-48d0-bcd2-0ecacecb0f53",
"credentials": {
"slackApi": {
"id": "Bg0bWXf8apAimCqJ",
"name": "Slack account 2"
}
}
},
{
"parameters": {},
"id": "06652908-6b8e-443a-9508-ab229b011b73",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1260, 360]
}
],
"pinData": {
"No Operation, do nothing": [
{
"json": {
"test": "OK"
}
}
]
},
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "Slack",
"type": "main",
"index": 0
}
]
]
},
"Slack": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "297af4ef-eca5-493d-8a1f-c735fcb805f2",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "be251a83c052a9862eeac953816fbb1464f89dfbf79d7ac490a8e336a8cc8bfd"
},
"id": "qJdEfiBgYLdfYOTs",
"tags": []
}