From df878cfcd479e65c3e5b0c4e412eea4f5d18fd9e Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:47:35 +0200 Subject: [PATCH] chore: Clean up some code --- .../__tests__/js-task-runner.test.ts | 25 ++++++++----------- .../src/js-task-runner/js-task-runner.ts | 6 ++--- packages/core/test/SerializedBuffer.test.ts | 4 +-- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/packages/@n8n/task-runner/src/js-task-runner/__tests__/js-task-runner.test.ts b/packages/@n8n/task-runner/src/js-task-runner/__tests__/js-task-runner.test.ts index dbb94038946fd..e93ff10dc4320 100644 --- a/packages/@n8n/task-runner/src/js-task-runner/__tests__/js-task-runner.test.ts +++ b/packages/@n8n/task-runner/src/js-task-runner/__tests__/js-task-runner.test.ts @@ -633,6 +633,7 @@ describe('JsTaskRunner', () => { ), }); + // Assert expect(rpcCallSpy).toHaveBeenCalledWith('1', group.method, group.expectedParams); }); @@ -661,26 +662,22 @@ describe('JsTaskRunner', () => { describe('unsupported methods', () => { for (const unsupportedFunction of UNSUPPORTED_HELPER_FUNCTIONS) { it(`should throw an error if ${unsupportedFunction} is used in runOnceForAllItems`, async () => { - // Act - + // Act & Assert await expect( - async () => - await executeForAllItems({ - code: `${unsupportedFunction}()`, - inputItems, - }), + executeForAllItems({ + code: `${unsupportedFunction}()`, + inputItems, + }), ).rejects.toThrow(UnsupportedFunctionError); }); it(`should throw an error if ${unsupportedFunction} is used in runOnceForEachItem`, async () => { - // Act - + // Act & Assert await expect( - async () => - await executeForEachItem({ - code: `${unsupportedFunction}()`, - inputItems, - }), + executeForEachItem({ + code: `${unsupportedFunction}()`, + inputItems, + }), ).rejects.toThrow(UnsupportedFunctionError); }); } diff --git a/packages/@n8n/task-runner/src/js-task-runner/js-task-runner.ts b/packages/@n8n/task-runner/src/js-task-runner/js-task-runner.ts index 04e05fb30aed6..802b78a640372 100644 --- a/packages/@n8n/task-runner/src/js-task-runner/js-task-runner.ts +++ b/packages/@n8n/task-runner/src/js-task-runner/js-task-runner.ts @@ -42,8 +42,8 @@ import { createRequireResolver } from './require-resolver'; import { validateRunForAllItemsOutput, validateRunForEachItemOutput } from './result-validation'; import { DataRequestResponseReconstruct } from '../data-request/data-request-response-reconstruct'; -export interface RPCCallObject { - [name: string]: ((...args: unknown[]) => Promise) | RPCCallObject; +export interface RpcCallObject { + [name: string]: ((...args: unknown[]) => Promise) | RpcCallObject; } export interface JSExecSettings { @@ -449,7 +449,7 @@ export class JsTaskRunner extends TaskRunner { } private buildRpcCallObject(taskId: string) { - const rpcObject: RPCCallObject = {}; + const rpcObject: RpcCallObject = {}; for (const rpcMethod of EXPOSED_RPC_METHODS) { set( diff --git a/packages/core/test/SerializedBuffer.test.ts b/packages/core/test/SerializedBuffer.test.ts index 42437296299f0..95d721340131c 100644 --- a/packages/core/test/SerializedBuffer.test.ts +++ b/packages/core/test/SerializedBuffer.test.ts @@ -7,7 +7,7 @@ const validSerializedBuffer: SerializedBuffer = { data: [65, 66, 67], // Corresponds to 'ABC' in ASCII }; -describe('serializedBufferToBuffer', () => { +describe('toBuffer', () => { it('should convert a SerializedBuffer to a Buffer', () => { const buffer = toBuffer(validSerializedBuffer); expect(buffer).toBeInstanceOf(Buffer); @@ -43,7 +43,7 @@ describe('isSerializedBuffer', () => { }); }); -describe('Integration: serializedBufferToBuffer and isSerializedBuffer', () => { +describe('Integration: toBuffer and isSerializedBuffer', () => { it('should correctly validate and convert a SerializedBuffer', () => { if (isSerializedBuffer(validSerializedBuffer)) { const buffer = toBuffer(validSerializedBuffer);