Skip to content

Commit

Permalink
feat(rhsmServices,redux): ent-4367 instances inventory (#830)
Browse files Browse the repository at this point in the history
* dotenv, instances table disable and endpoint
* helpers, expose table disable
* redux, action, reducer, selector for instances response
* rhsmConstants, Types, updated constants, cross linked
* rhsmSchemas, instances schema
* rhsmServices, get instances endpoint
* rhsmTransformers, instances response transform
  • Loading branch information
cdcabrera committed Nov 29, 2021
1 parent 52d1648 commit f58b073
Show file tree
Hide file tree
Showing 26 changed files with 838 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ REACT_APP_UI_DISABLED_TOOLBAR=false
REACT_APP_UI_DISABLED_GRAPH=false
REACT_APP_UI_DISABLED_TABLE=false
REACT_APP_UI_DISABLED_TABLE_HOSTS=false
REACT_APP_UI_DISABLED_TABLE_INSTANCES=false
REACT_APP_UI_DISABLED_TABLE_SUBSCRIPTIONS=false
REACT_APP_UI_LOGGER_ID=curiosity
REACT_APP_UI_LOGGER_FILE=curiosity_debug_log_{0}.json
Expand All @@ -37,5 +38,6 @@ REACT_APP_SERVICES_RHSM_TALLY=/api/rhsm-subscriptions/v1/tally/products/{0}/{1}
REACT_APP_SERVICES_RHSM_CAPACITY=/api/rhsm-subscriptions/v1/capacity/products/
REACT_APP_SERVICES_RHSM_INVENTORY=/api/rhsm-subscriptions/v1/hosts/products/
REACT_APP_SERVICES_RHSM_INVENTORY_GUESTS=/api/rhsm-subscriptions/v1/hosts/{0}/guests
REACT_APP_SERVICES_RHSM_INVENTORY_INSTANCES=/api/rhsm-subscriptions/v1/instances/products/
REACT_APP_SERVICES_RHSM_INVENTORY_SUBSCRIPTIONS=/api/rhsm-subscriptions/v1/subscriptions/products/
REACT_APP_SERVICES_RHSM_OPTIN=/api/rhsm-subscriptions/v1/opt-in
3 changes: 2 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DEV_PORT=3000
DEV_BRANCH=ci-beta
DEV_BRANCH=ci-stable

REACT_APP_ENV=development

Expand All @@ -9,5 +9,6 @@ REACT_APP_SERVICES_RHSM_TALLY=http://localhost:5000/api/rhsm-subscriptions/v1/ta
REACT_APP_SERVICES_RHSM_CAPACITY=http://localhost:5000/api/rhsm-subscriptions/v1/capacity/products/
REACT_APP_SERVICES_RHSM_INVENTORY=http://localhost:5000/api/rhsm-subscriptions/v1/hosts/products/
REACT_APP_SERVICES_RHSM_INVENTORY_GUESTS=//localhost:5000/api/rhsm-subscriptions/v1/hosts/{0}/guests
REACT_APP_SERVICES_RHSM_INVENTORY_INSTANCES=//localhost:5000/api/rhsm-subscriptions/v1/instances/products/
REACT_APP_SERVICES_RHSM_INVENTORY_SUBSCRIPTIONS=//localhost:5000/api/rhsm-subscriptions/v1/subscriptions/products/
REACT_APP_SERVICES_RHSM_OPTIN=http://localhost:5000/api/rhsm-subscriptions/v1/opt-in
3 changes: 3 additions & 0 deletions src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Object {
"UI_DISABLED_GRAPH": false,
"UI_DISABLED_TABLE": false,
"UI_DISABLED_TABLE_HOSTS": false,
"UI_DISABLED_TABLE_INSTANCES": false,
"UI_DISABLED_TABLE_SUBSCRIPTIONS": false,
"UI_DISABLED_TOOLBAR": false,
"UI_DISPLAY_CONFIG_NAME": "Subscriptions",
Expand Down Expand Up @@ -56,6 +57,7 @@ Object {
"UI_DISABLED_GRAPH": false,
"UI_DISABLED_TABLE": false,
"UI_DISABLED_TABLE_HOSTS": false,
"UI_DISABLED_TABLE_INSTANCES": false,
"UI_DISABLED_TABLE_SUBSCRIPTIONS": false,
"UI_DISABLED_TOOLBAR": false,
"UI_DISPLAY_CONFIG_NAME": "Subscriptions",
Expand Down Expand Up @@ -95,6 +97,7 @@ Object {
"UI_DISABLED_GRAPH": false,
"UI_DISABLED_TABLE": false,
"UI_DISABLED_TABLE_HOSTS": false,
"UI_DISABLED_TABLE_INSTANCES": false,
"UI_DISABLED_TABLE_SUBSCRIPTIONS": false,
"UI_DISABLED_TOOLBAR": false,
"UI_DISPLAY_CONFIG_NAME": "Subscriptions",
Expand Down
9 changes: 9 additions & 0 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ const UI_DISABLED_TABLE = process.env.REACT_APP_UI_DISABLED_TABLE === 'true';
*/
const UI_DISABLED_TABLE_HOSTS = process.env.REACT_APP_UI_DISABLED_TABLE_HOSTS === 'true';

/**
* Disable the current instances inventory/table aspect of the UI.
* See dotenv config files for activation.
*
* @type {boolean}
*/
const UI_DISABLED_TABLE_INSTANCES = process.env.REACT_APP_UI_DISABLED_TABLE_INSTANCES === 'true';

/**
* Disable the current subscriptions inventory/table aspect of the UI.
* See dotenv config files for activation.
Expand Down Expand Up @@ -306,6 +314,7 @@ const helpers = {
UI_DISABLED_GRAPH,
UI_DISABLED_TABLE,
UI_DISABLED_TABLE_HOSTS,
UI_DISABLED_TABLE_INSTANCES,
UI_DISABLED_TABLE_SUBSCRIPTIONS,
UI_DISABLED_TOOLBAR,
UI_DISPLAY_NAME,
Expand Down
13 changes: 12 additions & 1 deletion src/redux/actions/__tests__/rhsmActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('RhsmActions', () => {
beforeEach(() => {
moxios.install();

moxios.stubRequest(/\/(tally|capacity|hosts|subscriptions|version).*?/, {
moxios.stubRequest(/\/(tally|capacity|hosts|instances|subscriptions|version).*?/, {
status: 200,
responseText: 'success',
timeout: 1,
Expand Down Expand Up @@ -86,6 +86,17 @@ describe('RhsmActions', () => {
});
});

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

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

it('Should return response content for getMessageReports method', done => {
const store = generateStore();
const dispatcher = rhsmActions.getMessageReports();
Expand Down
20 changes: 20 additions & 0 deletions src/redux/actions/rhsmActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ const getHostsInventoryGuests = (id = null, query = {}) => dispatch =>
}
});

/**
* Get an instances response listing from RHSM subscriptions.
*
* @param {string} id
* @param {object} query
* @returns {Function}
*/
const getInstancesInventory = (id = null, query = {}) => dispatch =>
dispatch({
type: rhsmTypes.GET_INSTANCES_INVENTORY_RHSM,
payload: rhsmServices.getInstancesInventory(id, query),
meta: {
id,
query,
notifications: {}
}
});

/**
* Get a RHSM response from message reporting.
*
Expand Down Expand Up @@ -136,6 +154,7 @@ const rhsmActions = {
getGraphTally,
getHostsInventory,
getHostsInventoryGuests,
getInstancesInventory,
getMessageReports,
getSubscriptionsInventory
};
Expand All @@ -147,6 +166,7 @@ export {
getGraphTally,
getHostsInventory,
getHostsInventoryGuests,
getInstancesInventory,
getMessageReports,
getSubscriptionsInventory
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Object {
"status": 0,
},
"hostsInventory": Object {},
"instancesInventory": Object {},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
Expand All @@ -31,18 +32,40 @@ Object {
"pending": false,
"status": 0,
},
"instancesInventory": Object {},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_REJECTED",
}
`;

exports[`InventoryReducer should handle all defined error types: rejected types GET_INSTANCES_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {},
"instancesInventory": Object {
"error": true,
"errorMessage": "MESSAGE",
"fulfilled": false,
"meta": Object {},
"pending": false,
"status": 0,
},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
"type": "GET_INSTANCES_INVENTORY_RHSM_REJECTED",
}
`;

exports[`InventoryReducer should handle all defined error types: rejected types GET_SUBSCRIPTIONS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {},
"instancesInventory": Object {},
"subscriptionsInventory": Object {
"error": true,
"errorMessage": "MESSAGE",
Expand Down Expand Up @@ -73,6 +96,7 @@ Object {
"status": 0,
},
"hostsInventory": Object {},
"instancesInventory": Object {},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
Expand All @@ -96,18 +120,44 @@ Object {
"pending": false,
"status": 0,
},
"instancesInventory": Object {},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_FULFILLED",
}
`;

exports[`InventoryReducer should handle all defined fulfilled types: fulfilled types GET_INSTANCES_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {},
"instancesInventory": Object {
"data": Object {
"test": "success",
},
"date": null,
"error": false,
"errorMessage": "",
"fulfilled": true,
"meta": Object {},
"pending": false,
"status": 0,
},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
"type": "GET_INSTANCES_INVENTORY_RHSM_FULFILLED",
}
`;

exports[`InventoryReducer should handle all defined fulfilled types: fulfilled types GET_SUBSCRIPTIONS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {},
"instancesInventory": Object {},
"subscriptionsInventory": Object {
"data": Object {
"test": "success",
Expand Down Expand Up @@ -137,6 +187,7 @@ Object {
"pending": true,
},
"hostsInventory": Object {},
"instancesInventory": Object {},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
Expand All @@ -155,18 +206,39 @@ Object {
"meta": Object {},
"pending": true,
},
"instancesInventory": Object {},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_PENDING",
}
`;

exports[`InventoryReducer should handle all defined pending types: pending types GET_INSTANCES_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {},
"instancesInventory": Object {
"error": false,
"errorMessage": "",
"fulfilled": false,
"meta": Object {},
"pending": true,
},
"subscriptionsInventory": Object {},
"tabs": Object {},
},
"type": "GET_INSTANCES_INVENTORY_RHSM_PENDING",
}
`;

exports[`InventoryReducer should handle all defined pending types: pending types GET_SUBSCRIPTIONS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {},
"instancesInventory": Object {},
"subscriptionsInventory": Object {
"error": false,
"errorMessage": "",
Expand All @@ -185,6 +257,7 @@ Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {},
"instancesInventory": Object {},
"subscriptionsInventory": Object {},
"tabs": Object {
"lorem": 1,
Expand Down
3 changes: 3 additions & 0 deletions src/redux/reducers/__tests__/inventoryReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('InventoryReducer', () => {
const specificTypes = [
types.GET_HOSTS_INVENTORY_RHSM,
types.GET_HOSTS_INVENTORY_GUESTS_RHSM,
types.GET_INSTANCES_INVENTORY_RHSM,
types.GET_SUBSCRIPTIONS_INVENTORY_RHSM
];

Expand Down Expand Up @@ -59,6 +60,7 @@ describe('InventoryReducer', () => {
const specificTypes = [
types.GET_HOSTS_INVENTORY_RHSM,
types.GET_HOSTS_INVENTORY_GUESTS_RHSM,
types.GET_INSTANCES_INVENTORY_RHSM,
types.GET_SUBSCRIPTIONS_INVENTORY_RHSM
];

Expand All @@ -79,6 +81,7 @@ describe('InventoryReducer', () => {
const specificTypes = [
types.GET_HOSTS_INVENTORY_RHSM,
types.GET_HOSTS_INVENTORY_GUESTS_RHSM,
types.GET_INSTANCES_INVENTORY_RHSM,
types.GET_SUBSCRIPTIONS_INVENTORY_RHSM
];

Expand Down
2 changes: 1 addition & 1 deletion src/redux/reducers/graphReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { reduxHelpers } from '../common/reduxHelpers';
* Initial state.
*
* @private
* @type {{reportCapacity: {}, legend: {}, tallyCapacity: {}}}
* @type {{reportCapacity: {}, legend: {}, tally: {}}}
*/
const initialState = {
legend: {},
Expand Down
4 changes: 3 additions & 1 deletion src/redux/reducers/inventoryReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { inventoryTypes } from '../types';
* Initial state.
*
* @private
* @type {{subscriptionsInventory: {}, tabs: {}, hostsInventory: {}, hostsGuests: {}}}
* @type {{subscriptionsInventory: {}, instancesInventory: {}, tabs: {}, hostsInventory: {}, hostsGuests: {}}}
*/
const initialState = {
hostsInventory: {},
hostsGuests: {},
instancesInventory: {},
subscriptionsInventory: {},
tabs: {}
};
Expand Down Expand Up @@ -41,6 +42,7 @@ const inventoryReducer = (state = initialState, action) => {
[
{ ref: 'hostsInventory', type: rhsmTypes.GET_HOSTS_INVENTORY_RHSM },
{ ref: 'hostsGuests', type: rhsmTypes.GET_HOSTS_INVENTORY_GUESTS_RHSM },
{ ref: 'instancesInventory', type: rhsmTypes.GET_INSTANCES_INVENTORY_RHSM },
{ ref: 'subscriptionsInventory', type: rhsmTypes.GET_SUBSCRIPTIONS_INVENTORY_RHSM }
],
state,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InstancesListSelectors should pass existing query data through response: existing query data 1`] = `
Object {
"query": Object {
"a": "b",
"c": "d",
},
}
`;

exports[`InstancesListSelectors should pass existing state data through response: existing state data 1`] = `
Object {
"data": Array [],
"meta": "meta field",
"query": Object {},
"testing": "lorem ipsum",
}
`;

exports[`InstancesListSelectors should pass minimal data on missing a reducer response: missing reducer error 1`] = `
Object {
"query": Object {},
}
`;

exports[`InstancesListSelectors should return specific selectors: selectors 1`] = `
Object {
"instancesList": [Function],
"makeInstancesList": [Function],
}
`;
Loading

0 comments on commit f58b073

Please sign in to comment.