Refactor action for easier testing

pull/462/head
Andrew Watkins 2016-11-10 16:18:39 -08:00
parent 089d727c11
commit 80d03553c9
3 changed files with 13 additions and 10 deletions

View File

@ -7,7 +7,7 @@ import {
updateMessage,
updateAlerts,
updateRuleName,
deleteRule,
deleteRuleSuccess,
} from 'src/kapacitor/actions/view';
describe('Kapacitor.Reducers.rules', () => {
@ -113,7 +113,7 @@ describe('Kapacitor.Reducers.rules', () => {
};
expect(Object.keys(initialState).length).to.equal(2);
const newState = reducer(initialState, deleteRule(rule2));
const newState = reducer(initialState, deleteRuleSuccess(rule2));
expect(Object.keys(newState).length).to.equal(1);
expect(newState[rule1]).to.equal(initialState[rule1]);
});

View File

@ -109,16 +109,19 @@ export function updateRuleName(ruleID, name) {
};
}
export function deleteRuleSuccess(ruleID) {
return {
type: 'DELETE_RULE_SUCCESS',
payload: {
ruleID,
},
};
}
export function deleteRule(rule) {
return (dispatch) => {
deleteRuleAPI(rule).then(() => {
dispatch({
type: 'DELETE_RULE',
payload: {
ruleID: rule.id,
},
});
dispatch(deleteRuleSuccess(rule.id));
dispatch(publishNotification('success', `${rule.name} deleted successfully`));
}).catch(() => {
dispatch(publishNotification('error', `${rule.name} deleted successfully`));

View File

@ -80,7 +80,7 @@ export default function rules(state = {}, action) {
});
}
case 'DELETE_RULE': {
case 'DELETE_RULE_SUCCESS': {
const {ruleID} = action.payload;
delete state[ruleID];
return Object.assign({}, state);