Skip to content

Commit

Permalink
feat(rhsmServices,redux): issues/491 initial api, state setup (#517)
Browse files Browse the repository at this point in the history
* build, dotenv, subscriptions inventory endpoint, platform test
* inventoryListSel, minor test update
* redux, rhsmActions,reducer,type, subscriptions inventory state
* rhsmApiTypes, expand for subscriptions, sort types
* rhsmServices, getSubscriptionsInventory api method
* subscriptionsListSel, base selector from inventoryListSel
  • Loading branch information
cdcabrera committed Feb 16, 2021
1 parent 289fba9 commit ffecb3f
Show file tree
Hide file tree
Showing 21 changed files with 1,110 additions and 53 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ REACT_APP_SERVICES_RHSM_REPORT=/api/rhsm-subscriptions/v1/tally/products/
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_SUBSCRIPTIONS=/api/rhsm-subscriptions/v1/subscriptions/products/
REACT_APP_SERVICES_RHSM_OPTIN=/api/rhsm-subscriptions/v1/opt-in
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ REACT_APP_SERVICES_RHSM_REPORT=http://localhost:5000/api/rhsm-subscriptions/v1/t
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_SUBSCRIPTIONS=//localhost:5000/api/rhsm-subscriptions/v1/subscriptions/products/
REACT_APP_SERVICES_RHSM_OPTIN=http://localhost:5000/api/rhsm-subscriptions/v1/opt-in
1 change: 1 addition & 0 deletions .env.proxy
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ REACT_APP_SERVICES_RHSM_REPORT=/api/rhsm-subscriptions/v1/tally/products/
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_SUBSCRIPTIONS=/api/rhsm-subscriptions/v1/subscriptions/products/
REACT_APP_SERVICES_RHSM_OPTIN=/api/rhsm-subscriptions/v1/opt-in
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 @@ -21,7 +21,7 @@ describe('RhsmActions', () => {
beforeEach(() => {
moxios.install();

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

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

dispatcher(store.dispatch).then(() => {
const response = store.getState().inventory;
expect(response.subscriptionsInventory.fulfilled).toBe(true);
done();
});
});
});
29 changes: 27 additions & 2 deletions src/redux/actions/rhsmActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,38 @@ const getMessageReports = (id = null, query = {}) => dispatch =>
}
});

const rhsmActions = { getGraphReportsCapacity, getHostsInventory, getHostsInventoryGuests, getMessageReports };
/**
* Get a subscriptions response from RHSM subscriptions.
*
* @param {string} id
* @param {object} query
* @returns {Function}
*/
const getSubscriptionsInventory = (id = null, query = {}) => dispatch =>
dispatch({
type: rhsmTypes.GET_SUBSCRIPTIONS_INVENTORY_RHSM,
payload: rhsmServices.getSubscriptionsInventory(id, query),
meta: {
id,
query,
notifications: {}
}
});

const rhsmActions = {
getGraphReportsCapacity,
getHostsInventory,
getHostsInventoryGuests,
getMessageReports,
getSubscriptionsInventory
};

