2024-05-21 10:11:02 -07:00
|
|
|
import type {
|
|
|
|
INodeListSearchResult,
|
|
|
|
IWorkflowExecuteAdditionalData,
|
|
|
|
ResourceMapperFields,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
import { mock } from 'jest-mock-extended';
|
2024-05-31 00:40:03 -07:00
|
|
|
|
2024-08-28 04:59:27 -07:00
|
|
|
import { DynamicNodeParametersService } from '@/services/dynamic-node-parameters.service';
|
2024-08-22 02:10:37 -07:00
|
|
|
import * as AdditionalData from '@/workflow-execute-additional-data';
|
2024-05-31 00:40:03 -07:00
|
|
|
|
|
|
|
import { createOwner } from '../shared/db/users';
|
|
|
|
import { setupTestServer } from '../shared/utils';
|
|
|
|
import type { SuperAgentTest } from '../shared/types';
|
2024-05-21 10:11:02 -07:00
|
|
|
|
|
|
|
describe('DynamicNodeParametersController', () => {
|
|
|
|
const testServer = setupTestServer({ endpointGroups: ['dynamic-node-parameters'] });
|
2024-05-31 00:40:03 -07:00
|
|
|
let ownerAgent: SuperAgentTest;
|
2024-05-21 10:11:02 -07:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
const owner = await createOwner();
|
|
|
|
ownerAgent = testServer.authAgentFor(owner);
|
|
|
|
});
|
|
|
|
|
|
|
|
const commonRequestParams = {
|
|
|
|
credentials: {},
|
|
|
|
currentNodeParameters: {},
|
|
|
|
nodeTypeAndVersion: {},
|
|
|
|
path: 'path',
|
|
|
|
methodName: 'methodName',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('POST /dynamic-node-parameters/options', () => {
|
|
|
|
jest.spyOn(AdditionalData, 'getBase').mockResolvedValue(mock<IWorkflowExecuteAdditionalData>());
|
|
|
|
|
|
|
|
it('should take params via body', async () => {
|
|
|
|
jest
|
|
|
|
.spyOn(DynamicNodeParametersService.prototype, 'getOptionsViaMethodName')
|
|
|
|
.mockResolvedValue([]);
|
|
|
|
|
|
|
|
await ownerAgent
|
|
|
|
.post('/dynamic-node-parameters/options')
|
|
|
|
.send({
|
|
|
|
...commonRequestParams,
|
2024-05-24 02:00:15 -07:00
|
|
|
loadOptions: {},
|
2024-05-21 10:11:02 -07:00
|
|
|
})
|
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('POST /dynamic-node-parameters/resource-locator-results', () => {
|
|
|
|
it('should take params via body', async () => {
|
|
|
|
jest
|
|
|
|
.spyOn(DynamicNodeParametersService.prototype, 'getResourceLocatorResults')
|
|
|
|
.mockResolvedValue(mock<INodeListSearchResult>());
|
|
|
|
|
|
|
|
await ownerAgent
|
|
|
|
.post('/dynamic-node-parameters/resource-locator-results')
|
|
|
|
.send({
|
|
|
|
...commonRequestParams,
|
|
|
|
filter: 'filter',
|
|
|
|
paginationToken: 'paginationToken',
|
|
|
|
})
|
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('POST /dynamic-node-parameters/resource-mapper-fields', () => {
|
|
|
|
it('should take params via body', async () => {
|
|
|
|
jest
|
|
|
|
.spyOn(DynamicNodeParametersService.prototype, 'getResourceMappingFields')
|
|
|
|
.mockResolvedValue(mock<ResourceMapperFields>());
|
|
|
|
|
|
|
|
await ownerAgent
|
|
|
|
.post('/dynamic-node-parameters/resource-mapper-fields')
|
|
|
|
.send({
|
|
|
|
...commonRequestParams,
|
|
|
|
loadOptions: 'loadOptions',
|
|
|
|
})
|
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|