Files
n8n/packages/nodes-base/nodes/Pipedrive/test/PipedriveTrigger.node.test.ts
alighasami 3d5eaf9445
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
first commit
2026-03-17 16:22:57 +03:30

110 lines
3.3 KiB
TypeScript

import type { IHookFunctions } from 'n8n-workflow';
import { pipedriveApiRequest } from '../GenericFunctions';
import { PipedriveTrigger } from '../PipedriveTrigger.node';
jest.mock('basic-auth');
jest.mock('../GenericFunctions');
describe('PipedriveTrigger', () => {
let pipedriveTrigger: PipedriveTrigger;
let mockHookFunctions: jest.Mocked<IHookFunctions>;
beforeEach(() => {
pipedriveTrigger = new PipedriveTrigger();
mockHookFunctions = {
getNodeWebhookUrl: jest.fn(),
getWorkflowStaticData: jest.fn(),
getNodeParameter: jest.fn(),
getNode: jest.fn().mockReturnValue({ typeVersion: 1.1 }),
} as unknown as jest.Mocked<IHookFunctions>;
});
describe('Webhook Methods', () => {
describe('checkExists', () => {
it('should return true if webhook already exists', async () => {
mockHookFunctions.getNodeWebhookUrl.mockReturnValue('http://test-webhook-url');
mockHookFunctions.getWorkflowStaticData.mockReturnValue({});
mockHookFunctions.getNodeParameter.mockImplementation((param) => {
if (param === 'action') return '*';
if (param === 'entity') return 'deal';
return null;
});
(pipedriveApiRequest as jest.Mock).mockResolvedValue({
data: [
{
id: '123',
subscription_url: 'http://test-webhook-url',
event_action: '*',
event_object: 'deal',
},
],
});
const result =
await pipedriveTrigger.webhookMethods.default.checkExists.call(mockHookFunctions);
expect(result).toBe(true);
expect(mockHookFunctions.getWorkflowStaticData('node').webhookId).toBe('123');
});
it('should return false if no matching webhook exists', async () => {
mockHookFunctions.getNodeWebhookUrl.mockReturnValue('http://test-webhook-url');
mockHookFunctions.getWorkflowStaticData.mockReturnValue({});
mockHookFunctions.getNodeParameter.mockImplementation((param) => {
if (param === 'action') return '*';
if (param === 'entity') return 'deal';
return null;
});
(pipedriveApiRequest as jest.Mock).mockResolvedValue({
data: [
{
subscription_url: 'http://different-url',
event_action: 'create',
event_object: 'person',
},
],
});
const result =
await pipedriveTrigger.webhookMethods.default.checkExists.call(mockHookFunctions);
expect(result).toBe(false);
});
});
describe('create', () => {
it('should create a webhook successfully', async () => {
mockHookFunctions.getNodeWebhookUrl.mockReturnValue('http://test-webhook-url');
mockHookFunctions.getNodeParameter.mockImplementation((param) => {
if (param === 'incomingAuthentication') return 'none';
if (param === 'action') return '*';
if (param === 'entity') return 'deal';
return null;
});
mockHookFunctions.getWorkflowStaticData.mockReturnValue({});
(pipedriveApiRequest as jest.Mock).mockResolvedValue({
data: { id: '123' },
});
const result = await pipedriveTrigger.webhookMethods.default.create.call(mockHookFunctions);
expect(result).toBe(true);
expect(pipedriveApiRequest).toHaveBeenCalledWith(
'POST',
'/webhooks',
expect.objectContaining({
event_action: '*',
event_object: 'deal',
subscription_url: 'http://test-webhook-url',
}),
);
});
});
});
});