describe('#createNetwork', () => { it('should merge name correctly into opts', () => { const stub = sinon.stub(landerode, 'createNetwork') .usingPromise(Promise) .resolves(); return landerode.createNet('elthree', {}).then(() => { // for some reason should/expect doesn't work here... stub.calledWith({Name: 'elthree'}); stub.restore(); }); }); it('should throw an error if can\'t create network', () => { const stub = sinon.stub(landerode, 'createNetwork').rejects('Too Many Capes'); return landerode.createNet('hardtimes').should.be.rejectedWith('Too Many Capes') .then(() => { stub.restore(); }); }); });
return metrics.report('escape', {inspecter: 'javier'}) .should.be.fulfilled .then(() => { counter.should.equal(reportable); }) .then(() => axios.create.restore()); }); })); return metrics.report() .then(() => { metrics.log.debug.callCount.should.equal(reportable + 1); }) .should.be.fulfilled .then(() => axios.create.restore()); }); return metrics.report('escape', {freedman: 'valjean'}) .delay(5) .then(() => metrics.report('apprehended', {prisoner: 'valjean'})) .then(() => axios.create.restore()); }); });
sinon.stub(_shell, 'exec').callsFake(fakeExec); return shell.sh(['slip', 'sliding', 'away']) .then(result => { result.should.equal('EXEC: slip sliding away'); }) .then(_shell.exec.restore()) .should.be.fulfilled; }); _.forEach([{mode: 'collect'}, {detached: true}], opts => { return shell.sh(['tupelo', 'honey', 'baby'], opts) .then(result => { result.should.equal('SPAWN: tupelo honey baby'); }) sinon.stub(child, 'spawn').callsFake(fakeSpawn); return shell.sh(['set', 'us', 'up', 'the', 'bomb'], {mode: 'attach'}).should.be.rejected .then(child.spawn.restore()); }); sinon.stub(child, 'spawn').callsFake(fakeSpawn); return shell.sh(['van', 'the', 'man'], {detached: true}).should.be.fulfilled .then(child.spawn.restore()); }); }); return shell.sh(['van', 'the', 'man'], {mode: 'attach'}).should.be.fulfilled .then(child.spawn.restore()) .then(() => {
it('should accept 88.8', (done) => { const rules = { amount: { type: 'float' } }; const params = { amount: 88.8 }; expect(whitelister(rules, params)).to.eventually.be.fulfilled .then((response) => { expect(response).to.be.an('object').that.has.property('amount', 88.8); done(); }); });
it('rejects 5xx HTTP status codes', function () { scope.reply(500, 'Internal Service Error', { 'Content-Type': 'text/plain' }); return http.request({path: 'test'}).should.be.rejected .then( err => err.should.contain({'type': NeverBounce.errors.GeneralError}) ) });
describe('rule: allowNull', () => { const rules = { name: { type: 'string', allowNull: true } }; it('should return an object with property: null', (done) => { expect(whitelister(rules, { name: null })).to.eventually.be.fulfilled .then((response) => { expect(response).to.be.an('object').that.has.property('name', null); done(); }); }); });
it('leaves non JSON responses as is', function () { scope.reply(200, 'Hello World!', { 'Content-Type': 'text/plain' }); return http.request({path: 'test', acceptedType: 'text/plain'}).should.be.fulfilled .then( resp => resp.should.be.a('string').that.is.equal('Hello World!') ) });
it('should accept a valid array of numbers', (done) => { const rules = { digits: 'array' }; const params = { digits: [1, 2, 3] }; expect(whitelister(rules, params)).to.eventually.be.fulfilled .then((response) => { expect(response).to.be.an('object') .that.has.property('digits') .that.is.an('array') .that.has.members([1, 2, 3]); done(); }); });
it('should accept value of "bob@email.com"', (done) => { const rules = { email: 'email' }; const params = { email: 'bob@email.com' }; expect(whitelister(rules, params)).to.eventually.be.fulfilled .then((response) => { expect(response).to.have.property('email', 'bob@email.com'); done(); }); });
it('rejects throttle_triggered statuses', function () { scope.reply(200, {'status': 'throttle_triggered', 'message': 'Too many requrests'}, { 'Content-Type': 'application/json' }); return http.request({path: 'test'}).should.be.rejected .then( err => err.should.contain({'type': NeverBounce.errors.ThrottleError}) ) });
it('rejects poorly formatted JSON', function () { scope.reply(200, '{\'bad_json\'}', { 'Content-Type': 'application/json' }); return http.request({path: 'test'}).should.be.rejected .then( err => err.should.contain({'type': NeverBounce.errors.GeneralError}) ) });
it('rejects temp_unavail statuses', function () { scope.reply(200, {'status': 'temp_unavail', 'message': 'Service has gone away'}, { 'Content-Type': 'application/json' }); return http.request({path: 'test'}).should.be.rejected .then( err => err.should.contain({'type': NeverBounce.errors.GeneralError}) ) });
it('should parse "100" to integer', (done) => { const rules = { user_id: { type: 'integer' } }; const params = { user_id: '100' }; expect(whitelister(rules, params)).to.eventually.be.fulfilled .then((response) => { expect(response).to.be.an('object').that.has.property('user_id', 100); done(); }); });
it('should accept 9999', (done) => { const rules = { user_id: { type: 'integer' } }; const params = { user_id: 9999 }; expect(whitelister(rules, params)).to.eventually.be.fulfilled .then((response) => { expect(response).to.be.an('object').that.has.property('user_id', 9999); done(); }); });
describe('rule: default', () => { it('should return an object with a default value', (done) => { const rules = { per_page: { type: 'integer', default: 20 } }; expect(whitelister(rules, {})).to.eventually.be.fulfilled .then((response) => { expect(response).to.be.an('object').that.has.property('per_page', 20); done(); }); }); });