Skip to content

Commit

Permalink
fix failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ShireenMissi committed Nov 19, 2024
1 parent f8cde6e commit 3c20fea
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/nodes-base/nodes/Form/test/Form.node.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -7,14 +8,16 @@ import type {
IWebhookFunctions,
NodeTypeAndVersion,
} from 'n8n-workflow';
import type { Response, Request } from 'express';

import { Form } from '../Form.node';

describe('Form Node', () => {
let form: Form;
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
let mockWebhookFunctions: MockProxy<IWebhookFunctions>;

const formCompletionNodeName = 'Form Completion';
const testExecutionId = 'test_execution_id';
beforeEach(() => {
form = new Form();
mockExecuteFunctions = mock<IExecuteFunctions>();
Expand Down Expand Up @@ -68,7 +71,12 @@ describe('Form Node', () => {
]);
mockExecuteFunctions.getChildNodes.mockReturnValue([]);
mockExecuteFunctions.getInputData.mockReturnValue(inputData);
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>());
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>({ name: formCompletionNodeName }));
mockExecuteFunctions.getExecutionId.mockReturnValue(testExecutionId);

mockExecuteFunctions.getWorkflowStaticData.mockReturnValue({
[`${testExecutionId}-${formCompletionNodeName}`]: { redirectUrl: 'test' },
});

const result = await form.execute(mockExecuteFunctions);

Expand Down Expand Up @@ -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<INode>());
mockWebhookFunctions.getNode.mockReturnValue(mock<INode>({ name: formCompletionNodeName }));
mockWebhookFunctions.getExecutionId.mockReturnValue(testExecutionId);
mockWebhookFunctions.getWorkflowStaticData.mockReturnValue({
[`${testExecutionId}-${formCompletionNodeName}`]: { redirectUrl: '' },
});

const result = await form.webhook(mockWebhookFunctions);

Expand Down

0 comments on commit 3c20fea

Please sign in to comment.