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