mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
61 lines
2.5 KiB
TypeScript
61 lines
2.5 KiB
TypeScript
import type { MockProxy } from 'jest-mock-extended';
|
|
import { mock } from 'jest-mock-extended';
|
|
import { type INode, SEND_AND_WAIT_OPERATION, type IExecuteFunctions } from 'n8n-workflow';
|
|
|
|
import * as genericFunctions from '../../GenericFunctions';
|
|
import { GoogleChat } from '../../GoogleChat.node';
|
|
|
|
jest.mock('../../GenericFunctions', () => {
|
|
const originalModule = jest.requireActual('../../GenericFunctions');
|
|
return {
|
|
...originalModule,
|
|
googleApiRequest: jest.fn(),
|
|
};
|
|
});
|
|
|
|
describe('Test GoogleChat, message => sendAndWait', () => {
|
|
let googleChat: GoogleChat;
|
|
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
|
|
|
|
beforeEach(() => {
|
|
googleChat = new GoogleChat();
|
|
mockExecuteFunctions = mock<IExecuteFunctions>();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should send message and put execution to wait', async () => {
|
|
const items = [{ json: { data: 'test' } }];
|
|
//node
|
|
mockExecuteFunctions.getInputData.mockReturnValue(items);
|
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('message');
|
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(SEND_AND_WAIT_OPERATION);
|
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('spaceID');
|
|
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>());
|
|
mockExecuteFunctions.getInstanceId.mockReturnValue('instanceId');
|
|
|
|
//getSendAndWaitConfig
|
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my message');
|
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject');
|
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook');
|
|
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID');
|
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({});
|
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval');
|
|
|
|
// configureWaitTillDate
|
|
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); //options.limitWaitTime.values
|
|
|
|
const result = await googleChat.execute.call(mockExecuteFunctions);
|
|
|
|
expect(result).toEqual([items]);
|
|
expect(genericFunctions.googleApiRequest).toHaveBeenCalledTimes(1);
|
|
expect(mockExecuteFunctions.putExecutionToWait).toHaveBeenCalledTimes(1);
|
|
|
|
expect(genericFunctions.googleApiRequest).toHaveBeenCalledWith('POST', '/v1/spaceID/messages', {
|
|
text: 'my message\n\n\n*<http://localhost/waiting-webhook/nodeID?approved=true|Approve>*\n\n_This_ _message_ _was_ _sent_ _automatically_ _with_ _<https://n8n.io/?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=n8n-nodes-base.telegram_instanceId|n8n>_',
|
|
});
|
|
});
|
|
});
|