mirror of https://github.com/pelias/api.git
Lily He
7 years ago
committed by
GitHub
20 changed files with 233 additions and 73 deletions
@ -1,5 +1,13 @@ |
|||||||
const _ = require('lodash'); |
const _ = require('lodash'); |
||||||
|
const Debug = require('../../helper/debug'); |
||||||
|
const debugLog = new Debug('controller:predicates:has_request_errors'); |
||||||
|
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||||
|
|
||||||
module.exports = (request, response) => { |
module.exports = (req, res) => { |
||||||
return _.get(request, 'errors', []).length > 0; |
const has_request_errors = _.get(req, 'errors', []).length > 0; |
||||||
|
debugLog.push(req, () => ({ |
||||||
|
reply: has_request_errors, |
||||||
|
stack_trace: stackTraceLine() |
||||||
|
})); |
||||||
|
return has_request_errors; |
||||||
}; |
}; |
||||||
|
@ -1,4 +1,15 @@ |
|||||||
const _ = require('lodash'); |
const _ = require('lodash'); |
||||||
|
const Debug = require('../../helper/debug'); |
||||||
|
const debugLog = new Debug('controller:predicates:has_request_parameter'); |
||||||
|
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||||
|
|
||||||
// returns true IFF req.clean has a key with the supplied name
|
// returns true IFF req.clean has a key with the supplied name
|
||||||
module.exports = (parameter) => (req, res) => (_.has(req, ['clean', parameter])); |
module.exports = (parameter) => (req, res) => { |
||||||
|
const has_request_parameter = _.has(req, ['clean', parameter]); |
||||||
|
|
||||||
|
debugLog.push(req, () => ({ |
||||||
|
reply: {[parameter]: has_request_parameter}, |
||||||
|
stack_trace: stackTraceLine() |
||||||
|
})); |
||||||
|
return has_request_parameter; |
||||||
|
}; |
||||||
|
@ -1,5 +1,13 @@ |
|||||||
const _ = require('lodash'); |
const _ = require('lodash'); |
||||||
|
const Debug = require('../../helper/debug'); |
||||||
|
const debugLog = new Debug('controller:predicates:has_response_data'); |
||||||
|
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||||
|
|
||||||
module.exports = (request, response) => { |
module.exports = (request, response) => { |
||||||
return _.get(response, 'data', []).length > 0; |
const has_response_data = _.get(response, 'data', []).length > 0; |
||||||
|
debugLog.push(request, () => ({ |
||||||
|
reply: has_response_data, |
||||||
|
stack_trace: stackTraceLine() |
||||||
|
})); |
||||||
|
return has_response_data; |
||||||
}; |
}; |
||||||
|
@ -1,4 +1,14 @@ |
|||||||
const _ = require('lodash'); |
const _ = require('lodash'); |
||||||
|
const Debug = require('../../helper/debug'); |
||||||
|
const debugLog = new Debug('controller:predicates:is_addressit_parse'); |
||||||
|
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||||
|
|
||||||
// returns true IFF req.clean.parser is addressit
|
// returns true IFF req.clean.parser is addressit
|
||||||
module.exports = (req, res) => (_.get(req, 'clean.parser') === 'addressit'); |
module.exports = (req, res) => { |
||||||
|
const is_addressit_parse = _.get(req, 'clean.parser') === 'addressit'; |
||||||
|
debugLog.push(req, () => ({ |
||||||
|
reply: is_addressit_parse, |
||||||
|
stack_trace: stackTraceLine() |
||||||
|
})); |
||||||
|
return is_addressit_parse; |
||||||
|
}; |
||||||
|
@ -1,7 +1,16 @@ |
|||||||
const _ = require('lodash'); |
const _ = require('lodash'); |
||||||
|
const Debug = require('../../helper/debug'); |
||||||
|
const debugLog = new Debug('controller:predicates:is_only_non_admin_layers'); |
||||||
|
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||||
|
|
||||||
// return true IFF req.clean.layers is empty OR there are non-venue/address/street layers
|
// return true IFF req.clean.layers is empty OR there are non-venue/address/street layers
|
||||||
module.exports = (req, res) => ( |
module.exports = (req, res) => { |
||||||
!_.isEmpty(_.get(req, 'clean.layers', [])) && |
const is_only_non_admin_layers = !_.isEmpty(_.get(req, 'clean.layers', [])) && |
||||||
_.isEmpty(_.difference(req.clean.layers, ['venue', 'address', 'street'])) |
_.isEmpty(_.difference(req.clean.layers, ['venue', 'address', 'street'])); |
||||||
); |
|
||||||
|
debugLog.push(req, () => ({ |
||||||
|
reply: is_only_non_admin_layers, |
||||||
|
stack_trace: stackTraceLine() |
||||||
|
})); |
||||||
|
return is_only_non_admin_layers; |
||||||
|
}; |
||||||
|
@ -1,9 +1,17 @@ |
|||||||
const _ = require('lodash'); |
const _ = require('lodash'); |
||||||
|
const Debug = require('../../helper/debug'); |
||||||
|
const debugLog = new Debug('controller:predicates:is_request_sources_only_whosonfirst'); |
||||||
|
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||||
|
|
||||||
// returns true IFF 'whosonfirst' is the only requested source
|
// returns true IFF 'whosonfirst' is the only requested source
|
||||||
module.exports = (req, res) => ( |
module.exports = (req, res) => { |
||||||
_.isEqual( |
const is_request_sources_only_whosonfirst = _.isEqual( |
||||||
_.get(req, 'clean.sources', []), |
_.get(req, 'clean.sources', []), |
||||||
['whosonfirst'] |
['whosonfirst'] |
||||||
) |
); |
||||||
); |
debugLog.push(req, () => ({ |
||||||
|
reply: is_request_sources_only_whosonfirst, |
||||||
|
stack_trace: stackTraceLine() |
||||||
|
})); |
||||||
|
return is_request_sources_only_whosonfirst; |
||||||
|
}; |
||||||
|
@ -0,0 +1,13 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = () => { |
||||||
|
const stack = new Error().stack.split('\n'); |
||||||
|
let targetLine; |
||||||
|
|
||||||
|
stack.forEach((line) => { |
||||||
|
if(line.indexOf('at controller') !== -1) { |
||||||
|
targetLine = line.trim(); |
||||||
|
} |
||||||
|
}); |
||||||
|
return targetLine; |
||||||
|
}; |
@ -0,0 +1,20 @@ |
|||||||
|
const stackTraceLine = require('../../../helper/stackTraceLine'); |
||||||
|
|
||||||
|
module.exports.tests = {}; |
||||||
|
module.exports.tests.stackTrace = (test, common) => { |
||||||
|
test('No exceptions thrown when function is called', (t) => { |
||||||
|
t.doesNotThrow(stackTraceLine, 'No exceptions thrown'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
module.exports.all = function (tape, common) { |
||||||
|
|
||||||
|
function test(name, testFunction) { |
||||||
|
return tape('[helper] stackTraceLine: ' + name, testFunction); |
||||||
|
} |
||||||
|
|
||||||
|
for( var testCase in module.exports.tests ){ |
||||||
|
module.exports.tests[testCase](test, common); |
||||||
|
} |
||||||
|
}; |
Loading…
Reference in new issue