couchdb-change-events
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "couchdb-change-events", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "This library will emit changes done in couchdb.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -82,3 +82,4 @@ const proxyquire = require('proxyquire').noCallThru(), | ||
db: 'my_database', | ||
lastEventId: '127-eb534549c61b48f28c753ea95c64f02b' | ||
lastEventId: '127-eb534549c61b48f28c753ea95c64f02b', | ||
autoConnect: false | ||
}); | ||
@@ -187,3 +188,4 @@ | ||
changeEvents = new CouchdbChangeEvents({ | ||
db: 'my_database' | ||
db: 'my_database', | ||
autoConnect: false | ||
}); | ||
@@ -309,2 +311,104 @@ | ||
}); | ||
describe('.onCouchdbChange()', () => { | ||
let changeEvents; | ||
beforeEach(() => { | ||
changeEvents = new CouchdbChangeEvents({ | ||
db: 'my_database', | ||
autoConnect: false | ||
}); | ||
changeEvents.lastHeartBeat = null; | ||
changeEvents.setCouchdbStatus = sinon.spy(); | ||
changeEvents.emit = sinon.spy(); | ||
}); | ||
it('sets couchdb status to connected, if its not already', () => { | ||
changeEvents.onCouchdbChange(''); | ||
should.equal( | ||
changeEvents.setCouchdbStatus.firstCall.args[0], | ||
'connected' | ||
); | ||
}); | ||
it('updates last heartbeat time', () => { | ||
changeEvents.onCouchdbChange(''); | ||
const timeDelta = new Date().getTime() - changeEvents.lastHeartBeat; | ||
should.equal(timeDelta < 15, true); | ||
should.equal(timeDelta >= 0, true); | ||
}); | ||
it('updates lastEventId, if real change is received', () => { | ||
changeEvents.onCouchdbChange('{"seq": 32}'); | ||
should.equal(changeEvents.lastEventId, 32); | ||
}); | ||
it('emits received event', () => { | ||
changeEvents.onCouchdbChange('{"seq": 32}'); | ||
should.deepEqual(changeEvents.emit.firstCall.args, [ | ||
'data', { seq: 32 } | ||
]); | ||
}); | ||
}); | ||
describe('.emitError()', () => { | ||
let changeEvents; | ||
beforeEach(() => { | ||
changeEvents = new CouchdbChangeEvents({ | ||
db: 'my_database', | ||
autoConnect: false | ||
}); | ||
changeEvents.emit = sinon.spy(); | ||
}); | ||
it('emits error', () => { | ||
changeEvents.emitError('couch-error'); | ||
should.deepEqual(changeEvents.emit.firstCall.args, [ | ||
'couchdb_error', 'couch-error' | ||
]); | ||
}); | ||
}); | ||
describe('.reconnect()', () => { | ||
let changeEvents; | ||
beforeEach(() => { | ||
changeEvents = new CouchdbChangeEvents({ | ||
db: 'my_database', | ||
autoConnect: false | ||
}); | ||
global.setTimeout.reset(); | ||
changeEvents.setCouchdbStatus = sinon.spy(); | ||
}); | ||
it('sets couchdb status to disconnected, if its not already', () => { | ||
changeEvents.reconnect(''); | ||
should.equal( | ||
changeEvents.setCouchdbStatus.firstCall.args[0], | ||
'disconnected' | ||
); | ||
}); | ||
it('tries to reconnect in 1 second', () => { | ||
changeEvents.reconnect(''); | ||
should.equal( | ||
global.setTimeout.firstCall.args[0].name, 'bound connect' | ||
); | ||
should.equal(global.setTimeout.firstCall.args[1], 1000); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16061
442