Browse Source

added has_parsed_text_property predicate

pull/912/head
Stephen Hess 8 years ago
parent
commit
e158c21685
  1. 13
      controller/predicates/has_parsed_text_property.js
  2. 10
      routes/v1.js
  3. 82
      test/unit/controller/predicates/has_parsed_text_property.js
  4. 1
      test/unit/run.js

13
controller/predicates/has_parsed_text_property.js

@ -0,0 +1,13 @@
const _ = require('lodash');
// returns a function that returns true if any result.layer is in any of the
// supplied layers using array intersection
// example usage: determining if the response contains only admin results
module.exports = (property) => {
return (request, response) => {
return _.has(request, ['clean', 'parsed_text', property]);
};
};

10
routes/v1.js

@ -66,6 +66,7 @@ var postProc = {
};
// predicates that drive whether controller/search runs
const hasParsedTextProperty = require('../controller/predicates/has_parsed_text_property');
const hasResponseData = require('../controller/predicates/has_response_data');
const hasRequestErrors = require('../controller/predicates/has_request_errors');
const isCoarseReverse = require('../controller/predicates/is_coarse_reverse');
@ -103,7 +104,14 @@ function addRoutes(app, peliasConfig) {
);
const placeholderShouldExecute = all(
not(hasResponseDataOrRequestErrors), isPlaceholderServiceEnabled, isAdminOnlyAnalysis
not(hasResponseDataOrRequestErrors),
isPlaceholderServiceEnabled,
not(
any(
hasParsedTextProperty('venue'),
hasParsedTextProperty('category')
)
)
);
// execute under the following conditions:

82
test/unit/controller/predicates/has_parsed_text_property.js

@ -0,0 +1,82 @@
'use strict';
const _ = require('lodash');
const has_parsed_text_property = require('../../../../controller/predicates/has_parsed_text_property');
module.exports.tests = {};
module.exports.tests.interface = (test, common) => {
test('valid interface', (t) => {
t.equal(typeof has_parsed_text_property, 'function', 'has_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'
}
}
};
const res = {};
t.ok(has_parsed_text_property('property')(req, res));
t.end();
});
};
module.exports.tests.false_conditions = (test, common) => {
test('undefined request should return false', (t) => {
const req = {};
t.notOk(has_parsed_text_property('property')(req, undefined));
t.end();
});
test('undefined request.clean should return false', (t) => {
const req = {};
t.notOk(has_parsed_text_property('property')(req, undefined));
t.end();
});
test('undefined request.clean.parsed_text should return false', (t) => {
const req = {
clean: {}
};
t.notOk(has_parsed_text_property('property')(req, undefined));
t.end();
});
test('undefined request.clean.parsed_text.property should return false', (t) => {
const req = {
clean: {
parsed_text: {}
}
};
t.notOk(has_parsed_text_property('property')(req, undefined));
t.end();
});
};
module.exports.all = (tape, common) => {
function test(name, testFunction) {
return tape(`GET /has_parsed_text_property ${name}`, testFunction);
}
for( const testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

1
test/unit/run.js

@ -16,6 +16,7 @@ var tests = [
require('./controller/place'),
require('./controller/placeholder'),
require('./controller/search'),
require('./controller/predicates/has_parsed_text_property'),
require('./controller/predicates/has_response_data'),
require('./controller/predicates/has_results_at_layers'),
require('./controller/predicates/has_request_errors'),

Loading…
Cancel
Save