Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for public components #383

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f78f8dd
[FEATURE] Detector must have at least one alert set #288
jovancvetkovic3006 Jan 9, 2023
1ea796c
Merge branch 'main' of https://github.com/opensearch-project/security…
jovancvetkovic3006 Jan 11, 2023
0d514d8
Merge branch 'main' of https://github.com/opensearch-project/security…
jovancvetkovic3006 Jan 16, 2023
ff8117e
[BUG] Create detector | Interval field can be empty #378
jovancvetkovic3006 Jan 23, 2023
b308059
Adjust styling for Finding details flyout #369
jovancvetkovic3006 Jan 24, 2023
73fae1f
Merge branch 'main' of https://github.com/opensearch-project/security…
jovancvetkovic3006 Jan 24, 2023
7a41744
unit tests
jovancvetkovic3006 Jan 24, 2023
06be7da
detector unit tests
jovancvetkovic3006 Jan 25, 2023
f0ccd00
Merge branch 'main' of https://github.com/opensearch-project/security…
jovancvetkovic3006 Jan 25, 2023
6bf765e
detector unit tests
jovancvetkovic3006 Jan 26, 2023
36b6390
detector unit tests
jovancvetkovic3006 Jan 26, 2023
c23a669
detector unit tests
jovancvetkovic3006 Jan 26, 2023
ce0944b
detector unit tests
jovancvetkovic3006 Jan 26, 2023
d37fb41
detector unit tests
jovancvetkovic3006 Jan 26, 2023
d523098
detector unit tests
jovancvetkovic3006 Jan 26, 2023
8ef0bd0
detector unit tests
jovancvetkovic3006 Jan 26, 2023
9c71aa8
detector unit tests
jovancvetkovic3006 Jan 27, 2023
bc50e0a
Merge branch 'main' of https://github.com/opensearch-project/security…
jovancvetkovic3006 Jan 31, 2023
31c02b0
Merge branch 'main' of https://github.com/opensearch-project/security…
jovancvetkovic3006 Jan 31, 2023
460e7d2
Merge branch 'main' of https://github.com/opensearch-project/security…
jovancvetkovic3006 Feb 1, 2023
482b2c7
unit tests review
jovancvetkovic3006 Feb 1, 2023
b4ed7fa
unit tests review
jovancvetkovic3006 Feb 3, 2023
8381d32
unit tests review
jovancvetkovic3006 Feb 3, 2023
2933d63
unit tests review
jovancvetkovic3006 Feb 3, 2023
378ea69
unit tests review
jovancvetkovic3006 Feb 3, 2023
84b225a
unit tests review
jovancvetkovic3006 Feb 3, 2023
9fa4df8
unit tests review
jovancvetkovic3006 Feb 3, 2023
7e03bfd
unit tests review
jovancvetkovic3006 Feb 3, 2023
237325a
Feature/update vertical domain #372
jovancvetkovic3006 Feb 3, 2023
5422508
Unit tests for public components #383
jovancvetkovic3006 Feb 10, 2023
d54ce17
Unit tests for public components #383
jovancvetkovic3006 Feb 10, 2023
926e249
Unit tests for public components #383
jovancvetkovic3006 Feb 10, 2023
092efff
Unit tests for public components #383
jovancvetkovic3006 Feb 10, 2023
8a2246b
Unit tests for public components #383
jovancvetkovic3006 Feb 11, 2023
fa436c4
Merge branch 'main' of https://github.com/opensearch-project/security…
jovancvetkovic3006 Feb 16, 2023
95c6db8
Unit tests for public components #383
jovancvetkovic3006 Feb 16, 2023
6dab0ee
PR code review
jovancvetkovic3006 Feb 16, 2023
239150f
PR code review
jovancvetkovic3006 Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { AlertCondition } from '../../../../../../../models/interfaces';
import {
NotificationChannelOption,
NotificationChannelTypeOptions,
} from '../../../../../../pages/CreateDetector/components/ConfigureAlerts/models/interfaces';
import { CreateDetectorRulesOptions } from '../../../../../types';
import { mockDetector, mockTriggerAction } from '../../../../../Interfaces.mock';
import { RuleOptions, RulesPage } from '../../../../../interfaces';

export const mockAlertCondition: AlertCondition = {
// Trigger fields
name: 'alertCondition',
id: 'alertConditionId',

// Detector types
types: ['windows', 'dns'],

// Trigger fields based on Rules
sev_levels: ['low', 'high', 'critical'],
tags: ['mock.tag'],
ids: ['ruleID1', 'ruleID2'],

// Alert related fields
actions: [mockTriggerAction],
severity: 'low',
};

export const mockNotificationChannelOption: NotificationChannelOption = {
label: 'notificationChanelOptionLabel',
value: 'notificationChanelOptionValue',
type: 'notificationChanelOptionType',
description: 'notificationChanelOptionDescription',
};
export const mockNotificationChannelTypeOptions: NotificationChannelTypeOptions = {
jovancacvetkovic marked this conversation as resolved.
Show resolved Hide resolved
label: 'notificationChannelLabel',
options: [mockNotificationChannelOption],
};
export const mockRulesPage: RulesPage = {
index: 1,
};
export const mockRuleOptions: RuleOptions = {
name: 'RuleOptionsName',
id: 'RuleOptionsID',
severity: 'low',
tags: ['mock.tag'],
};
export const mockCreateDetectorRulesOptions: CreateDetectorRulesOptions = {
page: mockRulesPage,
rulesOptions: [mockRuleOptions],
};

