Skip to content

Commit

Permalink
fix(inventoryListSelectors): issues/10 selectors, state (#343)
Browse files Browse the repository at this point in the history
* inventoryReducer, hostsGuests rename, test snapshot
* inventoryListSelectors, initial selector, memoize/cache
* guestListSelectors, initial selector,  memoize/cache
* reduxHelpers, annotation
* rhsmActions, hostsGuests test
* rhsmServices, mock data, delay, annotations
  • Loading branch information
cdcabrera committed Jul 20, 2020
1 parent 09ad83d commit e72bb01
Show file tree
Hide file tree
Showing 12 changed files with 1,083 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/redux/actions/__tests__/rhsmActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('RhsmActions', () => {

dispatcher(store.dispatch).then(() => {
const response = store.getState().inventory;
expect(response.hostsInventoryGuests.fulfilled).toBe(true);
expect(response.hostsGuests.fulfilled).toBe(true);
done();
});
});
Expand Down
1 change: 1 addition & 0 deletions src/redux/common/reduxHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const generatedPromiseActionReducer = (types = [], state = {}, action = {}) => {
...expandMetaTypes(action.meta)
};

// Automatically apply data and state to a contextual ID if meta.id exists.
const setId = data =>
(action.meta && action.meta.id && { [action.meta.id]: { ...baseState, ...data } }) || { ...baseState, ...data };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
exports[`InventoryReducer should handle all defined error types: rejected types GET_HOSTS_INVENTORY_GUESTS_RHSM 1`] = `
Object {
"result": Object {
"hostsInventory": Object {},
"hostsInventoryGuests": Object {
"hostsGuests": Object {
"error": true,
"errorMessage": "MESSAGE",
"fulfilled": false,
Expand All @@ -15,6 +14,7 @@ Object {
"pending": false,
"status": 0,
},
"hostsInventory": Object {},
},
"type": "GET_HOSTS_INVENTORY_GUESTS_RHSM_REJECTED",
}
Expand All @@ -23,6 +23,7 @@ Object {
exports[`InventoryReducer should handle all defined error types: rejected types GET_HOSTS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {
"error": true,
"errorMessage": "MESSAGE",
Expand All @@ -34,7 +35,6 @@ Object {
"pending": false,
"status": 0,
},
"hostsInventoryGuests": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_REJECTED",
}
Expand All @@ -43,8 +43,7 @@ Object {
exports[`InventoryReducer should handle all defined fulfilled types: fulfilled types GET_HOSTS_INVENTORY_GUESTS_RHSM 1`] = `
Object {
"result": Object {
"hostsInventory": Object {},
"hostsInventoryGuests": Object {
"hostsGuests": Object {
"data": Object {
"test": "success",
},
Expand All @@ -59,6 +58,7 @@ Object {
"pending": false,
"status": 0,
},
"hostsInventory": Object {},
},
"type": "GET_HOSTS_INVENTORY_GUESTS_RHSM_FULFILLED",
}
Expand All @@ -67,6 +67,7 @@ Object {
exports[`InventoryReducer should handle all defined fulfilled types: fulfilled types GET_HOSTS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {
"data": Object {
"test": "success",
Expand All @@ -82,7 +83,6 @@ Object {
"pending": false,
"status": 0,
},
"hostsInventoryGuests": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_FULFILLED",
}
Expand All @@ -91,8 +91,7 @@ Object {
exports[`InventoryReducer should handle all defined pending types: pending types GET_HOSTS_INVENTORY_GUESTS_RHSM 1`] = `
Object {
"result": Object {
"hostsInventory": Object {},
"hostsInventoryGuests": Object {
"hostsGuests": Object {
"error": false,
"errorMessage": "",
"fulfilled": false,
Expand All @@ -102,6 +101,7 @@ Object {
"metaQuery": undefined,
"pending": true,
},
"hostsInventory": Object {},
},
"type": "GET_HOSTS_INVENTORY_GUESTS_RHSM_PENDING",
}
Expand All @@ -110,6 +110,7 @@ Object {
exports[`InventoryReducer should handle all defined pending types: pending types GET_HOSTS_INVENTORY_RHSM 1`] = `
Object {
"result": Object {
"hostsGuests": Object {},
"hostsInventory": Object {
"error": false,
"errorMessage": "",
Expand All @@ -120,7 +121,6 @@ Object {
"metaQuery": undefined,
"pending": true,
},
"hostsInventoryGuests": Object {},
},
"type": "GET_HOSTS_INVENTORY_RHSM_PENDING",
}
Expand Down
4 changes: 2 additions & 2 deletions src/redux/reducers/inventoryReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { reduxHelpers } from '../common/reduxHelpers';
*/
const initialState = {
hostsInventory: {},
hostsInventoryGuests: {}
hostsGuests: {}
};

/**
Expand All @@ -23,7 +23,7 @@ const inventoryReducer = (state = initialState, action) =>
reduxHelpers.generatedPromiseActionReducer(
[
{ ref: 'hostsInventory', type: rhsmTypes.GET_HOSTS_INVENTORY_RHSM },
{ ref: 'hostsInventoryGuests', type: rhsmTypes.GET_HOSTS_INVENTORY_GUESTS_RHSM }
{ ref: 'hostsGuests', type: rhsmTypes.GET_HOSTS_INVENTORY_GUESTS_RHSM }
],
state,
action
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`GuestsListSelectors should handle pending state on a product ID: pending 1`] = `
Object {
"error": false,
"fulfilled": false,
"listData": Array [],
"pending": true,
"status": undefined,
}
`;

exports[`GuestsListSelectors should map a fulfilled product ID response to an aggregated output: fulfilled 1`] = `
Object {
"error": false,
"fulfilled": true,
"listData": Array [
Object {
"displayName": "db.lorem.com",
"insightsId": "d6214a0b-b344-4778-831c-d53dcacb2da3",
"lastSeen": "17 days ago",
"subscriptionManagerId": "adafd9d5-5b00-42fa-a6c9-75801d45cc6d",
},
Object {
"displayName": "db.ipsum.com",
"insightsId": "9358e312-1c9f-42f4-8910-dcef6e970852",
"lastSeen": "in a month",
"subscriptionManagerId": "b101a72f-1859-4489-acb8-d6d31c2578c4",
},
],
"pending": false,
"status": undefined,
}
`;

exports[`GuestsListSelectors should pass minimal data on a product ID without a product ID provided: no product id error 1`] = `
Object {
"error": false,
"fulfilled": false,
"listData": Array [],
"pending": false,
"status": undefined,
}
`;

exports[`GuestsListSelectors should pass minimal data on missing a reducer response: missing reducer error 1`] = `
Object {
"error": false,
"fulfilled": false,
"listData": Array [],
"pending": false,
"status": undefined,
}
`;

exports[`GuestsListSelectors should populate data from the in memory cache: cached data: ERROR, query mismatch 1`] = `
Object {
"error": false,
"fulfilled": true,
"listData": Array [
Object {
"displayName": "db.ipsum.com",
"insightsId": "9358e312-1c9f-42f4-8910-dcef6e970852",
"lastSeen": "in a month",
"subscriptionManagerId": "b101a72f-1859-4489-acb8-d6d31c2578c4",
},
],
"pending": false,
"status": undefined,
}
`;

exports[`GuestsListSelectors should populate data from the in memory cache: cached data: cache used and pending 1`] = `
Object {
"error": false,
"fulfilled": true,
"listData": Array [
Object {
"displayName": "db.lorem.com",
"insightsId": "d6214a0b-b344-4778-831c-d53dcacb2da3",
"lastSeen": "17 days ago",
"subscriptionManagerId": "adafd9d5-5b00-42fa-a6c9-75801d45cc6d",
},
],
"pending": false,
"status": undefined,
}
`;

exports[`GuestsListSelectors should populate data from the in memory cache: cached data: initial fulfilled 1`] = `
Object {
"error": false,
"fulfilled": true,
"listData": Array [
Object {
"displayName": "db.lorem.com",
"insightsId": "d6214a0b-b344-4778-831c-d53dcacb2da3",
"lastSeen": "17 days ago",
"subscriptionManagerId": "adafd9d5-5b00-42fa-a6c9-75801d45cc6d",
},
],
"pending": false,
"status": undefined,
}
`;

exports[`GuestsListSelectors should populate data from the in memory cache: cached data: updated and fulfilled 1`] = `
Object {
"error": false,
"fulfilled": true,
"listData": Array [
Object {
"displayName": "db.ipsum.com",
"insightsId": "9358e312-1c9f-42f4-8910-dcef6e970852",
"lastSeen": "in a month",
"subscriptionManagerId": "b101a72f-1859-4489-acb8-d6d31c2578c4",
},
],
"pending": false,
"status": undefined,
}
`;

exports[`GuestsListSelectors should populate data on a product ID when the api response is missing expected properties: data populated, missing properties 1`] = `
Object {
"error": false,
"fulfilled": true,
"listData": Array [
Object {
"displayName": null,
"insightsId": "d6214a0b-b344-4778-831c-d53dcacb2da3",
"lastSeen": "in a year",
"subscriptionManagerId": "adafd9d5-5b00-42fa-a6c9-75801d45cc6d",
},
Object {
"displayName": "db.example.com",
"insightsId": "9358e312-1c9f-42f4-8910-dcef6e970852",
"lastSeen": "in a month",
"subscriptionManagerId": null,
},
],
"pending": false,
"status": undefined,
}
`;

exports[`GuestsListSelectors should return specific selectors: selectors 1`] = `
Object {
"guestsList": [Function],
"makeGuestsList": [Function],
}
`;
Loading

0 comments on commit e72bb01

Please sign in to comment.