Adding update state to reducer.

This commit is contained in:
David Jay
2016-12-15 14:05:10 -05:00
parent c7b232f0b3
commit 328eaad8e5
2 changed files with 32 additions and 4 deletions
+5 -2
View File
@@ -1,5 +1,5 @@
import {Map, List, fromJS} from 'immutable';
import {FETCH_ASSETS_SUCCESS} from '../constants/assets';
import {FETCH_ASSETS_SUCCESS, UPDATE_ASSET_STATE} from '../constants/assets';
const initialState = Map({
byId: Map(),
@@ -8,7 +8,10 @@ const initialState = Map({
export default (state = initialState, action) => {
switch (action.type) {
case FETCH_ASSETS_SUCCESS: return replaceAssets(action, state);
case FETCH_ASSETS_SUCCESS:
return replaceAssets(action, state);
case UPDATE_ASSET_STATE:
return state.setIn(['byId', action.id, 'closedAt'], action.closedAt);
default: return state;
}
};
+27 -2
View File
@@ -1,4 +1,4 @@
import {Map} from 'immutable';
import {Map, fromJS} from 'immutable';
import {expect} from 'chai';
import assetsReducer from '../../../../client/coral-admin/src/reducers/assets';
@@ -23,7 +23,6 @@ describe ('assetsReducer', () => {
};
const store = new Map({});
const result = assetsReducer(store, action);
console.log(result.getIn(['byId', '123']).toJS());
expect(result.getIn(['byId', '123']).toJS()).to.deep.equal({
url: 'http://test.com',
closedAt: 'tomorrow',
@@ -36,4 +35,30 @@ describe ('assetsReducer', () => {
expect(result.getIn(['count'])).to.equal(200);
});
});
describe('UPDATE_ASSET_STATE', () => {
it('should update the state of a particular asset', () => {
const action = {
type: 'UPDATE_ASSET_STATE',
id: '123',
closedAt: null
};
const store = new fromJS({
byId: {
'123': {
id: '123',
url: 'http://test.com',
closedAt: Date.now()
},
'456': {
id: '456',
url: 'http://test2.com',
closedAt: 'thursday'
}
}
});
const result = assetsReducer(store, action);
expect(result.getIn(['byId', '123', 'closedAt'])).to.equal.null;
});
});
});