export default {
alertCondition: mockAlertCondition,
allNotificationChannels: [mockNotificationChannelTypeOptions],
rulesOptions: [mockRuleOptions],
detector: mockDetector,
indexNum: 1,
isEdit: false,
hasNotificationPlugin: false,
loadingNotifications: false,
onAlertTriggerChanged: jest.fn(),
refreshNotificationChannels: jest.fn(),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { RuleInfo, RuleSource } from '../../../../../server/models/interfaces';
import { mockAlertCondition, mockDetector } from '../../../Interfaces.mock';

const mockRuleSource: RuleSource = {
rule: 'ruleName',
last_update_time: '12/12/2022',
queries: [{ value: '.windows' }],
};

const mockRuleInfo: RuleInfo = {
_id: 'ruleId',
_index: '.windows',
_primary_term: 1,
_source: mockRuleSource,
_version: 1,
};

export default {
alertTrigger: mockAlertCondition,
orderPosition: 1,
detector: mockDetector,
notificationChannels: [],
rules: { rileId: mockRuleInfo },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { mockDetector } from '../../../Interfaces.mock';

export default {
detector: mockDetector,
rulesCanFold: true,
enabled_time: 1,
last_update_time: 1,
onEditClicked: () => jest.fn(),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { mockDetector, mockNotificationsStart } from '../../../Interfaces.mock';

export default {
detector: mockDetector,
rulesCanFold: false,
onEditClicked: jest.fn(),
notifications: mockNotificationsStart,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { FieldMapping } from '../../../../../models/interfaces';
import { mockDetector, mockNotificationsStart } from '../../../Interfaces.mock';

const mockFieldMapping: FieldMapping = {
indexFieldName: 'indexFieldName',
ruleFieldName: 'ruleFieldName',
};
export default {
detector: mockDetector,
existingMappings: [mockFieldMapping, mockFieldMapping],
editFieldMappings: jest.fn(),
notifications: mockNotificationsStart,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
DetectorsService,
NotificationsService,
OpenSearchService,
RuleService,
} from '../../../../services';
import { mockDetectorHit, mockNotificationsStart } from '../../../Interfaces.mock';

const mockNotificationsService: NotificationsService = {
getChannels: () => {
return {
ok: true,
response: {
channel_list: [],
},
};
},
};

const mockRuleService: RuleService = {
getRules: () => {
return {
ok: true,
response: {
hits: {
hits: [],
},
},
};
},
};
export default {
detectorHit: mockDetectorHit,
detectorService: DetectorsService,
opensearchService: OpenSearchService,
ruleService: mockRuleService,
notificationsService: mockNotificationsService,
notifications: mockNotificationsStart,
location: {
state: {
detectorHit: mockDetectorHit,
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { mockDetectorHit, mockHistory, mockNotificationsStart } from '../../../Interfaces.mock';

export default {
notifications: mockNotificationsStart,
detectorHit: mockDetectorHit,
location: {
pathname: '/edit-detector-details/detectorHitId',
},
history: mockHistory,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { mockDetectorHit, mockNotificationsStart } from '../../../Interfaces.mock';

export default {
notifications: mockNotificationsStart,
detectorHit: mockDetectorHit,
location: {
pathname: '',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
mockDetectorHit,
mockDetectorService,
mockHistory,
mockNotificationsStart,
} from '../../../Interfaces.mock';
import FieldMappingService from '../../../../services/FieldMappingService';

export const mockFieldMappingService: FieldMappingService = {
createMappings: () => {
return Promise.resolve({
ok: true,
});
},
getMappingsView: () => {
return {
ok: true,
response: {
properties: {},
},
};
},
getMappings: () => {
return {
ok: true,
response: {
'.windows': {
mappings: {
properties: {},
},
},
},
};
},
};

export default {
detectorHit: mockDetectorHit,
detectorService: mockDetectorService,
notifications: mockNotificationsStart,
filedMappingService: mockFieldMappingService,
location: {
state: {
detectorHit: mockDetectorHit,
},
pathname: '/edit-field-mappings/detectorHitId',
},
history: mockHistory,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { mockDetector, mockNotificationsStart } from '../../../Interfaces.mock';

export default {
detector: mockDetector,
editAlertTriggers: jest.fn(),
notifications: mockNotificationsStart,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {
mockDetectorHit,
mockDetectorService,
mockHistory,
mockNotificationsStart,
} from '../../../Interfaces.mock';

export default {
detectorHit: mockDetectorHit,
detectorService: mockDetectorService,
notifications: mockNotificationsStart,
location: {
pathname: '/detector-details/detectorHitId',
},
history: mockHistory,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { mockDetector, mockNotificationsStart } from '../../../Interfaces.mock';

export default {
detector: mockDetector,
enabled_time: 1,
last_update_time: 1,
rulesCanFold: false,
notifications: mockNotificationsStart,
editBasicDetails: jest.fn(),
editDetectorRules: jest.fn(),
};
11 changes: 11 additions & 0 deletions public/models/Detectors/containers/Detectors/Detectors.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { mockDetectorService, mockNotificationsStart } from '../../../Interfaces.mock';

export default {
detectorService: mockDetectorService,
notifications: mockNotificationsStart,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { mockDetector } from '../../../Interfaces.mock';
import { mockFieldMappingService } from '../../components/UpdateFieldMappings/UpdateFieldMappings.mock';

export default {
detector: mockDetector,
filedMappingService: mockFieldMappingService,
fieldMappings: [],
loading: false,
replaceFieldMappings: jest.fn(),
};
Loading