Skip to content

Commit

Permalink
feat(platformServices): issues/240 getUserPermissions (#249)
Browse files Browse the repository at this point in the history
* build, expand platform testing mock
* reduxHelpers, add getDataFromResults function alias
* userReducer, add admin, entitled, and permissions
* platformServices, expose getUserPermissions
* userServices, expose getUserPermissions through authorizeUser
* platformApiTypes, apply API types
  • Loading branch information
cdcabrera committed Apr 8, 2020
1 parent d74efc8 commit e4f8bb2
Show file tree
Hide file tree
Showing 18 changed files with 673 additions and 316 deletions.
20 changes: 20 additions & 0 deletions src/redux/common/__tests__/__snapshots__/reduxHelpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,33 @@ exports[`ReduxHelpers should get a message from a service call response: respons

exports[`ReduxHelpers should get a message from a service call response: response for 4XX 1`] = `"Request failed with status code 400"`;

exports[`ReduxHelpers should get data from a service call response: ARRAY data 1`] = `
Array [
Object {
"dolor": "sit",
"lorem": "ipsum",
},
Object {
"hello": "world",
},
]
`;

exports[`ReduxHelpers should get data from a service call response: data 1`] = `
Object {
"dolor": "sit",
"lorem": "ipsum",
}
`;

exports[`ReduxHelpers should have specific functions: reduxHelpers 1`] = `
Object {
"FULFILLED_ACTION": [Function],
"HTTP_STATUS_RANGE": [Function],
"PENDING_ACTION": [Function],
"REJECTED_ACTION": [Function],
"generatedPromiseActionReducer": [Function],
"getDataFromResults": [Function],
"getDateFromResults": [Function],
"getMessageFromResults": [Function],
"getSingleResponseFromResultArray": [Function],
Expand Down
36 changes: 36 additions & 0 deletions src/redux/common/__tests__/reduxHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,42 @@ describe('ReduxHelpers', () => {
).toMatchSnapshot('ARRAY date');
});

it('should get data from a service call response', () => {
expect(
reduxHelpers.getDataFromResults({
payload: {
headers: {
date: 'Tue, 11 Feb 2020 15:27:16 GMT'
},
status: 200,
statusText: 'OK',
data: { lorem: 'ipsum', dolor: 'sit' }
}
})
).toMatchSnapshot('data');

expect(
reduxHelpers.getDataFromResults([
{
headers: {
date: 'Tue, 11 Feb 2020 15:27:16 GMT'
},
status: 200,
statusText: 'OK',
data: { lorem: 'ipsum', dolor: 'sit' }
},
{
headers: {
date: 'Tue, 11 Feb 2020 15:27:18 GMT'
},
status: 200,
statusText: 'OK',
data: { hello: 'world' }
}
])
).toMatchSnapshot('ARRAY data');
});

it('should update a state object', () => {
const initialState = {
lorem: false,
Expand Down
9 changes: 9 additions & 0 deletions src/redux/common/reduxHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ const singlePromiseDataResponseFromArray = results => {
return updatedResults.data || {};
};

/**
* Alias for singlePromiseDataResponseFromArray.
*
* @param {Array|object} results
* @returns {Array|object}
*/
const getDataFromResults = results => singlePromiseDataResponseFromArray(results);

/**
* Automatically apply reducer logic to state by handling promise responses from redux-promise-middleware.
*
Expand Down Expand Up @@ -318,6 +326,7 @@ const reduxHelpers = {
HTTP_STATUS_RANGE,
setResponseSchemas,
generatedPromiseActionReducer,
getDataFromResults,
getDateFromResults,
getMessageFromResults,
getSingleResponseFromResultArray,
Expand Down
Loading

0 comments on commit e4f8bb2

Please sign in to comment.