mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { validateNoDisallowedMethodsInRunForEach } from '../JsCodeValidator';
|
|
|
|
describe('JsCodeValidator', () => {
|
|
describe('validateNoDisallowedMethodsInRunForEach', () => {
|
|
it('should not throw error if disallow method is used within single line comments', () => {
|
|
const code = [
|
|
"// Add a new field called 'myNewField' to the JSON of the item",
|
|
'$input.item.json.myNewField = 1;',
|
|
' // const xxx = $input.all()',
|
|
'return $input.item;',
|
|
].join('\n');
|
|
|
|
expect(() => validateNoDisallowedMethodsInRunForEach(code, 0)).not.toThrow();
|
|
});
|
|
|
|
it('should not throw error if disallow method is used in single multi line comments', () => {
|
|
const code = [
|
|
"// Add a new field called 'myNewField' to the JSON of the item",
|
|
'$input.item.json.myNewField = 1;',
|
|
'/** const xxx = $input.all()*/',
|
|
'return $input.item;',
|
|
].join('\n');
|
|
|
|
expect(() => validateNoDisallowedMethodsInRunForEach(code, 0)).not.toThrow();
|
|
});
|
|
|
|
it('should not throw error if disallow method is used within multi line comments', () => {
|
|
const code = [
|
|
"// Add a new field called 'myNewField' to the JSON of the item",
|
|
'$input.item.json.myNewField = 1;',
|
|
'/**',
|
|
'*const xxx = $input.all()',
|
|
'*/',
|
|
'return $input.item;',
|
|
].join('\n');
|
|
|
|
expect(() => validateNoDisallowedMethodsInRunForEach(code, 0)).not.toThrow();
|
|
});
|
|
|
|
it('should throw error if disallow method is used', () => {
|
|
const code = [
|
|
"// Add a new field called 'myNewField' to the JSON of the item",
|
|
'$input.item.json.myNewField = 1;',
|
|
'const xxx = $input.all()',
|
|
'return $input.item;',
|
|
].join('\n');
|
|
|
|
expect(() => validateNoDisallowedMethodsInRunForEach(code, 0)).toThrow();
|
|
});
|
|
});
|
|
});
|