Skip to content

Commit

Permalink
feat(services,redux): issues/240 add account opt-in services (#243)
Browse files Browse the repository at this point in the history
* build, rhsm API opt-in endpoint
* redux, layout for actions, reducers, types
* rhsmServices, jsdoc annotation updates
* userServices, rhsm opt-in services, mock layouts for delete, put, get
  • Loading branch information
cdcabrera committed Apr 17, 2020
1 parent 7c8e571 commit 87fdb68
Show file tree
Hide file tree
Showing 14 changed files with 684 additions and 31 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ REACT_APP_INCLUDE_CONTENT_BODY=<esi:include src="${UI_DEPLOY_PATH_PREFIX}/apps/c
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_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 @@ -10,3 +10,4 @@ REACT_APP_CONFIG_SERVICE_LOCALES_PATH=./locales/{{lng}}.json
REACT_APP_SERVICES_RHSM_VERSION=http://localhost:5000/api/rhsm-subscriptions/v1/version
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_OPTIN=http://localhost:5000/api/rhsm-subscriptions/v1/opt-in
48 changes: 40 additions & 8 deletions src/redux/actions/__tests__/userActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ describe('UserActions', () => {
beforeEach(() => {
moxios.install();

moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 200,
response: {
test: 'success'
}
});
moxios.stubRequest(/\/(opt-in).*?/, {
status: 200,
responseText: 'success',
timeout: 1,
response: {
test: 'success'
}
});
});

Expand All @@ -44,4 +43,37 @@ describe('UserActions', () => {
done();
});
});

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

dispatcher(store.dispatch).then(() => {
const response = store.getState().user;
expect(response.optin.fulfilled).toBe(true);
done();
});
});

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

dispatcher(store.dispatch).then(() => {
const response = store.getState().user;
expect(response.optin.fulfilled).toBe(true);
done();
});
});

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

dispatcher(store.dispatch).then(() => {
const response = store.getState().user;
expect(response.optin.fulfilled).toBe(true);
done();
});
});
});
56 changes: 54 additions & 2 deletions src/redux/actions/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,58 @@ const getLocale = () => ({
payload: userServices.getLocale()
});

const userActions = { authorizeUser, getLocale };
/**
* Delete a user's opt-in.
*
* @returns {Function}
*/
const deleteAccountOptIn = () => dispatch =>
dispatch({
type: userTypes.DELETE_USER_OPTIN,
payload: userServices.deleteAccountOptIn(),
meta: {
notifications: {}
}
});

/**
* Get a user's opt-in config.
*
* @returns {Function}
*/
const getAccountOptIn = () => dispatch =>
dispatch({
type: userTypes.GET_USER_OPTIN,
payload: userServices.getAccountOptIn(),
meta: {
notifications: {}
}
});

/**
* Update a user's opt-in.
*
* @param {object} query
* @returns {Function}
*/
const updateAccountOptIn = (query = {}) => dispatch =>
dispatch({
type: userTypes.UPDATE_USER_OPTIN,
payload: userServices.updateAccountOptIn(query),
meta: {
query,
notifications: {}
}
});

const userActions = { authorizeUser, getLocale, deleteAccountOptIn, getAccountOptIn, updateAccountOptIn };

export { userActions as default, userActions, authorizeUser, getLocale };
export {
userActions as default,
userActions,
authorizeUser,
getLocale,
deleteAccountOptIn,
getAccountOptIn,
updateAccountOptIn
};
Loading

0 comments on commit 87fdb68

Please sign in to comment.