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.
59 lines
1.3 KiB
59 lines
1.3 KiB
8 years ago
|
const _ = require('lodash');
|
||
8 years ago
|
const has_request_errors = require('../../../../controller/predicates/has_request_errors');
|
||
8 years ago
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.interface = (test, common) => {
|
||
|
test('valid interface', (t) => {
|
||
8 years ago
|
t.equal(typeof has_request_errors, 'function', 'has_request_errors is a function');
|
||
8 years ago
|
t.end();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.tests.true_conditions = (test, common) => {
|
||
|
test('request with non-empty errors should return true', (t) => {
|
||
|
const req = {
|
||
|
errors: ['error']
|
||
|
};
|
||
|
const res = {};
|
||
|
|
||
8 years ago
|
t.ok(has_request_errors(req, res));
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
module.exports.tests.false_conditions = (test, common) => {
|
||
|
test('response with undefined errors should return false', (t) => {
|
||
|
const req = {};
|
||
|
const res = {};
|
||
|
|
||
8 years ago
|
t.notOk(has_request_errors(req, res));
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('response with empty errors array should return false', (t) => {
|
||
|
const req = {
|
||
|
errors: []
|
||
|
};
|
||
|
const res = {};
|
||
|
|
||
8 years ago
|
t.notOk(has_request_errors(req, res));
|
||
8 years ago
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
module.exports.all = (tape, common) => {
|
||
|
function test(name, testFunction) {
|
||
8 years ago
|
return tape(`GET /has_request_errors ${name}`, testFunction);
|
||
8 years ago
|
}
|
||
|
|
||
|
for( const testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|