Skip to content

Commit

Permalink
Add getEnsaVersion selector
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-suse committed Dec 12, 2023
1 parent b812c65 commit 49e7361
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 0 deletions.
14 changes: 14 additions & 0 deletions assets/js/state/selectors/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ export const getClusterSapSystems = createSelector(
}
);

export const getEnsaVersion = createSelector(
[(state, clusterID) => getClusterSapSystems(state, clusterID)],
(sapSystems) => {
const ensaVersions = new Set();
sapSystems.forEach(({ ensa_version }) => ensaVersions.add(ensa_version));

const firstEnsaVersion = [...ensaVersions.values()][0];

return firstEnsaVersion && ensaVersions.size === 1
? firstEnsaVersion
: 'mixed_versions';
}
);

export const getClusterSelectedChecks = createSelector(
[(state, clusterID) => getCluster(clusterID)(state)],
(cluster) => get(cluster, 'selected_checks', [])
Expand Down
176 changes: 176 additions & 0 deletions assets/js/state/selectors/cluster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getClusterSapSystems,
getClusterSelectedChecks,
getClusterIDs,
getEnsaVersion,
} from './cluster';

describe('Cluster selector', () => {
Expand Down Expand Up @@ -205,4 +206,179 @@ describe('Cluster selector', () => {

expect(getClusterIDs(state)).toEqual([clusterID1, clusterID2]);
});

it('should return ENSA version', () => {
const clusterID = faker.string.uuid();
const cluster = clusterFactory.build({ id: clusterID });

const sapSystems = sapSystemFactory.buildList(2, { ensa_version: 'ensa1' });
const [{ id: sapSystem1 }, { id: sapSystem2 }] = sapSystems;

const hosts = hostFactory
.buildList(4, { cluster_id: clusterID })
.concat(hostFactory.buildList(2));
const [{ id: host1 }, { id: host2 }, { id: host3 }, { id: host4 }] = hosts;

const applicationInstances = [
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host1,
}),
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host2,
}),
];

const databases = databaseFactory.buildList(4);

const databaseInstances = [
databaseInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host3,
}),
databaseInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host4,
}),
];

const state = {
hostsList: {
hosts,
},
databasesList: {
databases,
databaseInstances,
},
sapSystemsList: {
sapSystems,
applicationInstances,
databaseInstances,
},
clustersList: {
clusters: [cluster],
},
};

expect(getEnsaVersion(state, clusterID)).toEqual('ensa1');
});

it('should return mixed ENSA versions', () => {
const clusterID = faker.string.uuid();
const cluster = clusterFactory.build({ id: clusterID });

const sapSystems = [
sapSystemFactory.build({ ensa_version: 'ensa1' }),
sapSystemFactory.build({ ensa_version: 'ensa2' }),
];
const [{ id: sapSystem1 }, { id: sapSystem2 }] = sapSystems;

const hosts = hostFactory
.buildList(4, { cluster_id: clusterID })
.concat(hostFactory.buildList(2));
const [{ id: host1 }, { id: host2 }, { id: host3 }, { id: host4 }] = hosts;

const applicationInstances = [
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host1,
}),
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host2,
}),
];

const databases = databaseFactory.buildList(4);

const databaseInstances = [
databaseInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host3,
}),
databaseInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host4,
}),
];

const state = {
hostsList: {
hosts,
},
databasesList: {
databases,
databaseInstances,
},
sapSystemsList: {
sapSystems,
applicationInstances,
databaseInstances,
},
clustersList: {
clusters: [cluster],
},
};

expect(getEnsaVersion(state, clusterID)).toEqual('mixed_versions');
});

it('should return mixed ENSA versions if SAP system does not have ENSA version info', () => {
const clusterID = faker.string.uuid();
const cluster = clusterFactory.build({ id: clusterID });

const sapSystems = sapSystemFactory.buildList(2, { ensa_version: 'ensa1' });
const [{ id: sapSystem1 }, { id: sapSystem2 }] = sapSystems;

const hosts = hostFactory
.buildList(4, { cluster_id: clusterID })
.concat(hostFactory.buildList(2));
const [{ id: host1 }, { id: host2 }, { id: host3 }, { id: host4 }] = hosts;

const applicationInstances = [
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host1,
}),
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host2,
}),
];

const databases = databaseFactory.buildList(4);
const [{ id: database1 }, { id: database2 }] = databases;

const databaseInstances = [
databaseInstanceFactory.build({
sap_system_id: database1,
host_id: host3,
}),
databaseInstanceFactory.build({
sap_system_id: database2,
host_id: host4,
}),
];

const state = {
hostsList: {
hosts,
},
databasesList: {
databases,
databaseInstances,
},
sapSystemsList: {
sapSystems,
applicationInstances,
databaseInstances,
},
clustersList: {
clusters: [cluster],
},
};

expect(getEnsaVersion(state, clusterID)).toEqual('mixed_versions');
});
});

0 comments on commit 49e7361

Please sign in to comment.