diff --git a/client/coral-admin/src/reducers/assets.js b/client/coral-admin/src/reducers/assets.js index a1ca4c831..f18aaec33 100644 --- a/client/coral-admin/src/reducers/assets.js +++ b/client/coral-admin/src/reducers/assets.js @@ -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; } }; diff --git a/tests/client/coral-admin/reducers/assets.js b/tests/client/coral-admin/reducers/assets.js index 2a3c15b45..60972f47a 100644 --- a/tests/client/coral-admin/reducers/assets.js +++ b/tests/client/coral-admin/reducers/assets.js @@ -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; + }); + }); });