Skip to content

Commit

Permalink
[backend/frontend] backend tests (#6390)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archidoit committed Mar 20, 2024
1 parent fb33396 commit 46f07c0
Showing 1 changed file with 21 additions and 8 deletions.
Expand Up @@ -18,7 +18,16 @@ import { ENTITY_TYPE_NOTIFICATION, ENTITY_TYPE_TRIGGER } from '../../../src/modu
import { ENTITY_HASHED_OBSERVABLE_ARTIFACT, ENTITY_HASHED_OBSERVABLE_STIX_FILE, ENTITY_HASHED_OBSERVABLE_X509_CERTIFICATE } from '../../../src/schema/stixCyberObservable';
import { ENTITY_TYPE_CONTAINER_CASE } from '../../../src/modules/case/case-types';
import { ENTITY_TYPE_CONTAINER_GROUPING } from '../../../src/modules/grouping/grouping-types';
import { ALIAS_FILTER, CONNECTED_TO_INSTANCE_FILTER, CONTEXT_OBJECT_LABEL_FILTER, INSTANCE_REGARDING_OF, TYPE_FILTER } from '../../../src/utils/filtering/filtering-constants';
import {
ALIAS_FILTER,
CONNECTED_TO_INSTANCE_FILTER,
CONTEXT_OBJECT_LABEL_FILTER,
INSTANCE_FILTER_TARGET_TYPES,
INSTANCE_REGARDING_OF,
RELATION_FROM_FILTER,
RELATION_TO_TYPES_FILTER,
TYPE_FILTER
} from '../../../src/utils/filtering/filtering-constants';
import { ENTITY_TYPE_HISTORY } from '../../../src/schema/internalObject';

describe('Filter keys schema generation testing', async () => {
Expand Down Expand Up @@ -128,22 +137,26 @@ describe('Filter keys schema generation testing', async () => {
expect(filterDefinition?.type).toEqual('enum');
expect(filterDefinition?.elementsForFilterValuesSearch.length).toEqual(3); // create, update, delete
});
it('should construct correct filter definition for nested object attributes', () => {
it('should construct correct filter definition for nested object attributes: case of relationships', () => {
// 'fromId' for stix core relationships
let filterDefinition = filterKeysSchema.get(ABSTRACT_STIX_CORE_RELATIONSHIP)?.get('fromId');
expect(filterDefinition?.filterKey).toEqual('fromId');
let filterDefinition = filterKeysSchema.get(ABSTRACT_STIX_CORE_RELATIONSHIP)?.get(RELATION_FROM_FILTER);
expect(filterDefinition?.filterKey).toEqual(RELATION_FROM_FILTER);
expect(filterDefinition?.type).toEqual('id');
expect(filterDefinition?.label).toEqual('Source entity');
expect(filterDefinition?.elementsForFilterValuesSearch.length).toEqual(1);
expect(filterDefinition?.elementsForFilterValuesSearch[0]).toEqual(ABSTRACT_STIX_CORE_OBJECT);
// 'toTypes' for stix core relationships
filterDefinition = filterKeysSchema.get(ABSTRACT_STIX_CORE_RELATIONSHIP)?.get('toTypes');
expect(filterDefinition?.filterKey).toEqual('toTypes');
filterDefinition = filterKeysSchema.get(ABSTRACT_STIX_CORE_RELATIONSHIP)?.get(RELATION_TO_TYPES_FILTER);
expect(filterDefinition?.filterKey).toEqual(RELATION_TO_TYPES_FILTER);
expect(filterDefinition?.type).toEqual('string');
expect(filterDefinition?.label).toEqual('Target type');
expect(filterDefinition?.elementsForFilterValuesSearch.length).toEqual(0);
// 'elementWithTargetTypes' for stix core relationships
filterDefinition = filterKeysSchema.get(ABSTRACT_STIX_CORE_RELATIONSHIP)?.get(INSTANCE_FILTER_TARGET_TYPES);
expect(filterDefinition?.filterKey).toEqual(INSTANCE_FILTER_TARGET_TYPES);
expect(filterDefinition?.type).toEqual('string');
// 'fromId' for basic relationships: not filterable
filterDefinition = filterKeysSchema.get(ABSTRACT_BASIC_RELATIONSHIP)?.get('fromId');
filterDefinition = filterKeysSchema.get(ABSTRACT_BASIC_RELATIONSHIP)?.get(RELATION_FROM_FILTER);
expect(filterDefinition).toBeUndefined();
});
it('should construct correct filter definition for special filter keys', () => {
Expand Down Expand Up @@ -199,7 +212,7 @@ describe('Filter keys schema generation testing', async () => {
expect(filterDefinition?.subEntityTypes.length).toEqual(1); // 'Threat-Actor-Individual'

// Stix Core Relationships
filterDefinition = filterKeysSchema.get(ABSTRACT_STIX_CORE_RELATIONSHIP)?.get('fromId');
filterDefinition = filterKeysSchema.get(ABSTRACT_STIX_CORE_RELATIONSHIP)?.get(RELATION_FROM_FILTER);
expect(filterDefinition?.subEntityTypes.length).toEqual(49); // 48 stix core relationship types + abstract type 'stix-core-relationships'
// Stix Cyber Observables
filterDefinition = filterKeysSchema.get(ABSTRACT_STIX_CYBER_OBSERVABLE)?.get('x_opencti_score'); // attribute existing for all the observables
Expand Down

0 comments on commit 46f07c0

Please sign in to comment.