mirror of https://github.com/pelias/api.git
Julian Simioni
7 years ago
committed by
GitHub
6 changed files with 215 additions and 3 deletions
@ -0,0 +1,16 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:is_request_sources_includes_whosonfirst'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
// returns true IFF 'whosonfirst' is included in the requested sources
|
||||
module.exports = (req, res) => { |
||||
const is_request_sources_includes_whosonfirst = _.get(req, 'clean.sources', []).includes( |
||||
'whosonfirst' |
||||
); |
||||
debugLog.push(req, () => ({ |
||||
reply: is_request_sources_includes_whosonfirst, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return is_request_sources_includes_whosonfirst; |
||||
}; |
@ -0,0 +1,16 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:is_request_sources_undefined'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
// returns true IFF there are no requested sources
|
||||
module.exports = (req, res) => { |
||||
const is_request_sources_undefined = _.isEmpty( |
||||
_.get(req, 'clean.sources') |
||||
); |
||||
debugLog.push(req, () => ({ |
||||
reply: is_request_sources_undefined, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return is_request_sources_undefined; |
||||
}; |
@ -0,0 +1,92 @@
|
||||
const _ = require('lodash'); |
||||
const is_request_sources_includes_whosonfirst = require('../../../../controller/predicates/is_request_sources_includes_whosonfirst'); |
||||
|
||||
module.exports.tests = {}; |
||||
|
||||
module.exports.tests.interface = (test, common) => { |
||||
test('valid interface', (t) => { |
||||
t.ok(_.isFunction(is_request_sources_includes_whosonfirst), 'is_request_sources_includes_whosonfirst is a function'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.tests.true_conditions = (test, common) => { |
||||
test('sources includes \'whosonfirst\' should return true', (t) => { |
||||
const req = { |
||||
clean: { |
||||
sources: [ |
||||
'whosonfirst', |
||||
'not whosonfirst' |
||||
] |
||||
} |
||||
}; |
||||
|
||||
t.ok(is_request_sources_includes_whosonfirst(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('empty req.clean.sources should return false', (t) => { |
||||
const req = { |
||||
clean: { |
||||
sources: [] |
||||
} |
||||
}; |
||||
|
||||
t.notOk(is_request_sources_includes_whosonfirst(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
}; |
||||
|
||||
module.exports.tests.false_conditions = (test, common) => { |
||||
test('undefined req should return false', (t) => { |
||||
t.notOk(is_request_sources_includes_whosonfirst(undefined)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('undefined req.clean should return false', (t) => { |
||||
const req = {}; |
||||
|
||||
t.notOk(is_request_sources_includes_whosonfirst(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('undefined req.clean.sources should return false', (t) => { |
||||
const req = { |
||||
clean: {} |
||||
}; |
||||
|
||||
t.notOk(is_request_sources_includes_whosonfirst(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('sources not \'whosonfirst\' should return false', (t) => { |
||||
const req = { |
||||
clean: { |
||||
sources: [ |
||||
'not whosonfirst' |
||||
] |
||||
} |
||||
}; |
||||
|
||||
t.notOk(is_request_sources_includes_whosonfirst(req)); |
||||
t.end(); |
||||
|
||||
}) |
||||
|
||||
}; |
||||
|
||||
module.exports.all = (tape, common) => { |
||||
function test(name, testFunction) { |
||||
return tape(`GET /is_request_sources_includes_whosonfirst ${name}`, testFunction); |
||||
} |
||||
|
||||
for( const testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
@ -0,0 +1,78 @@
|
||||
const _ = require('lodash'); |
||||
const is_request_sources_undefined = require('../../../../controller/predicates/is_request_sources_undefined'); |
||||
|
||||
module.exports.tests = {}; |
||||
|
||||
module.exports.tests.interface = (test, common) => { |
||||
test('valid interface', (t) => { |
||||
t.ok(_.isFunction(is_request_sources_undefined), 'is_request_sources_undefined is a function'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.tests.true_conditions = (test, common) => { |
||||
test('undefined req should return true', (t) => { |
||||
|
||||
t.ok(is_request_sources_undefined(undefined)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('undefined req.clean should return true', (t) => { |
||||
const req = {}; |
||||
|
||||
t.ok(is_request_sources_undefined(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('undefined req.clean.sources should return true', (t) => { |
||||
const req = { |
||||
clean: {} |
||||
}; |
||||
|
||||
t.ok(is_request_sources_undefined(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('empty req.clean.sources should return true', (t) => { |
||||
const req = { |
||||
clean: { |
||||
sources: [] |
||||
} |
||||
}; |
||||
|
||||
t.ok(is_request_sources_undefined(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
}; |
||||
|
||||
module.exports.tests.false_conditions = (test, common) => { |
||||
test('sources not empty should return false', (t) => { |
||||
const req = { |
||||
clean: { |
||||
sources: [ |
||||
'not empty' |
||||
] |
||||
} |
||||
}; |
||||
|
||||
t.notOk(is_request_sources_undefined(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
}; |
||||
|
||||
module.exports.all = (tape, common) => { |
||||
function test(name, testFunction) { |
||||
return tape(`GET /is_request_sources_undefined ${name}`, testFunction); |
||||
} |
||||
|
||||
for( const testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
Loading…
Reference in new issue