Commit 9b2e6653 authored by Johannes Bill's avatar Johannes Bill

added Mocha Test

parent 69a3e3d5
......@@ -150,8 +150,13 @@ function wrapper(_epochSpan) {
var days = [];
var cnt = endYear - startYear + 1;
var errRec = false;
function _cb(err, result) {
if (err) return cb(err);
if (errRec) return;
if (err){
errRec = true;
return cb(err);
}
days = days.concat(result);
cnt--;
......
......@@ -26,7 +26,7 @@
"default": ["106", "1", "111"]
},
"BY": {
"default": ["106", "1", "815", "111"],
"default": ["106", "1", "111"],
"kath": ["815"],
"augsburg": ["808"]
},
......
......@@ -26,19 +26,21 @@ var variableOffsets = {
602: 50
};
var holidayToSpecificMap = (function() {
var holidayToSpecificMap = (function () {
var regionH = holidayMapping["region"];
var hMap = {};
for(var rKey in regionH) {
for (var rKey in regionH) {
var rH = regionH[rKey];
for(var cKey in rH) {
for (var cKey in rH) {
var hArray = rH[cKey];
for (var i = 0; i < hArray.length; i++) {
var hd = hArray[i];
if(!hMap[hd])
if (!hMap[hd])
hMap[hd] = [];
if(cKey == "default") hMap[hd].region.push(rKey);
else hMap[hd].special.push(cKey);
hMap[hd].push({
region: rKey,
category: cKey
});
}
}
}
......@@ -83,20 +85,20 @@ function Holidays(year) {
return !!(86150 <= plz && plz <= 86199);
}
function getRegionOptions(plz, epochSpan, cb) {
function getRegionOptions(plz, keys, cb) {
var blnd;
var options = {
isKath: false,
isAugsburg: false
};
restRequest.getBundesland(plz, function(err, result) {
if(err) return cb(err);
restRequest.getBundesland(plz, function (err, result) {
if (err) return cb(err);
blnd = result;
options.blnd = blnd;
if(blnd == "BY") {
if (blnd == "BY") {
options.isAugsburg = getIsAugsburg(plz);
restRequest.getKatholisch(plz, function(err1, isKath) {
if(err1) return cb(err1);
restRequest.getKatholisch(plz, function (err1, isKath) {
if (err1) return cb(err1);
options.isKath = isKath;
cb(null, options);
})
......@@ -107,22 +109,27 @@ function Holidays(year) {
});
}
function isInEpochSpan(date, epochSpan) {
var dateTime = date.getTime();
return epochSpan[0].getTime() <= dateTime && dateTime <= epochSpan[1].getTime()
}
function getRelevantHolidayKeys(epochSpan) {
return Object.keys(holidays).filter(function (key) {
return isInEpochSpan(holidays[key], epochSpan);
});
}
function getHolidayKeys(plz, epochSpan, cb) {
if(plz == 0) {
var keys = Object.keys(holidays);
return cb(null, keys);
var initKeys = getRelevantHolidayKeys(epochSpan);
if (plz == 0) {
return cb(null, initKeys);
}
getRegionOptions(plz, epochSpan, function(err, options) {
getRegionOptions(plz, initKeys, function (err, options) {
console.log(options);
if(err) return cb(err);
if (err) return cb(err);
var blnd = options.blnd;
var isAugsburg = options.isAugsburg;
var isKath = options.isKath;
......@@ -140,10 +147,27 @@ function Holidays(year) {
})
}
function blndGetter(plz) {
var blnd;
var errRec;
function getBlnd(cb) {
if(errRec) return cb(errRec);
if(blnd) return cb(null, blnd);
restRequest.getBundesland(plz, function(err, result) {
if(err) {
errRec = err;
return cb(err);
}
cb(null, result);
})
}
return getBlnd;
}
this.getAllHolidays = function (plz, epochSpan, cb) {
getHolidayKeys(plz, epochSpan, function (err, keys) {
if(err)
if (err)
return cb(err);
var result = [];
for (var i = 0; i < keys.length; i++) {
......@@ -164,4 +188,6 @@ function Holidays(year) {
};
}
module.exports = Holidays;
\ No newline at end of file
module.exports = Holidays;
var hds = new Holidays(2014);
......@@ -7,7 +7,6 @@ var now = new Date(2014, 4, 1);
dateArray(dateView.getPropperEpochSpan(now)).getData(require('../mochaTests/testData/testHof.json'), 0, function(err, data) {
console.log(data);
var view = dateView.getView(data, now, 93047);
fs.writeFile(process.env["HOME"] + '/Desktop/bla.html', view, function (err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment