Skip to content

Commit

Permalink
Externalized in epic getFeatureInfo retrieval logic (#3616)
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz authored Mar 13, 2019
1 parent cd62de6 commit e68ce42
Show file tree
Hide file tree
Showing 13 changed files with 467 additions and 1,451 deletions.
106 changes: 0 additions & 106 deletions web/client/actions/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

var expect = require('expect');
var {
ERROR_FEATURE_INFO,
EXCEPTIONS_FEATURE_INFO,
LOAD_FEATURE_INFO,
CHANGE_MAPINFO_STATE,
NEW_MAPINFO_REQUEST,
PURGE_MAPINFO_RESULTS,
Expand All @@ -20,7 +17,6 @@ var {
GET_VECTOR_INFO,
TOGGLE_MAPINFO_STATE,
UPDATE_CENTER_TO_MARKER,
getFeatureInfo,
changeMapInfoState,
newMapInfoRequest,
purgeMapInfoResults,
Expand All @@ -36,108 +32,6 @@ var {

describe('Test correctness of the map actions', () => {

it('get feature info data', (done) => {
/*eslint-disable */
let reqId;
/*eslint-enable */
getFeatureInfo('base/web/client/test-resources/featureInfo-response.json', {p: "p"}, "meta")((e) => {
if (e.type === NEW_MAPINFO_REQUEST) {
reqId = e.reqId;
try {
expect(e).toExist();
expect(e.type).toBe(NEW_MAPINFO_REQUEST);
expect(e.reqId).toExist();
expect(e.request).toExist();
expect(e.request.p).toBe("p");
} catch (ex) {
done(ex);
}
} else if (e.type === LOAD_FEATURE_INFO) {
try {
expect(e).toExist();
expect(e.type).toBe(LOAD_FEATURE_INFO);
expect(e.data).toExist();
expect(e.requestParams).toExist();
expect(e.reqId).toExist();
expect(e.reqId).toBe(reqId);
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch (ex) {
done(ex);
}
}
});
});

it('get feature info exception', (done) => {
/*eslint-disable */
let reqId;
/*eslint-enable */
getFeatureInfo('base/web/client/test-resources/featureInfo-exception.json', {p: "p"}, "meta")((e) => {
if (e.type === NEW_MAPINFO_REQUEST) {
reqId = e.reqId;
try {
expect(e).toExist();
expect(e.type).toBe(NEW_MAPINFO_REQUEST);
expect(e.reqId).toExist();
expect(e.request).toExist();
expect(e.request.p).toBe("p");
} catch (ex) {
done(ex);
}
} else if (e.type === EXCEPTIONS_FEATURE_INFO) {
try {
expect(e).toExist();
expect(e.type).toBe(EXCEPTIONS_FEATURE_INFO);
expect(e.exceptions).toExist();
expect(e.reqId).toExist();
expect(e.reqId).toBe(reqId);
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch (ex) {
done(ex);
}
}
});
});

it('get feature info error', (done) => {
/*eslint-disable */
let reqId;
/*eslint-enable */
getFeatureInfo('requestError.json', {p: "p"}, "meta")((e) => {
if (e.type === NEW_MAPINFO_REQUEST) {
reqId = e.reqId;
try {
expect(e).toExist();
expect(e.type).toBe(NEW_MAPINFO_REQUEST);
expect(e.reqId).toExist();
expect(e.request).toExist();
expect(e.request.p).toBe("p");
} catch (ex) {
done(ex);
}
} else if (e.type === ERROR_FEATURE_INFO) {
try {
expect(e).toExist();
expect(e.type).toBe(ERROR_FEATURE_INFO);
expect(e.error).toExist();
expect(e.reqId).toExist();
expect(e.reqId).toBe(reqId);
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch (ex) {
done(ex);
}
}
});
});

it('gets vector info', () => {
const retval = getVectorInfo('layer', 'request', 'metadata');

Expand Down
35 changes: 3 additions & 32 deletions web/client/actions/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

const assign = require('object-assign');
const axios = require('axios');
const uuid = require('uuid');
const GeoCodingApi = require('../api/Nominatim');

const LOAD_FEATURE_INFO = 'LOAD_FEATURE_INFO';
Expand Down Expand Up @@ -48,7 +44,7 @@ function loadFeatureInfo(reqId, data, rParams, lMetaData) {

/**
* Private
* @return a ERROR_FEATURE_INFO action with the error occured
* @return a ERROR_FEATURE_INFO action with the error occurred
*/
function errorFeatureInfo(reqId, e, rParams, lMetaData) {
return {
Expand All @@ -62,7 +58,7 @@ function errorFeatureInfo(reqId, e, rParams, lMetaData) {

/**
* Private
* @return a EXCEPTIONS_FEATURE_INFO action with the wms exception occured
* @return a EXCEPTIONS_FEATURE_INFO action with the wms exception occurred
* during a GetFeatureInfo request.
*/
function exceptionsFeatureInfo(reqId, exceptions, rParams, lMetaData) {
Expand Down Expand Up @@ -104,31 +100,6 @@ function getVectorInfo(layer, request, metadata) {
};
}


/**
* Sends a GetFeatureInfo request and dispatches the right action
* in case of success, error or exceptions.
*
* @param basePath {string} base path to the service
* @param requestParams {object} map of params for a getfeatureinfo request.
*/
function getFeatureInfo(basePath, requestParams, lMetaData, options = {}) {
const param = assign({}, options, requestParams);
const reqId = uuid.v1();
return (dispatch) => {
dispatch(newMapInfoRequest(reqId, param));
axios.get(basePath, {params: param}).then((response) => {
if (response.data.exceptions) {
dispatch(exceptionsFeatureInfo(reqId, response.data.exceptions, requestParams, lMetaData));
} else {
dispatch(loadFeatureInfo(reqId, response.data, requestParams, lMetaData));
}
}).catch((e) => {
dispatch(errorFeatureInfo(reqId, e.data || e.statusText || e.status, requestParams, lMetaData));
});
};
}

function changeMapInfoState(enabled) {
return {
type: CHANGE_MAPINFO_STATE,
Expand Down Expand Up @@ -263,7 +234,7 @@ module.exports = {
TOGGLE_SHOW_COORD_EDITOR, toggleShowCoordinateEditor,
CHANGE_FORMAT, changeFormat,
closeIdentify,
getFeatureInfo,
exceptionsFeatureInfo,
changeMapInfoState,
newMapInfoRequest,
purgeMapInfoResults,
Expand Down
Loading

0 comments on commit e68ce42

Please sign in to comment.