Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rhsmServices,redux): issues/10 inventory guests api, state #330

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ REACT_APP_SERVICES_RHSM_VERSION=/api/rhsm-subscriptions/v1/version
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_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 @@ -11,4 +11,5 @@ REACT_APP_SERVICES_RHSM_VERSION=http://localhost:5000/api/rhsm-subscriptions/v1/
REACT_APP_SERVICES_RHSM_REPORT=http://localhost:5000/api/rhsm-subscriptions/v1/tally/products/
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_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 @@ -15,4 +15,5 @@ REACT_APP_SERVICES_RHSM_VERSION=/api/rhsm-subscriptions/v1/version
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_OPTIN=/api/rhsm-subscriptions/v1/opt-in
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,6 @@ exports[`Authentication Component should render a non-connected component error:
<div
className="pf-c-empty-state__content"
>
<Title
headingLevel="h2"
size="lg"
>
<h2
className="pf-c-title pf-m-lg"
>
t(curiosity-auth.authorizedTitle, [object Object])
</h2>
</Title>
<EmptyStateIcon
icon={[Function]}
>
Expand Down Expand Up @@ -154,6 +144,16 @@ exports[`Authentication Component should render a non-connected component error:
</svg>
</LockIcon>
</EmptyStateIcon>
<Title
headingLevel="h2"
size="lg"
>
<h2
className="pf-c-title pf-m-lg"
>
t(curiosity-auth.authorizedTitle, [object Object])
</h2>
</Title>
<EmptyStateBody>
<div
className="pf-c-empty-state__body"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ exports[`MessageView Component should render a non-connected component: non-conn
className="fadein"
variant="full"
>
<EmptyStateIcon
icon={[Function]}
/>
<Title
headingLevel="h2"
size="lg"
>
lorem
</Title>
<EmptyStateIcon
icon={[Function]}
/>
<EmptyStateBody>
ipsum
</EmptyStateBody>
Expand Down
2 changes: 1 addition & 1 deletion src/components/messageView/messageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ const MessageView = ({ icon, message, pageTitle, title }) => (
<PageLayout>
<PageHeader>{pageTitle || helpers.UI_DISPLAY_NAME}</PageHeader>
<PfEmptyState variant={EmptyStateVariant.full} className="fadein">
{icon && <EmptyStateIcon icon={icon} />}
{title && (
<Title headingLevel="h2" size="lg">
{title}
</Title>
)}
{icon && <EmptyStateIcon icon={icon} />}
{message && <EmptyStateBody>{message}</EmptyStateBody>}
</PfEmptyState>
</PageLayout>
Expand Down
11 changes: 11 additions & 0 deletions src/redux/actions/__tests__/rhsmActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,15 @@ describe('RhsmActions', () => {
done();
});
});

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

dispatcher(store.dispatch).then(() => {
const response = store.getState().inventory;
expect(response.hostsInventoryGuests.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 @@ -19,6 +19,13 @@ const getGraphReportsCapacity = (id = null, query = {}) => dispatch =>
}
});

/**
* Get a hosts response listing from RHSM subscriptions.
*
* @param {string} id
* @param {object} query
* @returns {Function}
*/
const getHostsInventory = (id = null, query = {}) => dispatch =>
dispatch({
type: rhsmTypes.GET_HOSTS_INVENTORY_RHSM,
Expand All @@ -30,6 +37,24 @@ const getHostsInventory = (id = null, query = {}) => dispatch =>
}
});

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

const rhsmActions = { getGraphReportsCapacity, getHostsInventory, getHostsInventoryGuests };

export { rhsmActions as default, rhsmActions, getGraphReportsCapacity, getHostsInventory };
export { rhsmActions as default, rhsmActions, getGraphReportsCapacity, getHostsInventory, getHostsInventoryGuests };
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InventoryReducer should handle all defined error types: rejected types GET_HOSTS_INVENTORY_GUESTS_RHSM 1`] = `
Object {
"result": Object {
"hostsInventory": Object {},
"hostsInventoryGuests": Object {
"error": true,
"errorMessage": "MESSAGE",
"fulfilled": false,
"meta": Object {},
"metaData": undefined,
"metaId": undefined,
"metaQuery": undefined,
"pending": false,
"status": 0,
},
},
"type": "GET_HOSTS_INVENTORY_GUESTS_RHSM_REJECTED",
}
`;

exports[`InventoryReducer should handle all defined error types: rejected types GET_HOSTS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
Expand All @@ -14,11 +34,36 @@ Object {
"pending": false,
"status": 0,
},
"hostsInventoryGuests": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_REJECTED",
}
`;

exports[`InventoryReducer should handle all defined fulfilled types: fulfilled types GET_HOSTS_INVENTORY_GUESTS_RHSM 1`] = `
Object {
"result": Object {
"hostsInventory": Object {},
"hostsInventoryGuests": 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_HOSTS_INVENTORY_GUESTS_RHSM_FULFILLED",
}
`;

exports[`InventoryReducer should handle all defined fulfilled types: fulfilled types GET_HOSTS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
Expand All @@ -37,11 +82,31 @@ Object {
"pending": false,
"status": 0,
},
"hostsInventoryGuests": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_FULFILLED",
}
`;

exports[`InventoryReducer should handle all defined pending types: pending types GET_HOSTS_INVENTORY_GUESTS_RHSM 1`] = `
Object {
"result": Object {
"hostsInventory": Object {},
"hostsInventoryGuests": Object {
"error": false,
"errorMessage": "",
"fulfilled": false,
"meta": Object {},
"metaData": undefined,
"metaId": undefined,
"metaQuery": undefined,
"pending": true,
},
},
"type": "GET_HOSTS_INVENTORY_GUESTS_RHSM_PENDING",
}
`;

exports[`InventoryReducer should handle all defined pending types: pending types GET_HOSTS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
Expand All @@ -55,6 +120,7 @@ Object {
"metaQuery": undefined,
"pending": true,
},
"hostsInventoryGuests": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_PENDING",
}
Expand Down
6 changes: 3 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,7 @@ describe('InventoryReducer', () => {
});

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

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

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

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

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

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

/**
* Apply generated inventory observer/reducer for systemInventory to state, against actions.
* Apply generated inventory observer/reducer for hosts/system inventory to state, against actions.
*
* @param {object} state
* @param {object} action
* @returns {object|{}}
*/
const inventoryReducer = (state = initialState, action) =>
reduxHelpers.generatedPromiseActionReducer(
[{ ref: 'hostsInventory', type: rhsmTypes.GET_HOSTS_INVENTORY_RHSM }],
[
{ ref: 'hostsInventory', type: rhsmTypes.GET_HOSTS_INVENTORY_RHSM },
{ ref: 'hostsInventoryGuests', type: rhsmTypes.GET_HOSTS_INVENTORY_GUESTS_RHSM }
],
state,
action
);
Expand Down
4 changes: 4 additions & 0 deletions src/redux/types/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Object {
"GET_GRAPH_CAPACITY_RHSM": "GET_GRAPH_CAPACITY_RHSM",
"GET_GRAPH_REPORT_CAPACITY_RHSM": "GET_GRAPH_REPORT_CAPACITY_RHSM",
"GET_GRAPH_REPORT_RHSM": "GET_GRAPH_REPORT_RHSM",
"GET_HOSTS_INVENTORY_GUESTS_RHSM": "GET_HOSTS_INVENTORY_GUESTS_RHSM",
"GET_HOSTS_INVENTORY_RHSM": "GET_HOSTS_INVENTORY_RHSM",
"SET_GRAPH_GRANULARITY_RHSM": "SET_GRAPH_GRANULARITY_RHSM",
"SET_GRAPH_SLA_RHSM": "SET_GRAPH_SLA_RHSM",
Expand Down Expand Up @@ -73,6 +74,7 @@ Object {
"GET_GRAPH_CAPACITY_RHSM": "GET_GRAPH_CAPACITY_RHSM",
"GET_GRAPH_REPORT_CAPACITY_RHSM": "GET_GRAPH_REPORT_CAPACITY_RHSM",
"GET_GRAPH_REPORT_RHSM": "GET_GRAPH_REPORT_RHSM",
"GET_HOSTS_INVENTORY_GUESTS_RHSM": "GET_HOSTS_INVENTORY_GUESTS_RHSM",
"GET_HOSTS_INVENTORY_RHSM": "GET_HOSTS_INVENTORY_RHSM",
"SET_GRAPH_GRANULARITY_RHSM": "SET_GRAPH_GRANULARITY_RHSM",
"SET_GRAPH_SLA_RHSM": "SET_GRAPH_SLA_RHSM",
Expand All @@ -90,6 +92,7 @@ Object {
"GET_GRAPH_CAPACITY_RHSM": "GET_GRAPH_CAPACITY_RHSM",
"GET_GRAPH_REPORT_CAPACITY_RHSM": "GET_GRAPH_REPORT_CAPACITY_RHSM",
"GET_GRAPH_REPORT_RHSM": "GET_GRAPH_REPORT_RHSM",
"GET_HOSTS_INVENTORY_GUESTS_RHSM": "GET_HOSTS_INVENTORY_GUESTS_RHSM",
"GET_HOSTS_INVENTORY_RHSM": "GET_HOSTS_INVENTORY_RHSM",
"SET_GRAPH_GRANULARITY_RHSM": "SET_GRAPH_GRANULARITY_RHSM",
"SET_GRAPH_SLA_RHSM": "SET_GRAPH_SLA_RHSM",
Expand Down Expand Up @@ -127,6 +130,7 @@ Object {
"GET_GRAPH_CAPACITY_RHSM": "GET_GRAPH_CAPACITY_RHSM",
"GET_GRAPH_REPORT_CAPACITY_RHSM": "GET_GRAPH_REPORT_CAPACITY_RHSM",
"GET_GRAPH_REPORT_RHSM": "GET_GRAPH_REPORT_RHSM",
"GET_HOSTS_INVENTORY_GUESTS_RHSM": "GET_HOSTS_INVENTORY_GUESTS_RHSM",
"GET_HOSTS_INVENTORY_RHSM": "GET_HOSTS_INVENTORY_RHSM",
"SET_GRAPH_GRANULARITY_RHSM": "SET_GRAPH_GRANULARITY_RHSM",
"SET_GRAPH_SLA_RHSM": "SET_GRAPH_SLA_RHSM",
Expand Down
7 changes: 5 additions & 2 deletions src/redux/types/rhsmTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ const GET_GRAPH_CAPACITY_RHSM = 'GET_GRAPH_CAPACITY_RHSM';
const GET_GRAPH_REPORT_RHSM = 'GET_GRAPH_REPORT_RHSM';
const GET_GRAPH_REPORT_CAPACITY_RHSM = 'GET_GRAPH_REPORT_CAPACITY_RHSM';
const GET_HOSTS_INVENTORY_RHSM = 'GET_HOSTS_INVENTORY_RHSM';
const GET_HOSTS_INVENTORY_GUESTS_RHSM = 'GET_HOSTS_INVENTORY_GUESTS_RHSM';
const SET_GRAPH_GRANULARITY_RHSM = 'SET_GRAPH_GRANULARITY_RHSM';
const SET_GRAPH_SLA_RHSM = 'SET_GRAPH_SLA_RHSM';

/**
* RHSM API action, reducer types.
*
* @type {{GET_GRAPH_REPORT_CAPACITY_RHSM: string, SET_GRAPH_GRANULARITY_RHSM: string,
* GET_GRAPH_CAPACITY_RHSM: string, SET_GRAPH_SLA_RHSM: string, GET_HOSTS_INVENTORY_RHSM: string,
* GET_GRAPH_REPORT_RHSM: string}}
* GET_HOSTS_INVENTORY_GUESTS_RHSM: string, GET_GRAPH_CAPACITY_RHSM: string, SET_GRAPH_SLA_RHSM: string,
* GET_HOSTS_INVENTORY_RHSM: string, GET_GRAPH_REPORT_RHSM: string}}
*/
const rhsmTypes = {
GET_GRAPH_CAPACITY_RHSM,
GET_GRAPH_REPORT_RHSM,
GET_GRAPH_REPORT_CAPACITY_RHSM,
GET_HOSTS_INVENTORY_RHSM,
GET_HOSTS_INVENTORY_GUESTS_RHSM,
SET_GRAPH_GRANULARITY_RHSM,
SET_GRAPH_SLA_RHSM
};
Expand All @@ -28,6 +30,7 @@ export {
GET_GRAPH_REPORT_RHSM,
GET_GRAPH_REPORT_CAPACITY_RHSM,
GET_HOSTS_INVENTORY_RHSM,
GET_HOSTS_INVENTORY_GUESTS_RHSM,
SET_GRAPH_GRANULARITY_RHSM,
SET_GRAPH_SLA_RHSM
};
3 changes: 2 additions & 1 deletion src/services/__tests__/rhsmServices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ describe('RhsmServices', () => {
});

it('should export a specific number of methods and classes', () => {
expect(Object.keys(rhsmServices)).toHaveLength(4);
expect(Object.keys(rhsmServices)).toHaveLength(5);
});

it('should have specific methods', () => {
expect(rhsmServices.getApiVersion).toBeDefined();
expect(rhsmServices.getGraphCapacity).toBeDefined();
expect(rhsmServices.getGraphReports).toBeDefined();
expect(rhsmServices.getHostsInventory).toBeDefined();
expect(rhsmServices.getHostsInventoryGuests).toBeDefined();
});

/**
Expand Down
Loading