export {
rhsmActions as default,
rhsmActions,
getGraphReportsCapacity,
getHostsInventory,
getHostsInventoryGuests,
getMessageReports
getMessageReports,
getSubscriptionsInventory
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Object {
"status": 0,
},
"hostsInventory": Object {},
"subscriptionsInventory": Object {},
},
"type": "GET_HOSTS_INVENTORY_GUESTS_RHSM_REJECTED",
}
Expand All @@ -35,11 +36,33 @@ Object {
"pending": false,
"status": 0,
},
"subscriptionsInventory": Object {},
},
"type": "GET_HOSTS_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 {},
"subscriptionsInventory": Object {
"error": true,
"errorMessage": "MESSAGE",
"fulfilled": false,
"meta": Object {},
"metaData": undefined,
"metaId": undefined,
"metaQuery": undefined,
"pending": false,
"status": 0,
},
},
"type": "GET_SUBSCRIPTIONS_INVENTORY_RHSM_REJECTED",
}
`;

exports[`InventoryReducer should handle all defined fulfilled types: fulfilled types GET_HOSTS_INVENTORY_GUESTS_RHSM 1`] = `
Object {
"result": Object {
Expand All @@ -59,6 +82,7 @@ Object {
"status": 0,
},
"hostsInventory": Object {},
"subscriptionsInventory": Object {},
},
"type": "GET_HOSTS_INVENTORY_GUESTS_RHSM_FULFILLED",
}
Expand All @@ -83,11 +107,37 @@ Object {
"pending": false,
"status": 0,
},
"subscriptionsInventory": Object {},
},
"type": "GET_HOSTS_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 {},
"subscriptionsInventory": Object {
"data": Object {
"test": "success",
},
"date": null,
"error": false,
"errorMessage": "",
"fulfilled": true,
"meta": Object {},
"metaData": undefined,
"metaId": undefined,
"metaQuery": undefined,
"pending": false,
"status": 0,
},
},
"type": "GET_SUBSCRIPTIONS_INVENTORY_RHSM_FULFILLED",
}
`;

exports[`InventoryReducer should handle all defined pending types: pending types GET_HOSTS_INVENTORY_GUESTS_RHSM 1`] = `
Object {
"result": Object {
Expand All @@ -102,6 +152,7 @@ Object {
"pending": true,
},
"hostsInventory": Object {},
"subscriptionsInventory": Object {},
},
"type": "GET_HOSTS_INVENTORY_GUESTS_RHSM_PENDING",
}
Expand All @@ -121,7 +172,28 @@ Object {
"metaQuery": undefined,
"pending": true,
},
"subscriptionsInventory": Object {},
},
"type": "GET_HOSTS_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 {},
"subscriptionsInventory": Object {
"error": false,
"errorMessage": "",
"fulfilled": false,
"meta": Object {},
"metaData": undefined,
"metaId": undefined,
"metaQuery": undefined,
"pending": true,
},
},
"type": "GET_SUBSCRIPTIONS_INVENTORY_RHSM_PENDING",
}
`;
18 changes: 15 additions & 3 deletions src/redux/reducers/__tests__/inventoryReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ describe('InventoryReducer', () => {
});

it('should handle all defined error types', () => {
const specificTypes = [types.GET_HOSTS_INVENTORY_RHSM, types.GET_HOSTS_INVENTORY_GUESTS_RHSM];
const specificTypes = [
types.GET_HOSTS_INVENTORY_RHSM,
types.GET_HOSTS_INVENTORY_GUESTS_RHSM,
types.GET_SUBSCRIPTIONS_INVENTORY_RHSM
];

specificTypes.forEach(value => {
const dispatched = {
Expand All @@ -35,7 +39,11 @@ describe('InventoryReducer', () => {
});

it('should handle all defined pending types', () => {
const specificTypes = [types.GET_HOSTS_INVENTORY_RHSM, types.GET_HOSTS_INVENTORY_GUESTS_RHSM];
const specificTypes = [
types.GET_HOSTS_INVENTORY_RHSM,
types.GET_HOSTS_INVENTORY_GUESTS_RHSM,
types.GET_SUBSCRIPTIONS_INVENTORY_RHSM
];

specificTypes.forEach(value => {
const dispatched = {
Expand All @@ -51,7 +59,11 @@ describe('InventoryReducer', () => {
});

it('should handle all defined fulfilled types', () => {
const specificTypes = [types.GET_HOSTS_INVENTORY_RHSM, types.GET_HOSTS_INVENTORY_GUESTS_RHSM];
const specificTypes = [
types.GET_HOSTS_INVENTORY_RHSM,
types.GET_HOSTS_INVENTORY_GUESTS_RHSM,
types.GET_SUBSCRIPTIONS_INVENTORY_RHSM
];

specificTypes.forEach(value => {
const dispatched = {
Expand Down
11 changes: 7 additions & 4 deletions src/redux/reducers/inventoryReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { reduxHelpers } from '../common/reduxHelpers';
* Initial state.
*
* @private
* @type {{hostsInventoryGuests: {}, hostsInventory: {}}}
* @type {{subscriptionsInventory: {}, hostsInventory: {}, hostsGuests: {}}}
*/
const initialState = {
hostsInventory: {},
hostsGuests: {}
hostsGuests: {},
subscriptionsInventory: {}
};

/**
* Apply generated inventory observer/reducer for hosts/system inventory to state, against actions.
* Apply generated inventory observer/reducer for hosts/system and subscriptions inventory to state,
* against actions.
*
* @param {object} state
* @param {object} action
Expand All @@ -23,7 +25,8 @@ const inventoryReducer = (state = initialState, action) =>
reduxHelpers.generatedPromiseActionReducer(
[
{ ref: 'hostsInventory', type: rhsmTypes.GET_HOSTS_INVENTORY_RHSM },
{ ref: 'hostsGuests', type: rhsmTypes.GET_HOSTS_INVENTORY_GUESTS_RHSM }
{ ref: 'hostsGuests', type: rhsmTypes.GET_HOSTS_INVENTORY_GUESTS_RHSM },
{ ref: 'subscriptionsInventory', type: rhsmTypes.GET_SUBSCRIPTIONS_INVENTORY_RHSM }
],
state,
action
Expand Down
Loading

0 comments on commit ffecb3f

Please sign in to comment.