mirror of https://github.com/pelias/api.git
Stephen Hess
8 years ago
4 changed files with 7 additions and 121 deletions
@ -1,18 +0,0 @@
|
||||
const _ = require('lodash'); |
||||
|
||||
// return true if any setup parameter is a key of request.clean.parsed_text
|
||||
// "arguments" is only available in long-form function declarations, cannot be shortened to fat arrow syntax
|
||||
// potential improvement: inject set operator to allow for any/all functionality
|
||||
module.exports = function() { |
||||
// save off requested properties since arguments can't be referenced later
|
||||
const properties = _.values(arguments); |
||||
|
||||
// return true if any of the supplied properties are in clean.parsed_text
|
||||
return (request, response) => !_.isEmpty( |
||||
_.intersection( |
||||
properties, |
||||
_.keys(_.get(request, ['clean', 'parsed_text'], {})) |
||||
) |
||||
); |
||||
|
||||
}; |
@ -1,94 +0,0 @@
|
||||
'use strict'; |
||||
|
||||
const _ = require('lodash'); |
||||
const has_any_parsed_text_property = require('../../../../controller/predicates/has_any_parsed_text_property'); |
||||
|
||||
module.exports.tests = {}; |
||||
|
||||
module.exports.tests.interface = (test, common) => { |
||||
test('valid interface', (t) => { |
||||
t.ok(_.isFunction(has_any_parsed_text_property), 'has_any_parsed_text_property is a function'); |
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.tests.true_conditions = (test, common) => { |
||||
test('defined request.clean.parsed_text.property should return true', (t) => { |
||||
const req = { |
||||
clean: { |
||||
parsed_text: { |
||||
property: 'value' |
||||
} |
||||
} |
||||
}; |
||||
|
||||
t.ok(has_any_parsed_text_property('property')(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('clean.parsed_text with any property should return true ', (t) => { |
||||
const req = { |
||||
clean: { |
||||
parsed_text: { |
||||
property2: 'value2', |
||||
property3: 'value3' |
||||
} |
||||
} |
||||
}; |
||||
|
||||
t.ok(has_any_parsed_text_property('property1', 'property3')(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
}; |
||||
|
||||
module.exports.tests.false_conditions = (test, common) => { |
||||
test('undefined request should return false', (t) => { |
||||
t.notOk(has_any_parsed_text_property('property')()); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('undefined request.clean should return false', (t) => { |
||||
const req = {}; |
||||
|
||||
t.notOk(has_any_parsed_text_property('property')(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('undefined request.clean.parsed_text should return false', (t) => { |
||||
const req = { |
||||
clean: {} |
||||
}; |
||||
|
||||
t.notOk(has_any_parsed_text_property('property')(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
test('request.clean.parsed_text with none of the supplied properties should return false', (t) => { |
||||
const req = { |
||||
clean: { |
||||
parsed_text: {} |
||||
} |
||||
}; |
||||
|
||||
t.notOk(has_any_parsed_text_property('property1', 'property2')(req)); |
||||
t.end(); |
||||
|
||||
}); |
||||
|
||||
}; |
||||
|
||||
module.exports.all = (tape, common) => { |
||||
function test(name, testFunction) { |
||||
return tape(`GET /has_any_parsed_text_property ${name}`, testFunction); |
||||
} |
||||
|
||||
for( const testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
Loading…
Reference in new issue