-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* build, dotenv host inventory API endpoint * redux actions, reducers, types for inventory * rhsmServices, add base host inventory API * rhsmApiTypes, inventory API response types
- Loading branch information
Showing
16 changed files
with
406 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/redux/reducers/__tests__/__snapshots__/inventoryReducer.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`InventoryReducer should handle all defined error types: rejected types GET_HOSTS_INVENTORY_RHSM 1`] = ` | ||
Object { | ||
"result": Object { | ||
"hostsInventory": Object { | ||
"error": true, | ||
"errorMessage": "MESSAGE", | ||
"fulfilled": false, | ||
"meta": Object {}, | ||
"metaData": undefined, | ||
"metaId": undefined, | ||
"metaQuery": undefined, | ||
"pending": false, | ||
"status": 0, | ||
}, | ||
}, | ||
"type": "GET_HOSTS_INVENTORY_RHSM_REJECTED", | ||
} | ||
`; | ||
|
||
exports[`InventoryReducer should handle all defined fulfilled types: fulfilled types GET_HOSTS_INVENTORY_RHSM 1`] = ` | ||
Object { | ||
"result": Object { | ||
"hostsInventory": 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_RHSM_FULFILLED", | ||
} | ||
`; | ||
|
||
exports[`InventoryReducer should handle all defined pending types: pending types GET_HOSTS_INVENTORY_RHSM 1`] = ` | ||
Object { | ||
"result": Object { | ||
"hostsInventory": Object { | ||
"error": false, | ||
"errorMessage": "", | ||
"fulfilled": false, | ||
"meta": Object {}, | ||
"metaData": undefined, | ||
"metaId": undefined, | ||
"metaQuery": undefined, | ||
"pending": true, | ||
}, | ||
}, | ||
"type": "GET_HOSTS_INVENTORY_RHSM_PENDING", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import inventoryReducer from '../inventoryReducer'; | ||
import { rhsmTypes as types } from '../../types'; | ||
import { reduxHelpers } from '../../common/reduxHelpers'; | ||
|
||
describe('InventoryReducer', () => { | ||
it('should return the initial state', () => { | ||
expect(inventoryReducer.initialState).toBeDefined(); | ||
}); | ||
|
||
it('should handle all defined error types', () => { | ||
const specificTypes = [types.GET_HOSTS_INVENTORY_RHSM]; | ||
|
||
specificTypes.forEach(value => { | ||
const dispatched = { | ||
type: reduxHelpers.REJECTED_ACTION(value), | ||
error: true, | ||
payload: { | ||
message: 'MESSAGE', | ||
response: { | ||
status: 0, | ||
statusText: 'ERROR TEST', | ||
data: { | ||
detail: 'ERROR' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const resultState = inventoryReducer(undefined, dispatched); | ||
|
||
expect({ type: reduxHelpers.REJECTED_ACTION(value), result: resultState }).toMatchSnapshot( | ||
`rejected types ${value}` | ||
); | ||
}); | ||
}); | ||
|
||
it('should handle all defined pending types', () => { | ||
const specificTypes = [types.GET_HOSTS_INVENTORY_RHSM]; | ||
|
||
specificTypes.forEach(value => { | ||
const dispatched = { | ||
type: reduxHelpers.PENDING_ACTION(value) | ||
}; | ||
|
||
const resultState = inventoryReducer(undefined, dispatched); | ||
|
||
expect({ type: reduxHelpers.PENDING_ACTION(value), result: resultState }).toMatchSnapshot( | ||
`pending types ${value}` | ||
); | ||
}); | ||
}); | ||
|
||
it('should handle all defined fulfilled types', () => { | ||
const specificTypes = [types.GET_HOSTS_INVENTORY_RHSM]; | ||
|
||
specificTypes.forEach(value => { | ||
const dispatched = { | ||
type: reduxHelpers.FULFILLED_ACTION(value), | ||
payload: { | ||
data: { | ||
test: 'success' | ||
} | ||
} | ||
}; | ||
|
||
const resultState = inventoryReducer(undefined, dispatched); | ||
|
||
expect({ type: reduxHelpers.FULFILLED_ACTION(value), result: resultState }).toMatchSnapshot( | ||
`fulfilled types ${value}` | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import { combineReducers } from 'redux'; | ||
import { notifications } from '@redhat-cloud-services/frontend-components-notifications'; | ||
import graphReducer from './graphReducer'; | ||
import inventoryReducer from './inventoryReducer'; | ||
import viewReducer from './viewReducer'; | ||
import userReducer from './userReducer'; | ||
|
||
const reducers = { | ||
notifications, | ||
graph: graphReducer, | ||
view: viewReducer, | ||
user: userReducer | ||
inventory: inventoryReducer, | ||
user: userReducer, | ||
view: viewReducer | ||
}; | ||
|
||
const reduxReducers = combineReducers(reducers); | ||
|
||
export { reduxReducers as default, reduxReducers, graphReducer, viewReducer, userReducer }; | ||
export { reduxReducers as default, reduxReducers, graphReducer, inventoryReducer, userReducer, viewReducer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { rhsmTypes } from '../types/rhsmTypes'; | ||
import { reduxHelpers } from '../common/reduxHelpers'; | ||
|
||
/** | ||
* Initial state. | ||
* | ||
* @private | ||
* @type {{inventory: {}}} | ||
*/ | ||
const initialState = { | ||
hostsInventory: {} | ||
}; | ||
|
||
/** | ||
* Apply generated inventory observer/reducer for systemInventory 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 }], | ||
state, | ||
action | ||
); | ||
|
||
inventoryReducer.initialState = initialState; | ||
|
||
export { inventoryReducer as default, initialState, inventoryReducer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.