Skip to content

Commit

Permalink
Add tests for convertFeaturesListToArray
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed Oct 4, 2021
1 parent 5cca444 commit 357d6b2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x-pack/plugins/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export interface SystemIndicesUpgradeFeature {
upgrade_status: UPGRADE_STATUS;
indices: Array<{
index: string;
index_version: string;
version: string;
}>;
}
export interface SystemIndicesUpgradeStatus {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { convertFeaturesListToArray } from './es_system_indices_upgrade';
import { SystemIndicesUpgradeStatus } from '../../common/types';

const esUpgradeSystemIndicesStatusMock: SystemIndicesUpgradeStatus = {
features: [
{
feature_name: 'machine_learning',
minimum_index_version: '7.1.1',
upgrade_status: 'UPGRADE_NEEDED',
indices: [
{
index: '.ml-config',
version: '7.1.1',
},
{
index: '.ml-notifications',
version: '7.1.1',
},
],
},
{
feature_name: 'security',
minimum_index_version: '7.1.1',
upgrade_status: 'UPGRADE_NEEDED',
indices: [
{
index: '.ml-config',
version: '7.1.1',
},
],
},
],
upgrade_status: 'UPGRADE_NEEDED',
};

describe('convertFeaturesListToArray', () => {
it('converts list with features to flat array of uniq indices', async () => {
const result = convertFeaturesListToArray(esUpgradeSystemIndicesStatusMock.features);
expect(result).toEqual(['.ml-config', '.ml-notifications']);
});

it('returns empty array if no features are passed to it', async () => {
const result = convertFeaturesListToArray([]);
expect(result).toEqual([]);
});
});

0 comments on commit 357d6b2

Please sign in to comment.