From dd172d782ee3b178485b36baca3ff2de7fd6449a Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 2 May 2017 15:31:16 -0400 Subject: [PATCH] added PointInPolygon service configuration --- service/configurations/PointInPolygon.js | 18 ++++ .../service/configurations/PointInPolygon.js | 82 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 service/configurations/PointInPolygon.js create mode 100644 test/unit/service/configurations/PointInPolygon.js diff --git a/service/configurations/PointInPolygon.js b/service/configurations/PointInPolygon.js new file mode 100644 index 00000000..2bf7e721 --- /dev/null +++ b/service/configurations/PointInPolygon.js @@ -0,0 +1,18 @@ +'use strict'; + +const _ = require('lodash'); + +const ServiceConfiguration = require('./ServiceConfiguration'); + +class PointInPolygon extends ServiceConfiguration { + constructor(o) { + super('pip', o); + } + + getUrl(req) { + return `${this.baseUrl}/${req.clean.point.lon}/${req.clean.point.lat}`; + } + +} + +module.exports = PointInPolygon; diff --git a/test/unit/service/configurations/PointInPolygon.js b/test/unit/service/configurations/PointInPolygon.js new file mode 100644 index 00000000..5fb04d2d --- /dev/null +++ b/test/unit/service/configurations/PointInPolygon.js @@ -0,0 +1,82 @@ +module.exports.tests = {}; + +const PointInPolygon = require('../../../../service/configurations/PointInPolygon'); + +module.exports.tests.all = (test, common) => { + test('getName should return \'pip\'', (t) => { + const configBlob = { + url: 'base url', + timeout: 17, + retries: 19 + }; + + const pointInPolygon = new PointInPolygon(configBlob); + + t.equals(pointInPolygon.getName(), 'pip'); + t.equals(pointInPolygon.getBaseUrl(), 'base url'); + t.equals(pointInPolygon.getTimeout(), 17); + t.equals(pointInPolygon.getRetries(), 19); + t.end(); + + }); + + test('getUrl should return value formatted with point.lon/lat passed to constructor', (t) => { + const configBlob = { + url: 'base url' + }; + + const pointInPolygon = new PointInPolygon(configBlob); + + const req = { + clean: { + point: { + lat: 12.121212, + lon: 21.212121 + } + } + }; + + t.equals(pointInPolygon.getUrl(req), 'base url/21.212121/12.121212'); + t.end(); + + }); + + test('getHeaders should return an empty object', (t) => { + const configBlob = { + url: 'base url', + timeout: 17, + retries: 19 + }; + + const pointInPolygon = new PointInPolygon(configBlob); + + t.deepEquals(pointInPolygon.getHeaders(), {}); + t.end(); + + }); + + test('getParameters should return an empty object', (t) => { + const configBlob = { + url: 'base url', + timeout: 17, + retries: 19 + }; + + const pointInPolygon = new PointInPolygon(configBlob); + + t.deepEquals(pointInPolygon.getParameters(), {}); + t.end(); + + }); + +}; + +module.exports.all = (tape, common) => { + function test(name, testFunction) { + return tape(`SERVICE CONFIGURATION /PointInPolygon ${name}`, testFunction); + } + + for( var testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +};