diff --git a/package.json b/package.json index d543007..72c18c2 100644 --- a/package.json +++ b/package.json @@ -74,8 +74,8 @@ "start:react": "REACT_APP_ENV=local REACT_APP_AUTH_URL=http://localhost:3001 REACT_APP_API_URL=http://localhost:3001/api react-scripts start", "build": "react-scripts build", "eject": "react-scripts eject", - "cover": "NODE_ENV=test SERVE_HTML=true ENV=local ./node_modules/istanbul/lib/cli.js cover --report cobertura ./node_modules/mocha/bin/_mocha -- -R spec test/server.test.js", - "test": "npm run test:unit; npm run test:server; npm run test:server", + "cover": "NODE_ENV=test SERVE_HTML=true ./node_modules/istanbul/lib/cli.js cover --report cobertura ./node_modules/mocha/bin/_mocha -- -R spec test/server-test-spec --recursive", + "test": "npm run test:unit; npm run test:server; npm run test:load", "test:unit": "./node_modules/babel-cli/bin/babel-node.js test/utils-unit-tests.js", "test:load": "./node_modules/babel-cli/bin/babel-node.js test/loadtest-unit-tests.js", "test:server": "./node_modules/mocha/bin/mocha test/server.test.js; ./node_modules/mocha/bin/mocha test/server-test-spec --recursive", diff --git a/src/actions/ApiActions.js b/src/actions/ApiActions.js index e4e6887..2442f97 100644 --- a/src/actions/ApiActions.js +++ b/src/actions/ApiActions.js @@ -21,12 +21,17 @@ export function matchSearch(query) { apiSearch.match(formattedQuery, (success, data) => { dispatch(sendingRequest(SENDING_MATCH_REQUEST, false)); if (success) { - dispatch(setResults(SET_MATCH_RESULTS, { - results: data.results, - })); - dispatch(setHeaders(SET_MATCH_HEADERS, { - headers: data.response, - })); + // This is a workaround for the API returning 200 {} for no results, should be 404 + if (Object.keys(data.results).length === 0 && data.results.constructor === Object) { + dispatch(setErrorMessage(SET_MATCH_ERROR_MESSAGE, '404: No results found.', Math.floor(new Date() / 1000))); + } else { + dispatch(setResults(SET_MATCH_RESULTS, { + results: data.results, + })); + dispatch(setHeaders(SET_MATCH_HEADERS, { + headers: data.response, + })); + } } else { dispatch(setErrorMessage(SET_MATCH_ERROR_MESSAGE, data.message, Math.floor(new Date() / 1000))); } @@ -52,12 +57,17 @@ export function rangeSearch(query) { apiSearch.match(formattedQuery, (success, data) => { dispatch(sendingRequest(SENDING_RANGE_REQUEST, false)); if (success) { - dispatch(setResults(SET_RANGE_RESULTS, { - results: data.results, - })); - dispatch(setHeaders(SET_RANGE_HEADERS, { - headers: data.response, - })); + // This is a workaround for the API returning 200 {} for no results, should be 404 + if (Object.keys(data.results).length === 0 && data.results.constructor === Object) { + dispatch(setErrorMessage(SET_RANGE_ERROR_MESSAGE, '404: No results found.', Math.floor(new Date() / 1000))); + } else { + dispatch(setResults(SET_RANGE_RESULTS, { + results: data.results, + })); + dispatch(setHeaders(SET_RANGE_HEADERS, { + headers: data.response, + })); + } } else { dispatch(setErrorMessage(SET_RANGE_ERROR_MESSAGE, data.message, Math.floor(new Date() / 1000))); } @@ -81,12 +91,17 @@ export function ubrnSearch(id) { apiSearch.ubrn(id, (success, data) => { dispatch(sendingRequest(SENDING_UBRN_REQUEST, false)); if (success) { - dispatch(setResults(SET_UBRN_RESULTS, { - results: data.results, - })); - dispatch(setHeaders(SET_UBRN_HEADERS, { - headers: data.response, - })); + // This is a workaround for the API returning 200 {} for no results, should be 404 + if (Object.keys(data.results).length === 0 && data.results.constructor === Object) { + dispatch(setErrorMessage(SET_UBRN_ERROR_MESSAGE, '404: No results found.', Math.floor(new Date() / 1000))); + } else { + dispatch(setResults(SET_UBRN_RESULTS, { + results: data.results, + })); + dispatch(setHeaders(SET_UBRN_HEADERS, { + headers: data.response, + })); + } } else { dispatch(setErrorMessage(SET_UBRN_ERROR_MESSAGE, data.message, Math.floor(new Date() / 1000))); } diff --git a/src/components/ErrorModal.js b/src/components/ErrorModal.js index df20878..80fff38 100644 --- a/src/components/ErrorModal.js +++ b/src/components/ErrorModal.js @@ -10,11 +10,11 @@ class ErrorModal extends React.Component { window.removeEventListener('keydown', this.props.close); } render() { - const modal = (this.props.show) ? ( - + const modal = (this.props.show) ? ( +

{this.props.message}


- +
) :
; return ( diff --git a/src/utils/formQuery.js b/src/utils/formQuery.js index 9c0f4f4..690b593 100644 --- a/src/utils/formQuery.js +++ b/src/utils/formQuery.js @@ -16,7 +16,7 @@ export function formRangeQuery(query) { const queryArr = Object.keys(query).map(param => { if (param === 'IndustryCode') { // ES format: IndustryCode:[${min} TO ${max}] - return `${param}${SEPERATOR}%5B1${query[param][0]} TO ${query[param][1]}%5D`; + return `${param}${SEPERATOR}%5B${query[param][0]} TO ${query[param][1]}%5D`; } else if (param === 'PostCode') { // ES format: PostCode:(${postCode}) return `${param}${SEPERATOR}(${query[param]})`; diff --git a/src/views/Login.js b/src/views/Login.js index 1481548..23d743a 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -24,6 +24,7 @@ class Login extends React.Component { } closeModal() { this.setState({ show: false, errorMessage: '' }); + this.usernameInput.focus(); } render() { return ( @@ -36,7 +37,7 @@ class Login extends React.Component { (this.usernameInput = ref)} /> (this.passwordInput = ref)} />