Browse Source

added predicate that tests for existence of focus.point

query-for-venues-on-admin-only
Stephen Hess 7 years ago
parent
commit
20d15db07e
  1. 19
      controller/predicates/has_request_focus_point.js
  2. 90
      test/unit/controller/predicates/has_request_focus_point.js
  3. 1
      test/unit/run.js

19
controller/predicates/has_request_focus_point.js

@ -0,0 +1,19 @@
const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:has_request_errors');
const stackTraceLine = require('../../helper/stackTraceLine');
// returns true IFF req.clean has both focus.point.lat and focus.point.lon
module.exports = (req, res) => {
const has_request_focus_point =
_.has(req, ['clean', 'focus.point.lat']) &&
_.has(req, ['clean', 'focus.point.lon']);
debugLog.push(req, () => ({
reply: has_request_focus_point,
stack_trace: stackTraceLine()
}));
return has_request_focus_point;
};

90
test/unit/controller/predicates/has_request_focus_point.js

@ -0,0 +1,90 @@
'use strict';
const _ = require('lodash');
const has_request_focus_point = require('../../../../controller/predicates/has_request_focus_point');
module.exports.tests = {};
module.exports.tests.interface = (test, common) => {
test('valid interface', t => {
t.equal(typeof has_request_focus_point, 'function', 'has_request_focus_point is a function');
t.end();
});
};
module.exports.tests.true_conditions = (test, common) => {
test('request.clean with focus.point.lat and focus.point.lon should return true', t => {
const req = {
clean: {
'focus.point.lat': 12.121212,
'focus.point.lon': 21.212121
}
};
t.ok(has_request_focus_point(req));
t.end();
});
};
module.exports.tests.false_conditions = (test, common) => {
test('undefined req should return false', t => {
t.notOk(has_request_focus_point());
t.end();
});
test('undefined req.clean should return false', t => {
const req = {};
t.notOk(has_request_focus_point(req));
t.end();
});
test('undefined req.clean.\'focus.point.lat\' and req.clean.\'focus.point.lon\' should return false', t => {
const req = {
clean: {}
};
t.notOk(has_request_focus_point(req));
t.end();
});
test('undefined req.clean.\'focus.point.lat\' and defined req.clean.\'focus.point.lon\' should return false', t => {
const req = {
clean: {
'focus.point.lon': 21.212121
}
};
t.notOk(has_request_focus_point(req));
t.end();
});
test('defined req.clean.\'focus.point.lat\' and undefined req.clean.\'focus.point.lon\' should return false', t => {
const req = {
clean: {
'focus.point.lat': 12.121212
}
};
t.notOk(has_request_focus_point(req));
t.end();
});
};
module.exports.all = (tape, common) => {
function test(name, testFunction) {
return tape(`GET /has_request_focus_point ${name}`, testFunction);
}
for( const testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

1
test/unit/run.js

@ -20,6 +20,7 @@ var tests = [
require('./controller/search'),
require('./controller/search_with_ids'),
require('./controller/predicates/has_parsed_text_properties'),
require('./controller/predicates/has_request_focus_point'),
require('./controller/predicates/has_request_parameter'),
require('./controller/predicates/has_response_data'),
require('./controller/predicates/has_results_at_layers'),

Loading…
Cancel
Save