UNPKG

n8n-nodes-highlevelv2

Version:

n8n community node for HighLevel v2 API integration - comprehensive CRM, marketing automation, and business management platform

87 lines 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const GenericFunctions_1 = require("../GenericFunctions"); describe('highLevelApiPagination', () => { let mockContext; beforeEach(() => { mockContext = { getNodeParameter: jest.fn(), makeRoutingRequest: jest.fn(), }; }); it('should paginate and return all items when returnAll is true', async () => { mockContext.getNodeParameter.mockImplementation((parameter) => { if (parameter === 'resource') return 'contact'; if (parameter === 'returnAll') return true; return undefined; }); mockContext.makeRoutingRequest .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: {} } }; const result = await GenericFunctions_1.highLevelApiPagination.call(mockContext, 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.mockImplementation((parameter) => { if (parameter === 'resource') return 'contact'; if (parameter === 'returnAll') return false; return undefined; }); mockContext.makeRoutingRequest.mockResolvedValueOnce([ { json: { contacts: [{ id: '1' }, { id: '2' }], meta: { startAfterId: '2', startAfter: 2, total: 4 }, }, }, ]); const requestData = { options: { qs: {} } }; const result = await GenericFunctions_1.highLevelApiPagination.call(mockContext, requestData); expect(result).toEqual([{ json: { id: '1' } }, { json: { id: '2' } }]); }); it('should handle cases with no items', async () => { mockContext.getNodeParameter.mockImplementation((parameter) => { if (parameter === 'resource') return 'contact'; if (parameter === 'returnAll') return true; return undefined; }); mockContext.makeRoutingRequest.mockResolvedValueOnce([ { json: { contacts: [], meta: { startAfterId: null, startAfter: null, total: 0 }, }, }, ]); const requestData = { options: { qs: {} } }; const result = await GenericFunctions_1.highLevelApiPagination.call(mockContext, requestData); expect(result).toEqual([]); }); }); //# sourceMappingURL=HighLevelApiPagination.test.js.map