it('should return an events instance with correct default options', () => { const events = new AsyncEvents(); events.should.be.instanceof(AsyncEvents); events.should.be.an('object').with.property('log'); events.should.have.property('_maxListeners', 64); events._listeners.should.be.an('array').and.be.empty; events.should.have.property('_eventsCount', 0); }); const log = sinon.spy(); const events = new AsyncEvents(log); events.should.have.property('log', log); }); }); .filter(event => event.priority === 5) .size(); priorityFiveEvents.should.equal(2); }); events.on('event', 6, after); events.emit('event').then(() => { before.should.be.calledBefore(middle); middle.should.be.calledBefore(after); after.should.be.calledAfter(middle); }); }); it('should return a promise', () => {
describe('.pause()', function () { it('sends cmd', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.playbackControls.pause() sendCmd.should.have.been.calledWithExactly(3, 0, 0) }) })
it('should NOT try to update any timestamp properties if `options.timestamps` option is disabled', function() { var instance = this.model.build({}); var propNames = this.model._getTimestampPropertyNames(); var getTimestampNamesSpy = sinon.spy(this.model, '_getTimestampPropertyNames'); instance._touchTimestamps(); instance.getData().should.not.have.property(propNames.createdAt); instance.getData().should.not.have.property(propNames.updatedAt); instance.getData().should.not.have.property(propNames.deletedAt); getTimestampNamesSpy.should.have.callCount(0); getTimestampNamesSpy.restore(); });
it('should NOT call the `getAndLock` method if the `lockTime` option is set AND the relevant document IS soft-deleted', function() { const getAndLockSpy = sinon.spy(this.model.storage, 'getAndLock'); return this.model.getByIdOrFail(this.doc.getKey(), {lockTime: 20}) .should.be.rejected.then(function() { getAndLockSpy.should.have.callCount(0); getAndLockSpy.restore(); }); });
it('should call `touchTimestamps` method before removal', function() { var self = this; this.removeStub.returns(Promise.resolve({cas: '72286253696174100', token: undefined})); this.insertStub.returns(Promise.resolve({cas: '12343895749571342', token: undefined})); var touchTimestampsSpy = sinon.spy(this.user, '_touchTimestamps'); this.removeStub.withArgs(this.user.getKey()); var promise = this.user.destroy(); return promise.should.be.fulfilled.then(function(result) { touchTimestampsSpy.should.have.been.calledBefore( self.removeStub.withArgs(self.user.getKey()) ); touchTimestampsSpy.restore(); }); });
describe('.execCmd(msg, [arg1, arg2, arg3])', function () { it('sends arbitrary broadcast message', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.execCmd(12, 13, 14, 15) sendCmd.should.have.been.calledWithExactly(12, 13, 14, 15) }) })
describe('.rewind([speed])', function () { it('sends cmd', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.playbackControls.rewind() sendCmd.should.have.been.calledWithExactly(3, -2, 0) }) it('passes optional argument', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.playbackControls.rewind(16) sendCmd.should.have.been.calledWithExactly(3, -16, 0) }) })
describe('.setState(state)', function () { it('sends state cmd', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.camControls.setState(15) sendCmd.should.have.been.calledWithExactly(2, 15) }) })
describe('.reloadTextures()', function () { it('sends reload all command', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.reloadTextures() sendCmd.should.have.been.calledWithExactly(7, 0) }) })
describe('.slowBackward([divider])', function () { it('sends cmd', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.playbackControls.slowBackward() sendCmd.should.have.been.calledWithExactly(3, -1, 1) }) it('passes optional argument', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.playbackControls.slowBackward(16) sendCmd.should.have.been.calledWithExactly(3, -15, 1) }) })
describe('.reloadTexture(carIdx)', function () { it('sends reload car command', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.reloadTexture(13) sendCmd.should.have.been.calledWithExactly(7, 1, 13) }) })
describe('.searchTs(sessionNum, sessionTimeMS)', function () { it('sends cmd with args', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.playbackControls.searchTs(1, 5000) sendCmd.should.have.been.calledWithExactly(12, 1, 5000) }) })
describe('.execChatMacro(num)', function () { it('sends chat macro command', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.execChatMacro(7) sendCmd.should.have.been.calledWithExactly(8, 0, 7) }) })
describe('.play()', function () { it('sends cmd', function () { var mock = Object.create(IrSdkWrapper) var sendCmd = sinon.spy(mock, 'sendCmd') var iracing = new JsIrSdk(mock) iracing.playbackControls.play() sendCmd.should.have.been.calledWithExactly(3, 1, 0) }) })
it('should NOT call the `getAndTouch` method if the `expiry` option is set AND the relevant document IS soft-deleted', function() { const getAndTouchSpy = sinon.spy(this.model.storage, 'getAndTouch'); return this.model.getByIdOrFail(this.doc.getKey(), {expiry: 1000}) .should.be.rejected.then(function() { getAndTouchSpy.should.have.callCount(0); getAndTouchSpy.restore(); }); });