mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-23 18:41:48 -08:00
fix(Postgres Node): Falsy query parameters ignored (#10960)
This commit is contained in:
parent
c7888ef229
commit
4a63cff5ec
|
@ -46,6 +46,9 @@ const createMockExecuteFunction = (nodeParameters: IDataObject) => {
|
|||
node.parameters = { ...node.parameters, ...(nodeParameters as INodeParameters) };
|
||||
return node;
|
||||
},
|
||||
evaluateExpression(str: string, _: number) {
|
||||
return str.replace('{{', '').replace('}}', '');
|
||||
},
|
||||
} as unknown as IExecuteFunctions;
|
||||
return fakeExecuteFunction;
|
||||
};
|
||||
|
@ -290,6 +293,26 @@ describe('Test PostgresV2, executeQuery operation', () => {
|
|||
nodeOptions,
|
||||
);
|
||||
});
|
||||
|
||||
it('should call runQueries with falsy query replacements', async () => {
|
||||
const nodeParameters: IDataObject = {
|
||||
operation: 'executeQuery',
|
||||
query: 'SELECT *\nFROM users\nWHERE username IN ($1, $2, $3)',
|
||||
options: {
|
||||
queryReplacement: '={{ 0 }}, {{ null }}, {{ 0 }}',
|
||||
},
|
||||
};
|
||||
const nodeOptions = nodeParameters.options as IDataObject;
|
||||
|
||||
expect(async () => {
|
||||
await executeQuery.execute.call(
|
||||
createMockExecuteFunction(nodeParameters),
|
||||
runQueries,
|
||||
items,
|
||||
nodeOptions,
|
||||
);
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test PostgresV2, insert operation', () => {
|
||||
|
|
|
@ -80,7 +80,7 @@ export async function execute(
|
|||
const rawReplacements = (node.parameters.options as IDataObject)?.queryReplacement as string;
|
||||
|
||||
const stringToArray = (str: NodeParameterValueType | undefined) => {
|
||||
if (!str) return [];
|
||||
if (str === undefined) return [];
|
||||
return String(str)
|
||||
.split(',')
|
||||
.filter((entry) => entry)
|
||||
|
|
Loading…
Reference in a new issue