mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat: Human in the loop (#10675)
Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
This commit is contained in:
146
packages/nodes-base/nodes/Slack/test/v2/utils.test.ts
Normal file
146
packages/nodes-base/nodes/Slack/test/v2/utils.test.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
import { type MockProxy, mock } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
import { getTarget, createSendAndWaitMessageBody } from '../../V2/GenericFunctions';
|
||||
|
||||
describe('Slack Utility Functions', () => {
|
||||
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
|
||||
|
||||
beforeEach(() => {
|
||||
mockExecuteFunctions = mock<IExecuteFunctions>();
|
||||
mockExecuteFunctions.getNode.mockReturnValue({ name: 'Slack', typeVersion: 1 } as any);
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('getTarget', () => {
|
||||
it('should return corect target id', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockImplementation((parameterName: string) => {
|
||||
if (parameterName === 'user') {
|
||||
return 'testUser';
|
||||
}
|
||||
return 'testChannel';
|
||||
});
|
||||
expect(getTarget(mockExecuteFunctions, 0, 'channel')).toEqual('testChannel');
|
||||
|
||||
expect(getTarget(mockExecuteFunctions, 0, 'user')).toEqual('testUser');
|
||||
});
|
||||
});
|
||||
|
||||
describe('createSendAndWaitMessageBody', () => {
|
||||
it('should create message with single button', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('channel');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('channelID');
|
||||
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('message');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('subject');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('localhost');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('node123');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
||||
|
||||
expect(createSendAndWaitMessageBody(mockExecuteFunctions)).toEqual({
|
||||
blocks: [
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
text: {
|
||||
emoji: true,
|
||||
text: 'message',
|
||||
type: 'plain_text',
|
||||
},
|
||||
type: 'section',
|
||||
},
|
||||
{
|
||||
text: {
|
||||
text: ' ',
|
||||
type: 'plain_text',
|
||||
},
|
||||
type: 'section',
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
elements: [
|
||||
{
|
||||
style: 'primary',
|
||||
text: {
|
||||
emoji: true,
|
||||
text: 'Approve',
|
||||
type: 'plain_text',
|
||||
},
|
||||
type: 'button',
|
||||
url: 'localhost/node123?approved=true',
|
||||
},
|
||||
],
|
||||
type: 'actions',
|
||||
},
|
||||
],
|
||||
channel: 'channelID',
|
||||
});
|
||||
});
|
||||
|
||||
it('should create message with double buttona', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('channel');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('channelID');
|
||||
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('message');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('subject');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('localhost');
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('node123');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({ approvalType: 'double' });
|
||||
|
||||
expect(createSendAndWaitMessageBody(mockExecuteFunctions)).toEqual({
|
||||
blocks: [
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
text: {
|
||||
emoji: true,
|
||||
text: 'message',
|
||||
type: 'plain_text',
|
||||
},
|
||||
type: 'section',
|
||||
},
|
||||
{
|
||||
text: {
|
||||
text: ' ',
|
||||
type: 'plain_text',
|
||||
},
|
||||
type: 'section',
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
elements: [
|
||||
{
|
||||
style: undefined,
|
||||
text: {
|
||||
emoji: true,
|
||||
text: 'Disapprove',
|
||||
type: 'plain_text',
|
||||
},
|
||||
type: 'button',
|
||||
url: 'localhost/node123?approved=false',
|
||||
},
|
||||
|
||||
{
|
||||
style: 'primary',
|
||||
text: {
|
||||
emoji: true,
|
||||
text: 'Approve',
|
||||
type: 'plain_text',
|
||||
},
|
||||
type: 'button',
|
||||
url: 'localhost/node123?approved=true',
|
||||
},
|
||||
],
|
||||
type: 'actions',
|
||||
},
|
||||
],
|
||||
channel: 'channelID',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user