From 5b86fbd7d8a3c9627c802bbcab651e826b5306cf Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 19 Sep 2017 15:15:57 -0400 Subject: [PATCH] add layers parameter support to PointInPolygon service request --- service/configurations/PointInPolygon.js | 10 ++++ .../service/configurations/PointInPolygon.js | 56 +++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/service/configurations/PointInPolygon.js b/service/configurations/PointInPolygon.js index 66a766f9..58b52093 100644 --- a/service/configurations/PointInPolygon.js +++ b/service/configurations/PointInPolygon.js @@ -11,6 +11,16 @@ class PointInPolygon extends ServiceConfiguration { super('pip', o); } + getParameters(req) { + if (_.has(req, 'clean.layers')) { + return { + layers: _.join(req.clean.layers, ',') + }; + } + + return {}; + } + getUrl(req) { // use resolve to eliminate possibility of duplicate /'s in URL return url.resolve(this.baseUrl, `${req.clean['point.lon']}/${req.clean['point.lat']}`); diff --git a/test/unit/service/configurations/PointInPolygon.js b/test/unit/service/configurations/PointInPolygon.js index c754e7f9..6906950f 100644 --- a/test/unit/service/configurations/PointInPolygon.js +++ b/test/unit/service/configurations/PointInPolygon.js @@ -53,16 +53,62 @@ module.exports.tests.all = (test, common) => { }); - test('getParameters should return an empty object', (t) => { + test('getParameters should return an empty object when req is undefined', (t) => { const configBlob = { - url: 'http://localhost:1234', - timeout: 17, - retries: 19 + url: 'http://localhost:1234' }; const pointInPolygon = new PointInPolygon(configBlob); - t.deepEquals(pointInPolygon.getParameters(), {}); + t.deepEquals(pointInPolygon.getParameters(undefined), {}); + t.end(); + + }); + + test('getParameters should return an empty object when req.clean is undefined', (t) => { + const configBlob = { + url: 'http://localhost:1234' + }; + + const pointInPolygon = new PointInPolygon(configBlob); + + const req = {}; + + t.deepEquals(pointInPolygon.getParameters(req), {}); + t.end(); + + }); + + test('getParameters should return an empty object when req.clean.layers is undefined', (t) => { + const configBlob = { + url: 'http://localhost:1234' + }; + + const pointInPolygon = new PointInPolygon(configBlob); + + const req = { + clean: {} + }; + + t.deepEquals(pointInPolygon.getParameters(req), {}); + t.end(); + + }); + + test('getParameters should return object with layers property when req.clean.layers is specified', t => { + const configBlob = { + url: 'http://localhost:1234' + }; + + const pointInPolygon = new PointInPolygon(configBlob); + + const req = { + clean: { + layers: ['layer1', 'layer2'] + } + }; + + t.deepEquals(pointInPolygon.getParameters(req), { layers: 'layer1,layer2'}); t.end(); });