mirror of
https://github.com/wassname/talk.git
synced 2026-07-29 11:28:24 +08:00
Switching to central call for mod queue to support current reducer structure.
This commit is contained in:
@@ -9,17 +9,18 @@ export const fetchModerationQueueComments = () => {
|
||||
dispatch({type: commentTypes.COMMENTS_MODERATION_QUEUE_FETCH_REQUEST});
|
||||
return Promise.all([
|
||||
coralApi('/queue/comments/pending'),
|
||||
coralApi('/queue/users/pending'),
|
||||
coralApi('/comments?status=rejected'),
|
||||
coralApi('/comments?action_type=flag')
|
||||
])
|
||||
.then(([pending, rejected, flagged]) => {
|
||||
.then(([pendingComments, pendingUsers, rejected, flagged]) => {
|
||||
|
||||
/* Combine seperate calls into a single object */
|
||||
flagged.comments.forEach(comment => comment.flagged = true);
|
||||
return {
|
||||
comments: [...pending.comments, ...rejected.comments, ...flagged.comments],
|
||||
users: [...pending.users, ...rejected.users, ...flagged.users],
|
||||
actions: [...pending.actions, ...rejected.actions, ...flagged.actions]
|
||||
comments: [...pendingComments.comments, ...rejected.comments, ...flagged.comments],
|
||||
users: [...pendingComments.users, ...pendingUsers.users, ...rejected.users, ...flagged.users],
|
||||
actions: [...pendingComments.actions, ...pendingUsers.actions, ...rejected.actions, ...flagged.actions]
|
||||
};
|
||||
})
|
||||
.then(({comments, users, actions}) => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import coralApi from '../../../coral-framework/helpers/response';
|
||||
import * as userTypes from '../constants/user';
|
||||
import * as actionTypes from '../constants/actions';
|
||||
import * as userTypes from '../constants/users';
|
||||
|
||||
/**
|
||||
* Action disptacher related to users
|
||||
@@ -14,18 +13,3 @@ export const userStatusUpdate = (status, userId, commentId) => {
|
||||
.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}));
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
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';
|
||||
@@ -0,0 +1,3 @@
|
||||
export const UPDATE_STATUS_REQUEST = 'UPDATE_STATUS_REQUEST';
|
||||
export const UPDATE_STATUS_SUCCESS = 'UPDATE_STATUS_SUCCESS';
|
||||
export const UPDATE_STATUS_FAILURE = 'UPDATE_STATUS_FAILURE';
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as actions from '../constants/comments';
|
||||
import * as userActions from '../constants/user';
|
||||
import * as userActions from '../constants/users';
|
||||
import {Map, List, fromJS} from 'immutable';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as actions from '../constants/user';
|
||||
import * as actions from '../constants/users';
|
||||
import * as assetActions from '../constants/assets';
|
||||
import {addNotification} from '../actions/notification';
|
||||
import {addItem} from '../actions/items';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Map} from 'immutable';
|
||||
import * as authActions from '../constants/auth';
|
||||
import * as actions from '../constants/user';
|
||||
import * as actions from '../constants/users';
|
||||
import * as assetActions from '../constants/assets';
|
||||
|
||||
const initialState = Map({
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user