mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
fix(Postgres Node): Accommodate null values in query parameters for expressions (#13544)
This commit is contained in:
@@ -363,6 +363,26 @@ describe('Test PostgresV2, executeQuery operation', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should execute queries with null key/value pairs', async () => {
|
||||
const nodeParameters: IDataObject = {
|
||||
operation: 'executeQuery',
|
||||
query: 'SELECT *\nFROM users\nWHERE username IN ($1, $2)',
|
||||
options: {
|
||||
queryReplacement: '"={{ betty }}, {{ null }}"',
|
||||
},
|
||||
};
|
||||
const nodeOptions = nodeParameters.options as IDataObject;
|
||||
|
||||
expect(async () => {
|
||||
await executeQuery.execute.call(
|
||||
createMockExecuteFunction(nodeParameters),
|
||||
runQueries,
|
||||
items,
|
||||
nodeOptions,
|
||||
);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('should execute queries with multiple json key/value pairs', async () => {
|
||||
const nodeParameters: IDataObject = {
|
||||
operation: 'executeQuery',
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
isJSON,
|
||||
convertValuesToJsonWithPgp,
|
||||
hasJsonDataTypeInSchema,
|
||||
evaluateExpression,
|
||||
} from '../../v2/helpers/utils';
|
||||
|
||||
const node: INode = {
|
||||
@@ -39,6 +40,25 @@ describe('Test PostgresV2, isJSON', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test PostgresV2, evaluateExpression', () => {
|
||||
it('should evaluate undefined to an empty string', () => {
|
||||
expect(evaluateExpression(undefined)).toEqual('');
|
||||
});
|
||||
it('should evaluate null to a string with value null', () => {
|
||||
expect(evaluateExpression(null)).toEqual('null');
|
||||
});
|
||||
it('should evaluate object to a string', () => {
|
||||
expect(evaluateExpression({ key: '' })).toEqual('{"key":""}');
|
||||
expect(evaluateExpression([])).toEqual('[]');
|
||||
expect(evaluateExpression([1, 2, 4])).toEqual('[1,2,4]');
|
||||
});
|
||||
it('should evaluate everything else to a string', () => {
|
||||
expect(evaluateExpression(1)).toEqual('1');
|
||||
expect(evaluateExpression('string')).toEqual('string');
|
||||
expect(evaluateExpression(true)).toEqual('true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test PostgresV2, wrapData', () => {
|
||||
it('should wrap object in json', () => {
|
||||
const data = {
|
||||
|
||||
Reference in New Issue
Block a user