Files
n8n/packages/nodes-base/nodes/HighLevel/v2/test/HighLevelApiPagination.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

104 lines
2.7 KiB
TypeScript

import type { IExecutePaginationFunctions } from 'n8n-workflow';
import { highLevelApiPagination } from '../GenericFunctions';
describe('highLevelApiPagination', () => {
let mockContext: Partial<IExecutePaginationFunctions>;
beforeEach(() => {
mockContext = {
getNodeParameter: jest.fn(),
makeRoutingRequest: jest.fn(),
};
});
it('should paginate and return all items when returnAll is true', async () => {
(mockContext.getNodeParameter as jest.Mock).mockImplementation((parameter) => {
if (parameter === 'resource') return 'contact';
if (parameter === 'returnAll') return true;
});
(mockContext.makeRoutingRequest as jest.Mock)
.mockResolvedValueOnce([
{
json: {
contacts: [{ id: '1' }, { id: '2' }],
meta: { startAfterId: '2', startAfter: 2, total: 4 },
},
},
])
.mockResolvedValueOnce([
{
json: {
contacts: [{ id: '3' }, { id: '4' }],
meta: { startAfterId: null, startAfter: null, total: 4 },
},
},
]);
const requestData = { options: { qs: {} } } as any;
const result = await highLevelApiPagination.call(
mockContext as IExecutePaginationFunctions,
requestData,
);
expect(result).toEqual([
{ json: { id: '1' } },
{ json: { id: '2' } },
{ json: { id: '3' } },
{ json: { id: '4' } },
]);
});
it('should return only the first page of items when returnAll is false', async () => {
(mockContext.getNodeParameter as jest.Mock).mockImplementation((parameter) => {
if (parameter === 'resource') return 'contact';
if (parameter === 'returnAll') return false;
});
(mockContext.makeRoutingRequest as jest.Mock).mockResolvedValueOnce([
{
json: {
contacts: [{ id: '1' }, { id: '2' }],
meta: { startAfterId: '2', startAfter: 2, total: 4 },
},
},
]);
const requestData = { options: { qs: {} } } as any;
const result = await highLevelApiPagination.call(
mockContext as IExecutePaginationFunctions,
requestData,
);
expect(result).toEqual([{ json: { id: '1' } }, { json: { id: '2' } }]);
});
it('should handle cases with no items', async () => {
(mockContext.getNodeParameter as jest.Mock).mockImplementation((parameter) => {
if (parameter === 'resource') return 'contact';
if (parameter === 'returnAll') return true;
});
(mockContext.makeRoutingRequest as jest.Mock).mockResolvedValueOnce([
{
json: {
contacts: [],
meta: { startAfterId: null, startAfter: null, total: 0 },
},
},
]);
const requestData = { options: { qs: {} } } as any;
const result = await highLevelApiPagination.call(
mockContext as IExecutePaginationFunctions,
requestData,
);
expect(result).toEqual([]);
});
});