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

added Mocha Test

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