Skip to content

Commit

Permalink
refactor(rhsmServices): sw-690 metric capacity (#1017)
Browse files Browse the repository at this point in the history
* bannerMessagesContext, adjust type ref
* redux, rhsmActions, clean up tally, capacity
* rhsmConstants, merge tally capacity types
* rhsmServices, remove deprecated capacity
* rhsmSchema, metric capacity
* rhsmTransormers, merge tally capacity funcs
  • Loading branch information
cdcabrera committed Dec 12, 2022
1 parent 4972236 commit c834721
Show file tree
Hide file tree
Showing 12 changed files with 524 additions and 699 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('BannerMessagesContext', () => {
data: {
data: [
{
[rhsmConstants.RHSM_API_RESPONSE_TALLY_META_TYPES.HAS_CLOUDIGRADE_MISMATCH]: true
[rhsmConstants.RHSM_API_RESPONSE_TALLY_CAPACITY_META_TYPES.HAS_CLOUDIGRADE_MISMATCH]: true
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/bannerMessages/bannerMessagesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const useGetAppMessages = ({
messages?.data
?.reverse()
?.find(
({ [rhsmConstants.RHSM_API_RESPONSE_TALLY_META_TYPES.HAS_CLOUDIGRADE_MISMATCH]: mismatch }) =>
({ [rhsmConstants.RHSM_API_RESPONSE_TALLY_CAPACITY_META_TYPES.HAS_CLOUDIGRADE_MISMATCH]: mismatch }) =>
mismatch === true
) !== undefined;
}
Expand Down
27 changes: 0 additions & 27 deletions src/redux/actions/__tests__/rhsmActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ describe('RhsmActions', () => {
moxios.uninstall();
});

it('Should return response content for getGraphReportsCapacity method', done => {
const store = generateStore();
const dispatcher = rhsmActions.getGraphReportsCapacity();

dispatcher(store.dispatch).then(() => {
const response = store.getState().graph;
expect(response.reportCapacity.fulfilled).toBe(true);
done();
});
});

it('Should return response content for getGraphMetrics method', done => {
const store = generateStore();
const dispatcher = rhsmActions.getGraphMetrics([
Expand All @@ -70,22 +59,6 @@ describe('RhsmActions', () => {
});
});

it('Should return response content for getGraphTally method', done => {
const store = generateStore();
const dispatcher = rhsmActions.getGraphTally([
{ id: 'lorem', metric: 'ipsum' },
{ id: 'dolor', metric: 'sit' }
]);

dispatcher(store.dispatch).then(() => {
const response = store.getState().graph;
expect(response.tally.lorem_ipsum.fulfilled).toBe(true);
expect(response.tally.dolor_sit.fulfilled).toBe(true);
expect(Object.entries(response.tally).length).toBe(2);
done();
});
});

it('Should return response content for getHostsInventory method', done => {
const store = generateStore();
const dispatcher = rhsmActions.getHostsInventory();
Expand Down
66 changes: 0 additions & 66 deletions src/redux/actions/rhsmActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,6 @@ import { rhsmTypes } from '../types';
import { rhsmServices } from '../../services/rhsm/rhsmServices';
import { generateChartIds } from '../../components/graphCard/graphCardHelpers';

/**
* Get a combined RHSM response from reporting and capacity.
*
* @param {string} id
* @param {object} query
* @param {object} options
* @param {string} options.cancelId
* @returns {Function}
*/
const getGraphReportsCapacity =
(id = null, query = {}, options = {}) =>
dispatch => {
const { cancelId = 'graphReportsCapacity' } = options;

return dispatch({
type: rhsmTypes.GET_GRAPH_REPORT_CAPACITY_RHSM,
payload: Promise.all([
rhsmServices.getGraphReports(id, query, { cancelId }),
rhsmServices.getGraphCapacityDeprecated(id, query, { cancelId })
]),
meta: {
id,
query,
notifications: {}
}
});
};

/**
* Get a RHSM response from multiple Tally IDs and metrics.
*
* @param {object|Array} idMetric An object, or an Array of objects, in the form of { id: PRODUCT_ID, metric: METRIC_ID }
* @param {object} query
* @param {object} options
* @param {string} options.cancelId
* @returns {Function}
*/
const getGraphTally =
(idMetric = {}, query = {}, options = {}) =>
dispatch => {
const { cancelId = 'graphTally' } = options;
const multiMetric = (Array.isArray(idMetric) && idMetric) || [idMetric];
const multiDispatch = [];

multiMetric.forEach(({ id, metric }) => {
multiDispatch.push({
type: rhsmTypes.GET_GRAPH_TALLY_RHSM,
payload: rhsmServices.getGraphTally([id, metric], query, {
cancelId: `${cancelId}_${id}_${metric}`
}),
meta: {
id: `${id}_${metric}`,
idMetric: { id, metric },
query,
notifications: {}
}
});
});

return Promise.all(dispatch(multiDispatch));
};

/**
* Get a RHSM response from multiple Tally, or Capacity, IDs and metrics.
*
Expand Down Expand Up @@ -208,8 +146,6 @@ const getSubscriptionsInventory =

const rhsmActions = {
getGraphMetrics,
getGraphReportsCapacity,
getGraphTally,
getHostsInventory,
getHostsInventoryGuests,
getInstancesInventory,
Expand All @@ -221,8 +157,6 @@ export {
rhsmActions as default,
rhsmActions,
getGraphMetrics,
getGraphReportsCapacity,
getGraphTally,
getHostsInventory,
getHostsInventoryGuests,
getInstancesInventory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,6 @@ exports[`RHSM Constants should have specific properties: all exported constants
"AWS": "aws",
"RED_HAT": "red hat",
},
"RHSM_API_RESPONSE_CAPACITY_DATA_TYPES": {
"CORES": "cores",
"DATE": "date",
"HAS_INFINITE_QUANTITY": "has_infinite_quantity",
"SOCKETS": "sockets",
},
"RHSM_API_RESPONSE_CAPACITY_META_TYPES": {
"COUNT": "count",
"METRIC_ID": "metric_id",
"PRODUCT": "product",
},
"RHSM_API_RESPONSE_DATA": "data",
"RHSM_API_RESPONSE_ERRORS": "errors",
"RHSM_API_RESPONSE_ERRORS_CODE_TYPES": {
Expand Down Expand Up @@ -255,12 +244,13 @@ exports[`RHSM Constants should have specific properties: all exported constants
"ANNUAL": "Annual",
"ON_DEMAND": "On-demand",
},
"RHSM_API_RESPONSE_TALLY_DATA_TYPES": {
"RHSM_API_RESPONSE_TALLY_CAPACITY_DATA_TYPES": {
"DATE": "date",
"HAS_DATA": "has_data",
"HAS_INFINITE_QUANTITY": "has_infinite_quantity",
"VALUE": "value",
},
"RHSM_API_RESPONSE_TALLY_META_TYPES": {
"RHSM_API_RESPONSE_TALLY_CAPACITY_META_TYPES": {
"COUNT": "count",
"DATE": "date",
"HAS_CLOUDIGRADE_DATA": "has_cloudigrade_data",
Expand Down Expand Up @@ -445,17 +435,6 @@ exports[`RHSM Constants should have specific properties: all exported constants
"AWS": "aws",
"RED_HAT": "red hat",
},
"RHSM_API_RESPONSE_CAPACITY_DATA_TYPES": {
"CORES": "cores",
"DATE": "date",
"HAS_INFINITE_QUANTITY": "has_infinite_quantity",
"SOCKETS": "sockets",
},
"RHSM_API_RESPONSE_CAPACITY_META_TYPES": {
"COUNT": "count",
"METRIC_ID": "metric_id",
"PRODUCT": "product",
},
"RHSM_API_RESPONSE_DATA": "data",
"RHSM_API_RESPONSE_ERRORS": "errors",
"RHSM_API_RESPONSE_ERRORS_CODE_TYPES": {
Expand Down Expand Up @@ -541,12 +520,13 @@ exports[`RHSM Constants should have specific properties: all exported constants
"ANNUAL": "Annual",
"ON_DEMAND": "On-demand",
},
"RHSM_API_RESPONSE_TALLY_DATA_TYPES": {
"RHSM_API_RESPONSE_TALLY_CAPACITY_DATA_TYPES": {
"DATE": "date",
"HAS_DATA": "has_data",
"HAS_INFINITE_QUANTITY": "has_infinite_quantity",
"VALUE": "value",
},
"RHSM_API_RESPONSE_TALLY_META_TYPES": {
"RHSM_API_RESPONSE_TALLY_CAPACITY_META_TYPES": {
"COUNT": "count",
"DATE": "date",
"HAS_CLOUDIGRADE_DATA": "has_cloudigrade_data",
Expand Down Expand Up @@ -732,17 +712,6 @@ exports[`RHSM Constants should have specific properties: all exported constants
"AWS": "aws",
"RED_HAT": "red hat",
},
"RHSM_API_RESPONSE_CAPACITY_DATA_TYPES": {
"CORES": "cores",
"DATE": "date",
"HAS_INFINITE_QUANTITY": "has_infinite_quantity",
"SOCKETS": "sockets",
},
"RHSM_API_RESPONSE_CAPACITY_META_TYPES": {
"COUNT": "count",
"METRIC_ID": "metric_id",
"PRODUCT": "product",
},
"RHSM_API_RESPONSE_DATA": "data",
"RHSM_API_RESPONSE_ERRORS": "errors",
"RHSM_API_RESPONSE_ERRORS_CODE_TYPES": {
Expand Down Expand Up @@ -828,12 +797,13 @@ exports[`RHSM Constants should have specific properties: all exported constants
"ANNUAL": "Annual",
"ON_DEMAND": "On-demand",
},
"RHSM_API_RESPONSE_TALLY_DATA_TYPES": {
"RHSM_API_RESPONSE_TALLY_CAPACITY_DATA_TYPES": {
"DATE": "date",
"HAS_DATA": "has_data",
"HAS_INFINITE_QUANTITY": "has_infinite_quantity",
"VALUE": "value",
},
"RHSM_API_RESPONSE_TALLY_META_TYPES": {
"RHSM_API_RESPONSE_TALLY_CAPACITY_META_TYPES": {
"COUNT": "count",
"DATE": "date",
"HAS_CLOUDIGRADE_DATA": "has_cloudigrade_data",
Expand Down Expand Up @@ -1023,17 +993,6 @@ exports[`RHSM Constants should have specific properties: specific constants 1`]
"AWS": "aws",
"RED_HAT": "red hat",
},
"RHSM_API_RESPONSE_CAPACITY_DATA_TYPES": {
"CORES": "cores",
"DATE": "date",
"HAS_INFINITE_QUANTITY": "has_infinite_quantity",
"SOCKETS": "sockets",
},
"RHSM_API_RESPONSE_CAPACITY_META_TYPES": {
"COUNT": "count",
"METRIC_ID": "metric_id",
"PRODUCT": "product",
},
"RHSM_API_RESPONSE_DATA": "data",
"RHSM_API_RESPONSE_ERRORS": "errors",
"RHSM_API_RESPONSE_ERRORS_CODE_TYPES": {
Expand Down Expand Up @@ -1119,12 +1078,13 @@ exports[`RHSM Constants should have specific properties: specific constants 1`]
"ANNUAL": "Annual",
"ON_DEMAND": "On-demand",
},
"RHSM_API_RESPONSE_TALLY_DATA_TYPES": {
"RHSM_API_RESPONSE_TALLY_CAPACITY_DATA_TYPES": {
"DATE": "date",
"HAS_DATA": "has_data",
"HAS_INFINITE_QUANTITY": "has_infinite_quantity",
"VALUE": "value",
},
"RHSM_API_RESPONSE_TALLY_META_TYPES": {
"RHSM_API_RESPONSE_TALLY_CAPACITY_META_TYPES": {
"COUNT": "count",
"DATE": "date",
"HAS_CLOUDIGRADE_DATA": "has_cloudigrade_data",
Expand Down
Loading

0 comments on commit c834721

Please sign in to comment.