Skip to content

Commit

Permalink
Merge 7fdad3b into a0330fb
Browse files Browse the repository at this point in the history
  • Loading branch information
itayw committed Aug 10, 2014
2 parents a0330fb + 7fdad3b commit 3f8dc49
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
8 changes: 6 additions & 2 deletions lib/dispatch/beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ etl.verify = function (context, workspace, collection, documents, callback) {
if (documents.length > 0)
_document = ce.clone(documents[0]);

if (!_document.timestamp)
//console.log('doc', _document);

if (!_document.timestamp) {
console.log('generating timestamp');
_document.timestamp = new Date();
}

joola.dispatch.collections.metadata(context, workspace, null, _document, function (err, meta) {
/* istanbul ignore if */
Expand Down Expand Up @@ -116,7 +120,7 @@ etl.load = function (context, workspace, collection, documents, options, callbac

_collection.meta = meta;
_collection.storeKey = workspace + '_' + collection;

joola.datastore.providers.default.insert(_collection, ce.clone(documents), options, function (err, _documents) {
if (err) {
return setImmediate(function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"humanize-number": "0.0.2",
"jade": "*",
"joola.cli": "^0.1.0",
"joola.datastore-mongodb": "^0.0.6",
"joola.datastore-influxdb": "^0.0.5",
"joola.datastore-mongodb": "^0.0.5",
"joola.sdk": "^0.7.0",
"js-yaml": "~3.0.2",
"json-stringify-safe": "^5.0.0",
Expand Down
38 changes: 38 additions & 0 deletions test/fixtures/basic-timestamps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"bets": 1,
"player": "7890",
"game": "LOO",
"return": 1.1,
"currency": 87,
"operator": 81,
"timestamp": "2013-10-20T09:09:54.827Z",
"stake": 123.0,
"win": true,
"gameround_id": "1234"
},
{
"bets": 1,
"player": "7890",
"game": "LOO",
"return": 1.1,
"currency": 87,
"operator": 81,
"timestamp": "2013-10-20T10:09:54.827Z",
"stake": 123.0,
"win": true,
"gameround_id": "1235"
},
{
"bets": 1,
"player": "8384",
"game": "LOO",
"return": 0.0,
"currency": 92,
"operator": 81,
"timestamp": "2013-10-20T11:09:54.827Z",
"stake": 184.0,
"win": false,
"gameround_id": "1236"
}
]
24 changes: 18 additions & 6 deletions test/unit/6_beacon/beacon-basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,29 @@ describe("beacon-basic", function () {
it("should load array of documents", function (done) {
var self = this;
var docs = ce.clone(self.documents);
var counter = 0;
docs.forEach(function (d) {
d.timestamp = new Date();
d.timestamp.setMilliseconds(d.timestamp.getMilliseconds() - counter);
counter++;
engine.beacon.insert(self.context, self.context.user.workspace, self.collection, docs, function (err, docs) {
if (err)
return done(err);

docs.forEach(function (d, index) {
expect(d.saved).to.equal(true);
});
done();
});
});

it("should load array of documents and verify timestamp", function (done) {
var self = this;
var docs = require('../../fixtures/basic-timestamps.json');
engine.beacon.insert(self.context, self.context.user.workspace, self.collection, docs, function (err, docs) {
if (err)
return done(err);

docs.forEach(function (d) {
docs.forEach(function (d, index) {
expect(d.timestamp === docs[index].timestamp);
var shorttimestamp = new Date(d.timestamp);
shorttimestamp.setMilliseconds(0);
expect(d.timestamp_timebucket.second.getTime()).to.equal(shorttimestamp.getTime());
expect(d.saved).to.equal(true);
});
done();
Expand Down

0 comments on commit 3f8dc49

Please sign in to comment.