Skip to content

Commit ff40c69

Browse files
committed
Test sanitize-html
1 parent 9229148 commit ff40c69

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

packages/nodes-base/nodes/Form/test/utils.test.ts

+47
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,53 @@ describe('FormTrigger, formWebhook', () => {
111111
});
112112
});
113113

114+
it('should sanitize form descriptions', async () => {
115+
const mockRender = jest.fn();
116+
117+
const formDescription = [
118+
{ description: 'Test Description', expected: 'Test Description' },
119+
{ description: '<i>hello</i>', expected: '<i>hello</i>' },
120+
{ description: '<script>alert("hello world")</script>', expected: '' },
121+
];
122+
const formFields: FormFieldsParameter = [
123+
{ fieldLabel: 'Name', fieldType: 'text', requiredField: true },
124+
];
125+
126+
executeFunctions.getNodeParameter.calledWith('formFields.values').mockReturnValue(formFields);
127+
executeFunctions.getResponseObject.mockReturnValue({ render: mockRender } as any);
128+
129+
for (const { description, expected } of formDescription) {
130+
executeFunctions.getNodeParameter.calledWith('formDescription').mockReturnValue(description);
131+
132+
await formWebhook(executeFunctions);
133+
134+
expect(mockRender).toHaveBeenCalledWith('form-trigger', {
135+
appendAttribution: true,
136+
buttonLabel: 'Submit',
137+
formDescription: expected,
138+
formFields: [
139+
{
140+
defaultValue: '',
141+
errorId: 'error-field-0',
142+
id: 'field-0',
143+
inputRequired: 'form-required',
144+
isInput: true,
145+
label: 'Name',
146+
placeholder: undefined,
147+
type: 'text',
148+
},
149+
],
150+
formSubmittedText: 'Your response has been recorded',
151+
formTitle: 'Test Form',
152+
n8nWebsiteLink:
153+
'https://n8n.io/?utm_source=n8n-internal&utm_medium=form-trigger&utm_campaign=instanceId',
154+
testRun: true,
155+
useResponseData: false,
156+
validForm: true,
157+
});
158+
}
159+
});
160+
114161
it('should return workflowData on POST request', async () => {
115162
const mockStatus = jest.fn();
116163
const mockEnd = jest.fn();

0 commit comments

Comments
 (0)