mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
fix(core): Prevent re-parsing of dynamically loaded options (#9503)
This commit is contained in:
parent
24e8ac00c6
commit
a58be175cc
|
@ -1,5 +1,4 @@
|
|||
import type { INodePropertyOptions } from 'n8n-workflow';
|
||||
import { jsonParse } from 'n8n-workflow';
|
||||
|
||||
import { Post, RestController } from '@/decorators';
|
||||
import { getBase } from '@/WorkflowExecuteAdditionalData';
|
||||
|
@ -37,7 +36,7 @@ export class DynamicNodeParametersController {
|
|||
|
||||
if (loadOptions) {
|
||||
return await this.service.getOptionsViaLoadOptions(
|
||||
jsonParse(loadOptions),
|
||||
loadOptions,
|
||||
additionalData,
|
||||
nodeTypeAndVersion,
|
||||
currentNodeParameters,
|
||||
|
|
|
@ -3,6 +3,7 @@ import type {
|
|||
BannerName,
|
||||
ICredentialDataDecryptedObject,
|
||||
IDataObject,
|
||||
ILoadOptions,
|
||||
INodeCredentialTestRequest,
|
||||
INodeCredentials,
|
||||
INodeParameters,
|
||||
|
@ -406,19 +407,19 @@ export declare namespace DynamicNodeParametersRequest {
|
|||
{}
|
||||
>;
|
||||
|
||||
/** GET /dynamic-node-parameters/options */
|
||||
/** POST /dynamic-node-parameters/options */
|
||||
type Options = BaseRequest<{
|
||||
loadOptions?: string;
|
||||
loadOptions?: ILoadOptions;
|
||||
}>;
|
||||
|
||||
/** GET /dynamic-node-parameters/resource-locator-results */
|
||||
/** POST /dynamic-node-parameters/resource-locator-results */
|
||||
type ResourceLocatorResults = BaseRequest<{
|
||||
methodName: string;
|
||||
filter?: string;
|
||||
paginationToken?: string;
|
||||
}>;
|
||||
|
||||
/** GET dynamic-node-parameters/resource-mapper-fields */
|
||||
/** POST dynamic-node-parameters/resource-mapper-fields */
|
||||
type ResourceMapperFields = BaseRequest<{
|
||||
methodName: string;
|
||||
}>;
|
||||
|
|
|
@ -39,7 +39,7 @@ describe('DynamicNodeParametersController', () => {
|
|||
.post('/dynamic-node-parameters/options')
|
||||
.send({
|
||||
...commonRequestParams,
|
||||
loadOptions: 'loadOptions',
|
||||
loadOptions: {},
|
||||
})
|
||||
.expect(200);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import { DynamicNodeParametersController } from '@/controllers/dynamicNodeParameters.controller';
|
||||
import type { DynamicNodeParametersRequest } from '@/requests';
|
||||
import type { DynamicNodeParametersService } from '@/services/dynamicNodeParameters.service';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import * as AdditionalData from '@/WorkflowExecuteAdditionalData';
|
||||
import type { ILoadOptions, IWorkflowExecuteAdditionalData } from 'n8n-workflow';
|
||||
|
||||
describe('DynamicNodeParametersController', () => {
|
||||
const service = mock<DynamicNodeParametersService>();
|
||||
const controller = new DynamicNodeParametersController(service);
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('getOptions', () => {
|
||||
it('should take `loadOptions` as object', async () => {
|
||||
jest
|
||||
.spyOn(AdditionalData, 'getBase')
|
||||
.mockResolvedValue(mock<IWorkflowExecuteAdditionalData>());
|
||||
|
||||
const req = mock<DynamicNodeParametersRequest.Options>();
|
||||
const loadOptions: ILoadOptions = {};
|
||||
req.body.loadOptions = loadOptions;
|
||||
|
||||
await controller.getOptions(req);
|
||||
|
||||
const zerothArg = service.getOptionsViaLoadOptions.mock.calls[0][0];
|
||||
|
||||
expect(zerothArg).toEqual(loadOptions);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue