From 0a8a57e4ec8081ab1a53f36d686b3d5dcaae2476 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 2 Dec 2024 18:51:25 +0000 Subject: [PATCH] fix(Webflow Node): Fix issue with publishing items (#11982) --- .../V2/actions/Item/create.operation.ts | 3 +- .../V2/actions/Item/update.operation.ts | 3 +- .../Webflow/test/GenericFunctions.test.ts | 87 ++++++++++++++++++- 3 files changed, 87 insertions(+), 6 deletions(-) diff --git a/packages/nodes-base/nodes/Webflow/V2/actions/Item/create.operation.ts b/packages/nodes-base/nodes/Webflow/V2/actions/Item/create.operation.ts index da816d56f9..8189ade81c 100644 --- a/packages/nodes-base/nodes/Webflow/V2/actions/Item/create.operation.ts +++ b/packages/nodes-base/nodes/Webflow/V2/actions/Item/create.operation.ts @@ -115,9 +115,8 @@ export async function execute( responseData = await webflowApiRequest.call( this, 'POST', - `/collections/${collectionId}/items`, + `/collections/${collectionId}/items${live ? '/live' : ''}`, body, - { live }, ); const executionData = this.helpers.constructExecutionMetaData( diff --git a/packages/nodes-base/nodes/Webflow/V2/actions/Item/update.operation.ts b/packages/nodes-base/nodes/Webflow/V2/actions/Item/update.operation.ts index 37e716c783..a25db5e1bc 100644 --- a/packages/nodes-base/nodes/Webflow/V2/actions/Item/update.operation.ts +++ b/packages/nodes-base/nodes/Webflow/V2/actions/Item/update.operation.ts @@ -124,9 +124,8 @@ export async function execute( responseData = await webflowApiRequest.call( this, 'PATCH', - `/collections/${collectionId}/items/${itemId}`, + `/collections/${collectionId}/items/${itemId}${live ? '/live' : ''}`, body, - { live }, ); const executionData = this.helpers.constructExecutionMetaData( diff --git a/packages/nodes-base/nodes/Webflow/test/GenericFunctions.test.ts b/packages/nodes-base/nodes/Webflow/test/GenericFunctions.test.ts index cdccca5189..473c887116 100644 --- a/packages/nodes-base/nodes/Webflow/test/GenericFunctions.test.ts +++ b/packages/nodes-base/nodes/Webflow/test/GenericFunctions.test.ts @@ -1,6 +1,12 @@ -import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-workflow'; +import type { + IExecuteFunctions, + IHookFunctions, + IHttpRequestMethods, + ILoadOptionsFunctions, + INode, +} from 'n8n-workflow'; -import { webflowApiRequestAllItems } from '../GenericFunctions'; +import { webflowApiRequest, webflowApiRequestAllItems } from '../GenericFunctions'; describe('Webflow -> webflowApiRequestAllItems', () => { let mockExecuteFunctions: IExecuteFunctions | ILoadOptionsFunctions; @@ -64,3 +70,80 @@ describe('Webflow -> webflowApiRequestAllItems', () => { expect(result).toEqual(v2Response.body.items); }); }); + +describe('Webflow -> webflowApiRequest', () => { + const node: INode = { + id: '8e3c489c-4905-4bc4-9fc6-f1912d0766ec', + name: 'Webflow', + type: 'n8n-nodes-base.webflow', + typeVersion: 2, + position: [0, 0], + credentials: { + webflowOAuth2Api: { + id: 'xxyyzz', + name: 'credential name', + }, + }, + parameters: { + operation: 'update', + itemId: 'xxx', + siteId: 'yyy', + collectionId: 'zzz', + live: true, + }, + }; + it('should use live in the url for v2 when live is true', async () => { + const mockThis = { + helpers: { + httpRequestWithAuthentication: jest.fn().mockResolvedValue({ statusCode: 200, data: 'x' }), + }, + getNode() { + return node; + }, + getNodeParameter: jest.fn(), + } as unknown as IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions; + + const method: IHttpRequestMethods = 'PATCH'; + const resource = `/collections/${node.parameters.collectionId}/items/${node.parameters.itemId}${node.parameters.live ? '/live' : ''}`; + + await webflowApiRequest.call(mockThis, method, resource); + + expect(mockThis.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith( + 'webflowOAuth2Api', + { + method: 'PATCH', + returnFullResponse: true, + url: 'https://api.webflow.com/v2/collections/zzz/items/xxx/live', + json: true, + }, + ); + }); + it('should skip live in the url for v2 when live is false', async () => { + const mockThis = { + helpers: { + httpRequestWithAuthentication: jest.fn().mockResolvedValue({ statusCode: 200, data: 'x' }), + }, + getNode() { + return node; + }, + getNodeParameter: jest.fn(), + } as unknown as IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions; + + node.parameters.live = false; + + const method: IHttpRequestMethods = 'PATCH'; + const resource = `/collections/${node.parameters.collectionId}/items/${node.parameters.itemId}${node.parameters.live ? '/live' : ''}`; + + await webflowApiRequest.call(mockThis, method, resource); + + expect(mockThis.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith( + 'webflowOAuth2Api', + { + method: 'PATCH', + returnFullResponse: true, + url: 'https://api.webflow.com/v2/collections/zzz/items/xxx', + json: true, + }, + ); + }); +});