mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-04 18:49:20 +02:00
fix(TheHiveProject Node): Normalize analyzers when expression returns a string (#31580)
This commit is contained in:
parent
9cb9a1fc46
commit
43d32fd28f
|
|
@ -8,6 +8,7 @@ import type {
|
|||
import { updateDisplayOptions, wrapData } from '@utils/utilities';
|
||||
|
||||
import { observableRLC, observableTypeOptions } from '../../descriptions';
|
||||
import { parseAnalyzers } from '../../helpers/utils';
|
||||
import { theHiveApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
|
|
@ -49,13 +50,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
|
|||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
const analyzers = (this.getNodeParameter('analyzers', i) as string[]).map((analyzer) => {
|
||||
const parts = analyzer.split('::');
|
||||
return {
|
||||
analyzerId: parts[0],
|
||||
cortexId: parts[1],
|
||||
};
|
||||
});
|
||||
const analyzers = parseAnalyzers(this.getNodeParameter('analyzers', i) as string | string[]);
|
||||
let response: any;
|
||||
let body: IDataObject;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,18 @@ export function splitAndTrim(str: string | string[]) {
|
|||
return str;
|
||||
}
|
||||
|
||||
// The "Analyzers" field is a multiOptions parameter, so it normally resolves to
|
||||
// an array of "analyzerId::cortexId" entries. When its value comes from an
|
||||
// expression wrapped in surrounding text/whitespace, n8n switches to string
|
||||
// interpolation and the array is coerced to a comma-joined string. Normalize
|
||||
// both shapes so the operation does not throw "(...).map is not a function".
|
||||
export function parseAnalyzers(value: string | string[]) {
|
||||
return splitAndTrim(value).map((analyzer) => {
|
||||
const [analyzerId, cortexId] = analyzer.split('::');
|
||||
return { analyzerId, cortexId };
|
||||
});
|
||||
}
|
||||
|
||||
export function fixFieldType(fields: IDataObject) {
|
||||
const returnData: IDataObject = {};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
import { splitAndTrim, fixFieldType, prepareInputItem, constructFilter } from '../helpers/utils';
|
||||
import {
|
||||
splitAndTrim,
|
||||
parseAnalyzers,
|
||||
fixFieldType,
|
||||
prepareInputItem,
|
||||
constructFilter,
|
||||
} from '../helpers/utils';
|
||||
|
||||
describe('Test TheHiveProject, splitAndTrim', () => {
|
||||
it('should split and trim string, removing empty entries', () => {
|
||||
|
|
@ -18,6 +24,49 @@ describe('Test TheHiveProject, splitAndTrim', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Test TheHiveProject, parseAnalyzers', () => {
|
||||
it('should map an array of "analyzerId::cortexId" entries', () => {
|
||||
const data = ['analyzer-1::cortex-1', 'analyzer-2::cortex-2'];
|
||||
|
||||
const result = parseAnalyzers(data);
|
||||
|
||||
expect(result).toEqual([
|
||||
{ analyzerId: 'analyzer-1', cortexId: 'cortex-1' },
|
||||
{ analyzerId: 'analyzer-2', cortexId: 'cortex-2' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should map a comma-joined string (expression coercion case)', () => {
|
||||
const data = 'analyzer-1::cortex-1, analyzer-2::cortex-2';
|
||||
|
||||
const result = parseAnalyzers(data);
|
||||
|
||||
expect(result).toEqual([
|
||||
{ analyzerId: 'analyzer-1', cortexId: 'cortex-1' },
|
||||
{ analyzerId: 'analyzer-2', cortexId: 'cortex-2' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle a single analyzer provided as a string', () => {
|
||||
const result = parseAnalyzers('analyzer-1::cortex-1');
|
||||
|
||||
expect(result).toEqual([{ analyzerId: 'analyzer-1', cortexId: 'cortex-1' }]);
|
||||
});
|
||||
|
||||
it('should drop empty entries from a comma-joined string', () => {
|
||||
const result = parseAnalyzers('analyzer-1::cortex-1,, analyzer-2::cortex-2,');
|
||||
|
||||
expect(result).toEqual([
|
||||
{ analyzerId: 'analyzer-1', cortexId: 'cortex-1' },
|
||||
{ analyzerId: 'analyzer-2', cortexId: 'cortex-2' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return an empty array for an empty string', () => {
|
||||
expect(parseAnalyzers('')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test TheHiveProject, fixFieldType', () => {
|
||||
it('should split and trim tags', () => {
|
||||
const data = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user