first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,97 @@
import type { MockProxy } from 'jest-mock-extended';
import { mock } from 'jest-mock-extended';
import { type IExecuteFunctions } from 'n8n-workflow';
import * as googleHelpers from '../../GenericFunctions';
import { googleApiRequest } from '../GenericFunctions';
jest.mock('../../GenericFunctions', () => ({
...jest.requireActual('../../GenericFunctions'),
getGoogleAccessToken: jest.fn().mockResolvedValue({ access_token: 'mock-access-token' }),
}));
describe('Test GoogleChat, googleApiRequest', () => {
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
beforeEach(() => {
mockExecuteFunctions = mock<IExecuteFunctions>();
mockExecuteFunctions.helpers = {
requestWithAuthentication: jest.fn().mockResolvedValue({}),
request: jest.fn().mockResolvedValue({}),
} as any;
});
afterEach(() => {
jest.clearAllMocks();
});
it('should call requestWithAuthentication when authentication set to OAuth2', async () => {
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('oAuth2'); // authentication
const result = await googleApiRequest.call(mockExecuteFunctions, 'POST', '/test-resource', {
text: 'test',
});
expect(result).toEqual({ success: true });
expect(mockExecuteFunctions.helpers.requestWithAuthentication).toHaveBeenCalledTimes(1);
expect(mockExecuteFunctions.helpers.requestWithAuthentication).toHaveBeenCalledWith(
'googleChatOAuth2Api',
{
body: { text: 'test' },
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
json: true,
method: 'POST',
qs: {},
qsStringifyOptions: { arrayFormat: 'repeat' },
uri: 'https://chat.googleapis.com/test-resource',
},
);
});
it('should call request when authentication set to serviceAccount', async () => {
const mockCredentials = {
email: 'test@example.com',
privateKey: 'private-key',
};
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('serviceAccount');
mockExecuteFunctions.getCredentials.mockResolvedValueOnce(mockCredentials);
const result = await googleApiRequest.call(mockExecuteFunctions, 'GET', '/test-resource');
expect(googleHelpers.getGoogleAccessToken).toHaveBeenCalledWith(mockCredentials, 'chat');
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledWith(
expect.objectContaining({
headers: expect.objectContaining({
Authorization: 'Bearer mock-access-token',
}),
}),
);
expect(result).toEqual({ success: true });
});
it('should call request when noCredentials equals true', async () => {
const result = await googleApiRequest.call(
mockExecuteFunctions,
'GET',
'/test-resource',
{},
{},
undefined,
true,
);
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledTimes(1);
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledWith({
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
json: true,
method: 'GET',
qs: {},
qsStringifyOptions: { arrayFormat: 'repeat' },
uri: 'https://chat.googleapis.com/test-resource',
});
expect(result).toEqual({ success: true });
});
});
@@ -0,0 +1,62 @@
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.getSignedResumeUrl.mockReturnValue(
'http://localhost/waiting-webhook/nodeID?approved=true&signature=abc',
);
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // approvalOptions
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); // options
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&signature=abc|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.googleChat_instanceId|n8n>_',
});
});
});