Skip to content

Commit

Permalink
[backend] Fix tests (#issue/4911)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goumies committed Nov 22, 2023
1 parent b46f068 commit 439f726
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 128 deletions.
9 changes: 4 additions & 5 deletions opencti-platform/opencti-graphql/src/domain/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { RELATION_OBJECT } from '../schema/stixRefRelationship';
import { listAllThings, listThings } from '../database/middleware';
import {
internalFindByIds,
internalLoadById,
listAllRelations,
listEntities,
storeLoadById
Expand All @@ -19,7 +18,7 @@ import {
import { isStixDomainObjectContainer } from '../schema/stixDomainObject';
import { buildPagination, isInferredIndex, READ_INDEX_STIX_DOMAIN_OBJECTS } from '../database/utils';
import { now } from '../utils/format';
import { elCount } from '../database/engine';
import { elBatchIds, elCount } from '../database/engine';
import { findById as findInvestigationById } from '../modules/workspace/workspace-domain';
import { stixCoreObjectAddRelations } from './stixCoreObject';

Expand Down Expand Up @@ -151,8 +150,8 @@ export const containersObjectsOfObject = async (context, user, { id, types, filt

export const filterUnwantedEntitiesOut = async ({ context, user, ids }) => {
const filteredOutInvestigatedIds = [];
ids.forEach((id) => {
const entity = internalLoadById(context, user, id);
const entities = await elBatchIds(context, user, ids);
entities?.forEach((entity) => {
if (!['Task', 'Note'].includes(entity.entity_type)) {
filteredOutInvestigatedIds.push(entity.id);
}
Expand All @@ -162,7 +161,7 @@ export const filterUnwantedEntitiesOut = async ({ context, user, ids }) => {

export const knowledgeAddFromInvestigation = async (context, user, { containerId, workspaceId }) => {
const investigation = await findInvestigationById(context, user, workspaceId);
const ids = investigation.investigated_entities_ids.filter((id) => id !== containerId);
const ids = investigation.investigated_entities_ids?.filter((id) => id !== containerId);
const toIds = await filterUnwantedEntitiesOut({ context, user, ids });
const containerInput = { toIds, relationship_type: 'object' };
return await stixCoreObjectAddRelations(context, user, containerId, containerInput);
Expand Down

0 comments on commit 439f726

Please sign in to comment.