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.
107 lines
2.4 KiB
107 lines
2.4 KiB
7 years ago
|
var calcSizeMiddleware = require('../../../middleware/sizeCalculator.js');
|
||
9 years ago
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.interface = function(test, common) {
|
||
|
test('interface', function(t) {
|
||
7 years ago
|
t.equal(typeof calcSizeMiddleware, 'function', 'valid function');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.tests.valid = function(test, common) {
|
||
9 years ago
|
var req = { clean: {} };
|
||
7 years ago
|
function setupQuery(val) {
|
||
9 years ago
|
if (isNaN(val)) {
|
||
|
delete req.clean.size;
|
||
|
}
|
||
|
else {
|
||
|
req.clean.size = val;
|
||
|
}
|
||
|
delete req.clean.querySize;
|
||
|
}
|
||
|
|
||
9 years ago
|
test('size=0', function (t) {
|
||
7 years ago
|
setupQuery(0);
|
||
7 years ago
|
const calcSize = calcSizeMiddleware();
|
||
9 years ago
|
calcSize(req, {}, function () {
|
||
8 years ago
|
t.equal(req.clean.querySize, 20);
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
9 years ago
|
});
|
||
|
|
||
|
test('size=1', function (t) {
|
||
7 years ago
|
setupQuery(1);
|
||
7 years ago
|
const calcSize = calcSizeMiddleware();
|
||
9 years ago
|
calcSize(req, {}, function () {
|
||
8 years ago
|
t.equal(req.clean.querySize, 20);
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
9 years ago
|
});
|
||
|
|
||
|
test('size=10', function (t) {
|
||
7 years ago
|
setupQuery(10);
|
||
7 years ago
|
const calcSize = calcSizeMiddleware();
|
||
9 years ago
|
calcSize(req, {}, function () {
|
||
|
t.equal(req.clean.querySize, 20);
|
||
|
t.end();
|
||
|
});
|
||
|
});
|
||
|
|
||
8 years ago
|
test('size=20', function (t) {
|
||
7 years ago
|
setupQuery(20);
|
||
7 years ago
|
const calcSize = calcSizeMiddleware();
|
||
8 years ago
|
calcSize(req, {}, function () {
|
||
|
t.equal(req.clean.querySize, 40);
|
||
|
t.end();
|
||
|
});
|
||
|
});
|
||
|
|
||
9 years ago
|
test('no size', function (t) {
|
||
7 years ago
|
setupQuery();
|
||
7 years ago
|
const calcSize = calcSizeMiddleware();
|
||
9 years ago
|
calcSize(req, {}, function () {
|
||
|
t.equal(req.clean.hasOwnProperty('querySize'), false);
|
||
|
t.end();
|
||
|
});
|
||
9 years ago
|
});
|
||
7 years ago
|
|
||
|
test('no size, min query size 10', function (t) {
|
||
7 years ago
|
setupQuery();
|
||
7 years ago
|
const calcSize = calcSizeMiddleware(10);
|
||
|
calcSize(req, {}, function () {
|
||
|
t.equal(req.clean.hasOwnProperty('querySize'), false);
|
||
|
t.end();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('size 5, min query size 10', function (t) {
|
||
7 years ago
|
setupQuery(5);
|
||
7 years ago
|
const calcSize = calcSizeMiddleware(10);
|
||
|
calcSize(req, {}, function () {
|
||
|
t.equal(req.clean.querySize, 10);
|
||
|
t.end();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('size 3, min query size 2', function (t) {
|
||
7 years ago
|
setupQuery(3);
|
||
7 years ago
|
const calcSize = calcSizeMiddleware(2);
|
||
|
calcSize(req, {}, function () {
|
||
|
t.equal(req.clean.querySize, 6);
|
||
|
t.end();
|
||
|
});
|
||
|
});
|
||
9 years ago
|
};
|
||
|
|
||
|
module.exports.all = function (tape, common) {
|
||
|
|
||
|
function test(name, testFunction) {
|
||
|
return tape('sizeCalculator: ' + name, testFunction);
|
||
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|