mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Slack Node): Update wait for approval to use markdown (#11754)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { type MockProxy, mock } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import { getTarget, createSendAndWaitMessageBody } from '../../V2/GenericFunctions';
|
||||
|
||||
describe('Slack Utility Functions', () => {
|
||||
@@ -12,7 +13,7 @@ describe('Slack Utility Functions', () => {
|
||||
});
|
||||
|
||||
describe('getTarget', () => {
|
||||
it('should return corect target id', () => {
|
||||
it('should return correct target id', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockImplementation((parameterName: string) => {
|
||||
if (parameterName === 'user') {
|
||||
return 'testUser';
|
||||
@@ -26,7 +27,7 @@ describe('Slack Utility Functions', () => {
|
||||
});
|
||||
|
||||
describe('createSendAndWaitMessageBody', () => {
|
||||
it('should create message with single button', () => {
|
||||
it('should create message with single button - pre 2.3 plain_text', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('channel');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('channelID');
|
||||
|
||||
@@ -79,7 +80,7 @@ describe('Slack Utility Functions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should create message with double buttona', () => {
|
||||
it('should create message with double buttons - pre 2.3 plain_text', () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('channel');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('channelID');
|
||||
|
||||
@@ -142,5 +143,123 @@ describe('Slack Utility Functions', () => {
|
||||
channel: 'channelID',
|
||||
});
|
||||
});
|
||||
|
||||
it('should create message with single button - 2.3+ mrkdwn', () => {
|
||||
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({});
|
||||
mockExecuteFunctions.getNode.mockReturnValue({ name: 'Slack', typeVersion: 2.3 } as any);
|
||||
|
||||
expect(createSendAndWaitMessageBody(mockExecuteFunctions)).toEqual({
|
||||
blocks: [
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
text: {
|
||||
text: 'message',
|
||||
type: 'mrkdwn',
|
||||
},
|
||||
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 buttons - 2.3+ mrkdwn', () => {
|
||||
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' });
|
||||
|
||||
mockExecuteFunctions.getNode.mockReturnValue({ name: 'Slack', typeVersion: 2.3 } as any);
|
||||
|
||||
expect(createSendAndWaitMessageBody(mockExecuteFunctions)).toEqual({
|
||||
blocks: [
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
text: {
|
||||
text: 'message',
|
||||
type: 'mrkdwn',
|
||||
},
|
||||
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