Browse Source

added PointInPolygon service configuration

pull/875/head
Stephen Hess 8 years ago
parent
commit
dd172d782e
  1. 18
      service/configurations/PointInPolygon.js
  2. 82
      test/unit/service/configurations/PointInPolygon.js

18
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;

82
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);
}
};
Loading…
Cancel
Save