fix(Webflow Node): Fix issue with pagination in v2 node (#11934)

This commit is contained in:
Jon
2024-11-29 14:04:12 +00:00
committed by GitHub
parent af0398a5e3
commit 1eb94bcaf5
2 changed files with 84 additions and 11 deletions

View File

@@ -0,0 +1,66 @@
import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-workflow';
import { webflowApiRequestAllItems } from '../GenericFunctions';
describe('Webflow -> webflowApiRequestAllItems', () => {
let mockExecuteFunctions: IExecuteFunctions | ILoadOptionsFunctions;
const v1Response = {
items: [
{ id: '1', name: 'Item 1' },
{ id: '2', name: 'Item 2' },
],
total: 2,
};
const v2Response = {
body: {
items: [
{ id: '1', name: 'Item 1' },
{ id: '2', name: 'Item 2' },
],
pagination: {
total: 2,
},
},
};
const setupMockFunctions = (typeVersion: number) => {
mockExecuteFunctions = {
getNode: jest.fn().mockReturnValue({ typeVersion }),
getNodeParameter: jest.fn(),
helpers: {
httpRequestWithAuthentication: jest
.fn()
.mockResolvedValue(typeVersion === 1 ? v1Response : v2Response),
},
} as unknown as IExecuteFunctions | ILoadOptionsFunctions;
jest.clearAllMocks();
};
beforeEach(() => {
setupMockFunctions(1);
});
it('should return all items for type version 1', async () => {
const result = await webflowApiRequestAllItems.call(
mockExecuteFunctions,
'GET',
'/collections/collection_id/items',
);
expect(result).toEqual(v1Response.items);
});
it('should return all items for type version 2', async () => {
setupMockFunctions(2);
const result = await webflowApiRequestAllItems.call(
mockExecuteFunctions,
'GET',
'/collections/collection_id/items',
);
expect(result).toEqual(v2Response.body.items);
});
});