Skip to content

Commit

Permalink
Add tests to cover the migrations cases
Browse files Browse the repository at this point in the history
  • Loading branch information
WafaaNasr committed Apr 26, 2023
1 parent fe788e7 commit 4a75a51
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 75 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/lists/common/constants.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,6 @@ export const _VERSION = 'WzI5NywxXQ==';
export const VERSION = 1;
export const IMMUTABLE = false;
export const IMPORT_TIMEOUT = moment.duration(5, 'minutes');

/** Added in 8.7 */
export const EXPIRE_TIME = '2023-04-24T19:00:00.000Z';
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
COMMENTS,
DESCRIPTION,
ENTRIES,
EXPIRE_TIME,
ITEM_ID,
ITEM_TYPE,
LIST_ID,
Expand Down Expand Up @@ -60,3 +61,18 @@ export const getCreateExceptionListItemMinimalSchemaMockWithoutId =
os_types: OS_TYPES,
type: ITEM_TYPE,
});

/**
* Useful for testing newer exception list item versions, as the previous
* versions can be used to test migration cases
*/
export const getCreateExceptionListItemNewerVersionSchemaMock =
(): CreateExceptionListItemSchema => ({
description: DESCRIPTION,
entries: ENTRIES,
expire_time: EXPIRE_TIME,
list_id: LIST_ID,
name: NAME,
os_types: OS_TYPES,
type: ITEM_TYPE,
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ImportExceptionsListSchema,
} from '@kbn/securitysolution-io-ts-list-types';

import { ENTRIES } from '../../constants.mock';
import { ENTRIES, EXPIRE_TIME } from '../../constants.mock';

export const getImportExceptionsListSchemaMock = (
listId = 'detection_list_id'
Expand All @@ -23,6 +23,10 @@ export const getImportExceptionsListSchemaMock = (
type: 'detection',
});

/**
This mock holds the old properties of the Exception List item
so that we can test the migration test cases
*/
export const getImportExceptionsListItemSchemaMock = (
itemId = 'item_id_1',
listId = 'detection_list_id'
Expand All @@ -35,6 +39,23 @@ export const getImportExceptionsListItemSchemaMock = (
type: 'simple',
});

/**
This mock will hold the new properties of the Exception List item
so please keep it updated with the new ones and use it to test the
new scenarios
*/
export const getImportExceptionsListItemNewerVersionSchemaMock = (
itemId = 'item_id_1',
listId = 'detection_list_id'
): ImportExceptionListItemSchema => ({
description: 'some description',
entries: ENTRIES,
expire_time: EXPIRE_TIME,
item_id: itemId,
list_id: listId,
name: 'Query with a rule id',
type: 'simple',
});
export const getImportExceptionsListSchemaDecodedMock = (
listId = 'detection_list_id'
): ImportExceptionListSchemaDecoded => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
import { getExceptionList } from '../../../objects/exception';

// Test Skipped until we fix the Flyout rerendering issue
// https://github.com/elastic/kibana/issues/154994

// NOTE: You might look at these tests and feel they're overkill,
// but the exceptions flyout has a lot of logic making it difficult
Expand Down
Loading

0 comments on commit 4a75a51

Please sign in to comment.