mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(Microsoft SQL Node): Correctly resolve expressions with dollar signs (#18411)
Co-authored-by: Your Name <you@example.com>
This commit is contained in:
@@ -276,7 +276,7 @@ export class MicrosoftSql implements INodeType {
|
||||
for (const resolvable of getResolvables(rawQuery)) {
|
||||
rawQuery = rawQuery.replace(
|
||||
resolvable,
|
||||
this.evaluateExpression(resolvable, i) as string,
|
||||
() => this.evaluateExpression(resolvable, i) as string,
|
||||
);
|
||||
}
|
||||
const results = await executeSqlQueryAndPrepareResults(pool, rawQuery, i);
|
||||
|
||||
@@ -22,7 +22,7 @@ function getMockedExecuteFunctions(overrides: Partial<IExecuteFunctions> = {}) {
|
||||
requestTimeout: 10000,
|
||||
}),
|
||||
getInputData: jest.fn().mockReturnValue([{ json: {} }]),
|
||||
getNode: jest.fn().mockReturnValue({ typeVersion: 1 }),
|
||||
getNode: jest.fn().mockReturnValue({ typeVersion: 1.1 }),
|
||||
continueOnFail: jest.fn().mockReturnValue(true),
|
||||
helpers: {
|
||||
constructExecutionMetaData,
|
||||
@@ -80,4 +80,29 @@ describe('MicrosoftSql Node', () => {
|
||||
expect(mockRequest.query).toHaveBeenCalledWith('SELECT 1 AS value');
|
||||
expect(mockPool.close).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('correctly resolves expressions (does not remove $ characters)', async () => {
|
||||
const queryResult = { recordsets: [[{ value: 1 }]] };
|
||||
const mockRequest = { query: jest.fn().mockResolvedValue(queryResult) };
|
||||
const mockPool = mock<mssql.ConnectionPool>({
|
||||
connect: jest.fn().mockResolvedValue(undefined),
|
||||
close: jest.fn(),
|
||||
request: jest.fn().mockReturnValue(mockRequest),
|
||||
});
|
||||
|
||||
mockedConnectionPool.mockReturnValue(mockPool);
|
||||
|
||||
const node = new MicrosoftSql();
|
||||
const context = getMockedExecuteFunctions({
|
||||
getNodeParameter: jest
|
||||
.fn()
|
||||
.mockReturnValueOnce('executeQuery')
|
||||
.mockReturnValueOnce("SELECT '{{ '$$$' }}'"),
|
||||
});
|
||||
context.evaluateExpression.mockReturnValue('$$$');
|
||||
|
||||
await node.execute.call(context);
|
||||
|
||||
expect(mockRequest.query).toHaveBeenCalledWith("SELECT '$$$'");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user