Adding actions for fetching user moderation queue.

This commit is contained in:
David Jay
2017-01-03 15:05:45 -05:00
parent 800382132d
commit dd7bdb8a26
4 changed files with 97 additions and 5 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
import coralApi from '../../../coral-framework/helpers/response';
import * as commentTypes from '../constants/comments';
import * as actionTypes from '../constants/actions';
import * as userTypes from '../constants/users';
// Get comments to fill each of the three lists on the mod queue
export const fetchModerationQueueComments = () => {
@@ -24,7 +25,7 @@ export const fetchModerationQueueComments = () => {
.then(({comments, users, actions}) => {
/* Post comments and users to redux store. Actions will be posted when they are needed. */
dispatch({type: commentTypes.USERS_MODERATION_QUEUE_FETCH_SUCCESS, users});
dispatch({type: userTypes.USERS_MODERATION_QUEUE_FETCH_SUCCESS, users});
dispatch({type: commentTypes.COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS, comments});
dispatch({type: actionTypes.ACTIONS_MODERATION_QUEUE_FETCH_SUCCESS, actions});
+20 -4
View File
@@ -1,5 +1,6 @@
import coralApi from '../../../coral-framework/helpers/response';
import * as actions from '../constants/user';
import * as userTypes from '../constants/user';
import * as actionTypes from '../constants/actions';
/**
* Action disptacher related to users
@@ -7,9 +8,24 @@ import * as actions from '../constants/user';
// change status of a user
export const userStatusUpdate = (status, userId, commentId) => {
return dispatch => {
dispatch({type: actions.UPDATE_STATUS_REQUEST});
dispatch({type: userTypes.UPDATE_STATUS_REQUEST});
return coralApi(`/users/${userId}/status`, {method: 'POST', body: {status: status, comment_id: commentId}})
.then(res => dispatch({type: actions.UPDATE_STATUS_SUCCESS, res}))
.catch(error => dispatch({type: actions.UPDATE_STATUS_FAILURE, error}));
.then(res => dispatch({type: userTypes.UPDATE_STATUS_SUCCESS, res}))
.catch(error => dispatch({type: userTypes.UPDATE_STATUS_FAILURE, error}));
};
};
// Get users to add to the mod queue
export const fetchModerationQueueUsers = () => {
return dispatch => {
dispatch({type: userTypes.USERS_MODERATION_QUEUE_FETCH_REQUEST});
return coralApi('/queue/comments/pending')
.then(({users, actions}) => {
/* Post users and actions to redux store. Actions will be posted when they are needed. */
dispatch({type: userTypes.USERS_MODERATION_QUEUE_FETCH_SUCCESS, users});
dispatch({type: actionTypes.ACTIONS_MODERATION_QUEUE_FETCH_SUCCESS, actions});
})
.catch(error => dispatch({type: userTypes.USERS_MODERATION_QUEUE_FETCH_FAILURE, error}));
};
};
+3
View File
@@ -1,3 +1,6 @@
export const UPDATE_STATUS_REQUEST = 'UPDATE_STATUS_REQUEST';
export const UPDATE_STATUS_SUCCESS = 'UPDATE_STATUS_SUCCESS';
export const UPDATE_STATUS_FAILURE = 'UPDATE_STATUS_FAILURE';
export const USERS_MODERATION_QUEUE_FETCH_SUCCESS = 'USERS_MODERATION_QUEUE_FETCH_SUCCESS';
export const USERS_MODERATION_QUEUE_FETCH_FAILURE = 'USERS_MODERATION_QUEUE_FETCH_FAILURE';
export const USERS_MODERATION_QUEUE_FETCH_REQUEST = 'USERS_MODERATION_QUEUE_FETCH_REQUEST';
+72
View File
@@ -0,0 +1,72 @@
import 'react';
import 'redux';
import {expect} from 'chai';
import fetchMock from 'fetch-mock';
import * as userActions from '../../../../client/coral-admin/src/actions/users';
import {Map} from 'immutable';
import configureStore from 'redux-mock-store';
const mockStore = configureStore();
describe('User actions', () => {
let store;
const users = [
{
id: '123',
status: 'suspended'
},
{
id: '456',
status: 'active'
}
];
const actions = [
{
itemType: 'user',
itemId: '123'
}
];
beforeEach(() => {
store = mockStore(new Map({}));
fetchMock.restore();
});
describe('fetchModerationQueueUsers', () => {
it('should fetch users and actions pending moderation', () => {
fetchMock.get('*', JSON.stringify({
users,
actions
}));
return userActions.fetchModerationQueueUsers()(store.dispatch)
.then(() => {
console.log(store.getActions());
expect(store.getActions()[0]).to.have.property('type', 'USERS_MODERATION_QUEUE_FETCH_REQUEST');
expect(store.getActions()[1]).to.have.property('type', 'USERS_MODERATION_QUEUE_FETCH_SUCCESS');
expect(store.getActions()[1]).to.have.property('users').
and.to.deep.equal(users);
expect(store.getActions()[2]).to.have.property('type', 'ACTIONS_MODERATION_QUEUE_FETCH_SUCCESS');
expect(store.getActions()[2]).to.have.property('actions').
and.to.deep.equal(actions);
});
});
it('should return an error appropriatly', () => {
fetchMock.get('*', 404);
return userActions.fetchModerationQueueUsers()(store.dispatch)
.then(() => {
expect(store.getActions()[0]).to.have.property('type', 'USERS_MODERATION_QUEUE_FETCH_REQUEST');
expect(store.getActions()[1]).to.have.property('type', 'USERS_MODERATION_QUEUE_FETCH_FAILURE');
});
});
});
});