mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 09:04:07 -08:00
41228b472d
Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
147 lines
3.8 KiB
TypeScript
147 lines
3.8 KiB
TypeScript
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',
|
|
});
|
|
});
|
|
});
|
|
});
|