Commit 7987bd8b authored by Robbe Van Herck's avatar Robbe Van Herck Committed by Harrison Healey
Browse files

Fixed incorrect action dispatching +tests (#768)

* Store expanded URLs

* Fixed test

* Added tests

* fixed dispatched events structure

* Added tests for the actions
parent ef3caa55
......@@ -203,7 +203,7 @@ export function getRedirectLocation(url: string): ActionFunc {
return {error};
}
dispatch({type: GeneralTypes.REDIRECT_LOCATION_SUCCESS, data: {data, url}}, getState);
dispatch({type: GeneralTypes.REDIRECT_LOCATION_SUCCESS, data: {...data, url}}, getState);
return {data};
};
}
......
......@@ -174,5 +174,26 @@ describe('Actions.General', () => {
// Should not call the API on an old server
assert.equal(mock.isDone(), false);
});
it('should save the correct location', async () => {
store.dispatch({type: GeneralTypes.RECEIVED_SERVER_VERSION, data: '5.3.0'});
nock(Client4.getBaseRoute()).
get('/redirect_location').
query({url: 'http://examp.le'}).
reply(200, '{"location": "https://example.com"}');
// Save the found URL if it finds one
await store.dispatch(Actions.getRedirectLocation('http://examp.le'));
const existingURL = store.getState().entities.posts.expandedURLs['http://examp.le'];
assert.equal(existingURL, 'https://example.com');
// Save the found URL if it finds one
await store.dispatch(Actions.getRedirectLocation('http://nonexisting.url'));
const nonexistingURL = store.getState().entities.posts.expandedURLs['http://nonexisting.url'];
assert.equal(nonexistingURL, 'http://nonexisting.url');
});
});
});
......@@ -749,12 +749,12 @@ function expandedURLs(state = {}, action) {
case GeneralTypes.REDIRECT_LOCATION_SUCCESS:
return {
...state,
[action.url]: action.data.location,
[action.data.url]: action.data.location,
};
case GeneralTypes.REDIRECT_LOCATION_FAILURE:
return {
...state,
[action.url]: action.url,
[action.data.url]: action.data.url,
};
default:
return state;
......@@ -807,7 +807,8 @@ export default function(state = {}, action) {
state.currentFocusedPostId === nextState.currentFocusedPostId &&
state.reactions === nextState.reactions &&
state.openGraph === nextState.openGraph &&
state.messagesHistory === nextState.messagesHistory) {
state.messagesHistory === nextState.messagesHistory &&
state.expandedURLs === nextState.expandedURLs) {
// None of the children have changed so don't even let the parent object change
return state;
}
......
......@@ -1019,8 +1019,8 @@ describe('Reducers.posts', () => {
const state = deepFreeze({});
const action = {
type: GeneralTypes.REDIRECT_LOCATION_SUCCESS,
url: 'a',
data: {
url: 'a',
location: 'b',
},
};
......@@ -1034,7 +1034,9 @@ describe('Reducers.posts', () => {
const state = deepFreeze({});
const action = {
type: GeneralTypes.REDIRECT_LOCATION_FAILURE,
url: 'b',
data: {
url: 'b',
},
};
const nextState = postsReducer(state, action);
assert.notEqual(state, nextState);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment