mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-19 09:51:59 +08:00
fix(Postgres Node): Expressions are not resolved in v1 (#26496)
Co-authored-by: yehorkardash <yehor.kardash@n8n.io>
This commit is contained in:
co-authored by
yehorkardash
parent
91d4c1bdbd
commit
827e8680e3
@@ -0,0 +1,53 @@
|
||||
import { mockDeep } from 'jest-mock-extended';
|
||||
import { constructExecutionMetaData } from 'n8n-core';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
import pgPromise from 'pg-promise';
|
||||
|
||||
import { PostgresV1 } from '../../v1/PostgresV1.node';
|
||||
|
||||
const pgp = pgPromise();
|
||||
const multiSpy = jest.fn(() => [[{ id: 2, name: 'test' }]]);
|
||||
|
||||
jest.mock('../../transport', () => ({
|
||||
configurePostgres: jest.fn(() => ({ db: { multi: multiSpy }, pgp })),
|
||||
}));
|
||||
|
||||
describe('Postgres v1', () => {
|
||||
const node = new PostgresV1({
|
||||
displayName: 'Postgres',
|
||||
name: 'postgres',
|
||||
icon: 'file:postgres.svg',
|
||||
group: ['input'],
|
||||
defaultVersion: 1,
|
||||
description: 'Get, add and update data in Postgres',
|
||||
});
|
||||
const mockExecuteFunctions = mockDeep<IExecuteFunctions>();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockExecuteFunctions.getCredentials.mockResolvedValue({});
|
||||
mockExecuteFunctions.helpers.constructExecutionMetaData.mockImplementation(
|
||||
constructExecutionMetaData,
|
||||
);
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([{ json: {} }]);
|
||||
mockExecuteFunctions.continueOnFail.mockReturnValue(false);
|
||||
});
|
||||
|
||||
it('should resolve expressions in the query for executeQuery operation', async () => {
|
||||
mockExecuteFunctions.getNodeParameter.mockImplementation((param: string) => {
|
||||
const params: Record<string, unknown> = {
|
||||
'additionalFields.largeNumbersOutput': '',
|
||||
operation: 'executeQuery',
|
||||
query: 'SELECT * FROM users WHERE id = {{ 1 + 1 }}',
|
||||
additionalFields: {},
|
||||
};
|
||||
return params[param] as never;
|
||||
});
|
||||
mockExecuteFunctions.evaluateExpression.mockReturnValue(2);
|
||||
|
||||
await node.execute.call(mockExecuteFunctions);
|
||||
|
||||
expect(mockExecuteFunctions.evaluateExpression).toHaveBeenCalledWith('{{ 1 + 1 }}', 0);
|
||||
expect(multiSpy).toHaveBeenCalledWith('SELECT * FROM users WHERE id = 2');
|
||||
});
|
||||
});
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import pgPromise from 'pg-promise';
|
||||
|
||||
import * as PostgresFun from '../v1/genericFunctions';
|
||||
import type { PgpDatabase } from '../v2/helpers/interfaces';
|
||||
import * as PostgresFun from '../../v1/genericFunctions';
|
||||
import type { PgpDatabase } from '../../v2/helpers/interfaces';
|
||||
|
||||
type NodeParams = Record<string, string | {}>;
|
||||
|
||||
@@ -353,7 +353,9 @@ export class PostgresV1 implements INodeType {
|
||||
// executeQuery
|
||||
// ----------------------------------
|
||||
|
||||
const queryResult = await pgQueryV2.call(this, pgp, db, items, this.continueOnFail());
|
||||
const queryResult = await pgQueryV2.call(this, pgp, db, items, this.continueOnFail(), {
|
||||
resolveExpression: true,
|
||||
});
|
||||
returnItems = queryResult as INodeExecutionData[];
|
||||
} else if (operation === 'insert') {
|
||||
// ----------------------------------
|
||||
|
||||
Reference in New Issue
Block a user