Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Reports can now be genereated
Browse files Browse the repository at this point in the history
  • Loading branch information
dwnz committed Oct 6, 2014
1 parent 85727d9 commit 90ec9e1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,31 @@ engine.generateReport = function (dataDriver, startDate, endDate, callback) {
}

if (data === null) {
for (var i = 0; i < daysToLoop; i++) {
for (var x = 0; x < daysToLoop; x++) {
result.push(0);
}

callback(null, result);
return;
}


for (var i = 0; i < daysToLoop; i++) {
var loopDate = moment(startDate).add(i, 'day').toDate();

var dayData = data.filter(function (value, i) {
return value.date === moment(startDate);
return value.date.getTime() === loopDate.getTime();
});

if (dayData === null || dayData.length === 0) {
result.push(0);
if (dayData === null || dayData === undefined || dayData.length === 0) {
result.push({
date: loopDate,
value: 0
});
} else {
result.push({
date: loopDate,
value: dayData[0].value
});
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/basicEngineTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,28 @@ exports.checkThatDataDriverErrorGetsSent = function (test) {
test.equal(null, data);
test.done();
});
};


exports.checkThatOneDayOfDataIsReturned = function (test) {
var startDate = new Date(2014, 9, 1);
var endDate = new Date(2014, 9, 2);
var testEngine = {
getData: function (startDate, endDate, callback) {
callback(
null,
[
{date: new Date(2014, 9, 1), value: 10}
]
);
}
};

engine.generateReport(testEngine, startDate, endDate, function (err, data) {
test.ok(data);
test.equal(1, data.length);
test.equal(new Date(2014, 9, 1).getTime(), data[0].date.getTime());
test.equal(10, data[0].value);
test.done();
});
};

0 comments on commit 90ec9e1

Please sign in to comment.