it('should be ticking with argument given the constructor', function () { var task = this.sandbox.spy() var timer = new Timer(task, 1) var clock = this.sandbox.useFakeTimers() timer.start() clock.tick(3) timer.end() clock.restore() expect(task).to.have.been.calledThrice })
describe('#close()', function() { it('should call redisClient.quit thrice', function() { redlock.close(); expect(clientStub.quit).to.have.been.calledThrice; }); });
it('should mount the info route on the default endpoint', function () { actuator() expect(router.get).to.have.been.calledThrice() expect(router.get).to.have.been.calledWithExactly('/info', new Info().route) })
it('should update status to shipped', () => { o.ship(); expect(o.status).to.equal('Shipped'); expect(dateSpy).to.have.been.calledThrice; });
it('should register `Model`s schema difinition with Ajv validator', function() { const model = this.buildModel('Test3', { type: 'object' }, {}); const stub = sinon.stub(ODM.Model.validator, 'addSchema'); model._init(this.modelManager); stub.should.have.been.calledThrice; stub.getCall(0).should.have.been.calledWith(model.options.schema, model.name); stub.restore();//important! });
it('should update status to active and return order details', () => { let result = o.save(); expect(dateSpy).to.have.been.calledThrice; expect(o.status).to.equal('Active'); expect(result).to.be.a('Object'); expect(result).to.have.property('ref').to.equal(123); expect(result).to.have.property('user').to.equal('foo'); expect(result).to.have.property('updatedAt').to.be.a('Number'); expect(result).to.have.property('status').to.equal('Active'); expect(result).to.have.property('shipping').to.equal(5); expect(result).to.have.property('total').to.equal(20); expect(result).to.have.property('items').to.be.a('Array'); });
it("Creates three Layers when state is not-defined. (the same, but with big net)", () => { const netThis = {state: "not-defined", joinLayer: net.joinLayer, layers: [], activation: NetMath.sigmoid} net.initLayers.bind(netThis, 784, 10)() expect(netThis.state).to.equal("initialised") expect(net.joinLayer).to.have.been.calledThrice expect(netThis.layers.map(layer => layer.size)).to.deep.equal([784, 204, 10]) })
it('shouldn\'t be restartable with start', function () { var task = this.sandbox.spy() var anotherTask = this.sandbox.spy() var timer = new Timer() var clock = this.sandbox.useFakeTimers() timer.task = task timer.start(1) clock.tick(1) timer.task = anotherTask timer.start() clock.tick(1) clock.tick(1) timer.end() clock.restore() expect(task).to.have.been.calledThrice expect(anotherTask).to.not.have.been.called })
describe('constructor', function() { it('should call redis.createClient thrice', function() { expect(redisStub).to.have.been.calledThrice; }); it('should emit connect', function(done) { redlock.on('connect', done); clientStub.emit('ready'); }); it('should emit disconnect if all servers go down', function(done) { redlock.on('disconnect', done); clientStub.emit('ready'); clientStub.emit('end'); }); });
describe('#lock()', function() { it('should call redisClient.set thrice', function() { redlock.lock('test', 1000, function() { expect(clientStub.set).to.have.been.calledThrice; }); });
it('should cancel an order, update status and set shipping and total to zero', () => { let result = o.cancel(); expect(warnStub).to.have.been.calledWith('Order cancelled'); expect(dateSpy).to.have.been.calledThrice; expect(o.status).to.equal('Cancelled'); expect(result).to.be.true; expect(o.shipping).to.equal(0); expect(o.total).to.equal(0); });
it("Creates three Layers when state is not-defined. First and last layer sizes respective to input/output, middle is in-between", () => { const netThis = {state: "not-defined", joinLayer: net.joinLayer, layers: [], activation: NetMath.sigmoid} net.initLayers.bind(netThis, 3, 2)() expect(netThis.state).to.equal("initialised") expect(netThis.layers.map(layer => layer.size)).to.deep.equal([3, 5, 2]) expect(net.joinLayer).to.have.been.calledThrice })
describe('#unlock()', function() { it('should call redisClient.eval thrice', function() { redlock.unlock('test', 'value', function() {}); expect(clientStub.eval).to.have.been.calledThrice; }); });
it('should be ticking with the argument given to the start method', function () { var task = this.sandbox.spy() var timer = new Timer(task) var clock = this.sandbox.useFakeTimers() timer.start(1) clock.tick(3) timer.end() clock.restore() expect(task).to.have.been.calledThrice })
it('should mount the info route on the given endpoint', function () { actuator('/foobar') expect(router.get).to.have.been.calledThrice() expect(router.get).to.have.been.calledWithExactly('/foobar/info', new Info().route) })