From 3c20fea5e48febe3d50b3db83c8afd5a06f70a05 Mon Sep 17 00:00:00 2001 From: Shireen Missi Date: Tue, 19 Nov 2024 20:44:23 +0000 Subject: [PATCH] fix failing unit tests --- .../nodes/Form/test/Form.node.test.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Form/test/Form.node.test.ts b/packages/nodes-base/nodes/Form/test/Form.node.test.ts index 616e3cf8dbd62..ecd24d8ca54b3 100644 --- a/packages/nodes-base/nodes/Form/test/Form.node.test.ts +++ b/packages/nodes-base/nodes/Form/test/Form.node.test.ts @@ -1,3 +1,4 @@ +import type { Response, Request } from 'express'; import type { MockProxy } from 'jest-mock-extended'; import { mock } from 'jest-mock-extended'; import type { @@ -7,7 +8,7 @@ import type { IWebhookFunctions, NodeTypeAndVersion, } from 'n8n-workflow'; -import type { Response, Request } from 'express'; + import { Form } from '../Form.node'; describe('Form Node', () => { @@ -15,6 +16,8 @@ describe('Form Node', () => { let mockExecuteFunctions: MockProxy; let mockWebhookFunctions: MockProxy; + const formCompletionNodeName = 'Form Completion'; + const testExecutionId = 'test_execution_id'; beforeEach(() => { form = new Form(); mockExecuteFunctions = mock(); @@ -68,7 +71,12 @@ describe('Form Node', () => { ]); mockExecuteFunctions.getChildNodes.mockReturnValue([]); mockExecuteFunctions.getInputData.mockReturnValue(inputData); - mockExecuteFunctions.getNode.mockReturnValue(mock()); + mockExecuteFunctions.getNode.mockReturnValue(mock({ name: formCompletionNodeName })); + mockExecuteFunctions.getExecutionId.mockReturnValue(testExecutionId); + + mockExecuteFunctions.getWorkflowStaticData.mockReturnValue({ + [`${testExecutionId}-${formCompletionNodeName}`]: { redirectUrl: 'test' }, + }); const result = await form.execute(mockExecuteFunctions); @@ -172,11 +180,16 @@ describe('Form Node', () => { const mockResponseObject = { render: jest.fn(), + redirect: jest.fn(), }; mockWebhookFunctions.getResponseObject.mockReturnValue( mockResponseObject as unknown as Response, ); - mockWebhookFunctions.getNode.mockReturnValue(mock()); + mockWebhookFunctions.getNode.mockReturnValue(mock({ name: formCompletionNodeName })); + mockWebhookFunctions.getExecutionId.mockReturnValue(testExecutionId); + mockWebhookFunctions.getWorkflowStaticData.mockReturnValue({ + [`${testExecutionId}-${formCompletionNodeName}`]: { redirectUrl: '' }, + }); const result = await form.webhook(mockWebhookFunctions);