mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.1 KiB
95 lines
2.1 KiB
8 years ago
|
'use strict';
|
||
|
|
||
|
const _ = require('lodash');
|
||
7 years ago
|
const has_any_parsed_text_property = require('../../../../controller/predicates/has_any_parsed_text_property');
|
||
8 years ago
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.interface = (test, common) => {
|
||
|
test('valid interface', (t) => {
|
||
7 years ago
|
t.ok(_.isFunction(has_any_parsed_text_property), 'has_any_parsed_text_property is a function');
|
||
8 years ago
|
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'
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
7 years ago
|
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));
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
module.exports.tests.false_conditions = (test, common) => {
|
||
|
test('undefined request should return false', (t) => {
|
||
7 years ago
|
t.notOk(has_any_parsed_text_property('property')());
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('undefined request.clean should return false', (t) => {
|
||
|
const req = {};
|
||
|
|
||
7 years ago
|
t.notOk(has_any_parsed_text_property('property')(req));
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('undefined request.clean.parsed_text should return false', (t) => {
|
||
|
const req = {
|
||
|
clean: {}
|
||
|
};
|
||
|
|
||
7 years ago
|
t.notOk(has_any_parsed_text_property('property')(req));
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
7 years ago
|
test('request.clean.parsed_text with none of the supplied properties should return false', (t) => {
|
||
8 years ago
|
const req = {
|
||
|
clean: {
|
||
|
parsed_text: {}
|
||
|
}
|
||
|
};
|
||
|
|
||
7 years ago
|
t.notOk(has_any_parsed_text_property('property1', 'property2')(req));
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
module.exports.all = (tape, common) => {
|
||
|
function test(name, testFunction) {
|
||
7 years ago
|
return tape(`GET /has_any_parsed_text_property ${name}`, testFunction);
|
||
8 years ago
|
}
|
||
|
|
||
|
for( const testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|