Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Add permalink and nofication req failure tests #1576

Benjamin King437a6c8d5102
diff --git a/web/js/modules/core/actions.js b/web/js/modules/core/actions.js
index 9c851623c..76a307284 100644
--- a/web/js/modules/core/actions.js
+++ b/web/js/modules/core/actions.js
@@ -9,9 +9,9 @@ export function requestAction(dispatch, actionName, url, fileType, signal) {
dispatch(fetchSuccess(actionName, data));
resolve(data);
})
- .catch(function(err) {
- dispatch(fetchFailure(actionName, err));
- reject(err);
+ .catch(function(error) {
+ dispatch(fetchFailure(actionName, error));
+ reject(error);
});
});
}
@@ -31,6 +31,6 @@ export function fetchSuccess(actionName, response) {
export function fetchFailure(actionName, error) {
return {
type: `${actionName}_FAILURE`,
- error: { error }
+ error: error
};
}
diff --git a/web/js/modules/link/actions.test.js b/web/js/modules/link/actions.test.js
index 3e51e162c..acdbde925 100644
--- a/web/js/modules/link/actions.test.js
+++ b/web/js/modules/link/actions.test.js
@@ -3,23 +3,17 @@ import thunk from 'redux-thunk';
import fetchMock from 'fetch-mock';
import * as actions from './actions';
import * as constants from './constants';
+
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
+const ERROR_MESSAGE = 'There was an error';
-const RESPONSE_BODY = {
- data: {
- url: 'http://go.nasa.gov/1iKIZ4j'
- },
- status_code: 200,
- status_txt: 'OK'
-};
-
-const MOCK_RESPONSE = {
- success: true,
- notifications: RESPONSE_BODY
-};
+// throw new Error(ERROR_MESSAGE);
+describe('Short Link request action', () => {
+ afterEach(() => {
+ fetchMock.restore();
+ });
-describe('Short Link fetch action', () => {
test(
'creates ' +
constants.REQUEST_SHORT_LINK_SUCESSS +
@@ -27,7 +21,7 @@ describe('Short Link fetch action', () => {
() => {
const loc = 'mock/';
fetchMock.getOnce(loc, {
- body: MOCK_RESPONSE,
+ body: constants.MOCK_SHORT_LINK_RESPONSE,
headers: {
'content-type': 'application/json',
'Access-Control-Allow-Origin': '*',
@@ -38,7 +32,7 @@ describe('Short Link fetch action', () => {
{ type: constants.REQUEST_SHORT_LINK_START },
{
type: constants.REQUEST_SHORT_LINK_SUCCESS,
- response: MOCK_RESPONSE
+ response: constants.MOCK_SHORT_LINK_RESPONSE
}
];
const store = mockStore({ shortLink: {} });
@@ -47,6 +41,23 @@ describe('Short Link fetch action', () => {
});
}
);
+ test('creates ' + constants.REQUEST_SHORT_LINK_FAILURE + ' Action', () => {
+ const loc = 'mock/';
+ fetchMock.mock(loc, {
+ throws: ERROR_MESSAGE
+ });
+ const expectedActions = [
+ { type: constants.REQUEST_SHORT_LINK_START },
+ {
+ type: constants.REQUEST_SHORT_LINK_FAILURE,
+ error: ERROR_MESSAGE
+ }
+ ];
+ const store = mockStore({ shortLink: {} });
+ return store.dispatch(actions.requestShortLink(loc, 'json')).catch(() => {
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
});
describe('updatePermalink action', () => {
test(
diff --git a/web/js/modules/link/constants.js b/web/js/modules/link/constants.js
index 372656a3c..39f428ce0 100644
--- a/web/js/modules/link/constants.js
+++ b/web/js/modules/link/constants.js
@@ -4,6 +4,19 @@ export const UPDATE_PERMALINK = 'UPDATE_PERMALINK';
export const REQUEST_SHORT_LINK_START = 'REQUEST_BITLY_SHORTENED_LINK_START';
export const REQUEST_SHORT_LINK_SUCCESS =
'REQUEST_BITLY_SHORTENED_LINK_SUCCESS';
-export const REQUEST_SHORT_LINKE_FAILURE =
+export const REQUEST_SHORT_LINK_FAILURE =
'REQUEST_BITLY_SHORTENED_LINK_FAILURE';
export const REQUEST_SHORT_LINK = 'REQUEST_BITLY_SHORTENED_LINK';
+
+export const MOCK_SHORT_LINK_RESPONSE_BODY = {
+ data: {
+ url: 'http://go.nasa.gov/1iKIZ4j'
+ },
+ status_code: 200,
+ status_txt: 'OK'
+};
+
+export const MOCK_SHORT_LINK_RESPONSE = {
+ success: true,
+ notifications: MOCK_SHORT_LINK_RESPONSE_BODY
+};
diff --git a/web/js/modules/link/reducers.js b/web/js/modules/link/reducers.js
index 1d88799d1..d8009c1ee 100644
--- a/web/js/modules/link/reducers.js
+++ b/web/js/modules/link/reducers.js
@@ -2,15 +2,15 @@ import { UPDATE_PERMALINK, REQUEST_SHORT_LINK } from './constants';
import { requestReducer } from '../core/reducers';
import { assign as lodashAssign } from 'lodash';
-const linkState = {
- permalink: ''
+export const deafultLinkState = {
+ queryString: ''
};
export function shortLink(state = {}, action) {
return requestReducer(REQUEST_SHORT_LINK, state, action);
}
-export function linkReducer(state = linkState, action) {
+export function linkReducer(state = deafultLinkState, action) {
switch (action.type) {
case UPDATE_PERMALINK:
return lodashAssign({}, state, {
diff --git a/web/js/modules/notifications/actions.test.js b/web/js/modules/notifications/actions.test.js
index 5fa87a6c0..754d51e36 100644
--- a/web/js/modules/notifications/actions.test.js
+++ b/web/js/modules/notifications/actions.test.js
@@ -5,8 +5,12 @@ import * as actions from './actions';
import * as constants from './constants';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
+const ERROR_MESSAGE = 'There was an error';
describe('Notification fetch action', () => {
+ afterEach(() => {
+ fetchMock.restore();
+ });
test('triggers start and success action types', () => {
const loc = 'mock/';
fetchMock.getOnce(loc, {
@@ -31,6 +35,25 @@ describe('Notification fetch action', () => {
expect(store.getActions()).toEqual(expectedActions);
});
});
+ test('creates ' + constants.REQUEST_NOTIFICATIONS_FAILURE + ' Action', () => {
+ const loc = 'mock/';
+ fetchMock.mock(loc, {
+ throws: ERROR_MESSAGE
+ });
+ const expectedActions = [
+ { type: constants.REQUEST_NOTIFICATIONS_START },
+ {
+ type: constants.REQUEST_NOTIFICATIONS_FAILURE,
+ error: ERROR_MESSAGE
+ }
+ ];
+ const store = mockStore({ shortLink: {} });
+ return store
+ .dispatch(actions.requestNotifications(loc, 'json'))
+ .catch(() => {
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
});
describe('Notification post-request actions', () => {
test(