Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #126 from braydonf/master
Browse files Browse the repository at this point in the history
Test that contact is updated
  • Loading branch information
braydonf committed Sep 13, 2017
2 parents 660fdac + 2e703d7 commit 169317a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ContactSchema.plugin(SchemaOptions);

ContactSchema.index({lastSeen: 1});
//TODO Enable this index once the indexes have been added
//ContactSchema.index({responseTime: 1, spaceAvailable: 1, lastPublishSent: 1});
//ContactSchema.index({responseTime:1,spaceAvailable:1,lastContractSent:1});

ContactSchema.set('toObject', {
virtuals: true,
Expand Down Expand Up @@ -164,7 +164,7 @@ ContactSchema.statics.recall = function(num, callback) {
};

ContactSchema.statics.updateLastContractSent = function(id, callback) {
this.update({ _id: id}, { lastContractSent: Date.now() }, callback);
this.update({ _id: id}, { $set: { lastContractSent: Date.now() } }, callback);
};

module.exports = function(connection) {
Expand Down
8 changes: 6 additions & 2 deletions test/contact.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,13 @@ describe('Storage/models/Contact', function() {
it('will update the last contract sent time', function(done) {
let clock = sandbox.useFakeTimers();
let nodeID = storj.KeyPair().getNodeID();
let now = Date.now();

Contact.record({
address: '127.0.0.12',
port: 3943,
nodeID: nodeID,
lastSeen: Date.now()
lastSeen: now
}, (err, contact) => {
if (err) {
return done(err);
Expand All @@ -366,8 +367,11 @@ describe('Storage/models/Contact', function() {
return done(err);
}
expect(_contact.lastContractSent).to.equal(1000);
expect(_contact.address).to.equal('127.0.0.12');
expect(_contact.port).to.equal(3943);
expect(_contact.nodeID).to.equal(nodeID);
expect(_contact.lastSeen.getTime()).to.equal(0);
done();

});
});
});
Expand Down

0 comments on commit 169317a

Please sign in to comment.