mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-28 05:59:42 -08:00
fix(Webflow Node): Fix issue with publishing items (#11982)
This commit is contained in:
parent
9f78b16efc
commit
0a8a57e4ec
|
@ -115,9 +115,8 @@ export async function execute(
|
||||||
responseData = await webflowApiRequest.call(
|
responseData = await webflowApiRequest.call(
|
||||||
this,
|
this,
|
||||||
'POST',
|
'POST',
|
||||||
`/collections/${collectionId}/items`,
|
`/collections/${collectionId}/items${live ? '/live' : ''}`,
|
||||||
body,
|
body,
|
||||||
{ live },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
|
|
|
@ -124,9 +124,8 @@ export async function execute(
|
||||||
responseData = await webflowApiRequest.call(
|
responseData = await webflowApiRequest.call(
|
||||||
this,
|
this,
|
||||||
'PATCH',
|
'PATCH',
|
||||||
`/collections/${collectionId}/items/${itemId}`,
|
`/collections/${collectionId}/items/${itemId}${live ? '/live' : ''}`,
|
||||||
body,
|
body,
|
||||||
{ live },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const executionData = this.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
|
|
|
@ -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', () => {
|
describe('Webflow -> webflowApiRequestAllItems', () => {
|
||||||
let mockExecuteFunctions: IExecuteFunctions | ILoadOptionsFunctions;
|
let mockExecuteFunctions: IExecuteFunctions | ILoadOptionsFunctions;
|
||||||
|
@ -64,3 +70,80 @@ describe('Webflow -> webflowApiRequestAllItems', () => {
|
||||||
expect(result).toEqual(v2Response.body.items);
|
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,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue