describe('functions_bearer_token', () => { it('should run', async () => { const {sample, mocks} = getSample(); await sample.callingFunction(null, mocks.res); assert(mocks.axios.get.calledTwice); assert.deepEqual(mocks.axios.get.firstCall.args[1], { headers: {'Metadata-Flavor': 'Google'}, }); assert(mocks.res.send.calledWith('function-response')); }); });
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(); }); }); });
if (err) return done(err) if (!addToQueue.calledWith({ url: 'https://google.com', meta: meta })) { throw new Error('Queue was not called with correct url')
'configs were merged' ); assert.ok(bsConfigMock.calledWith(bs), 'browsersync passed into bsconfig fn'); }); });
if (!createClientStub.calledOnce || !createClientStub.calledWith(expectedOptions)) { throw new Error('Client was not created with correct options') if (!uploadFileStub.calledOnce || !uploadFileStub.calledWith(expectedOptions)) { throw new Error('uploadFile was not called with correct options') if (!path.calledOnce || !path.calledWith('path', job)) { throw new Error('Path function was not called')
it('should log warn', () => { logger.set('w') const s = sinon.stub() logger.listen(s) logger('test').w('test') expect(s.calledWith('w', 'test', 'test')).equals(true) })
test('publish publishes message to provided queue', function(done) { var stubs = build(); var ex = queue.create(stubs.chFactory) .configure('myQueue', {}) .publish({Hello:'World'}) .then(function() { assert(stubs.ch.sendToQueue.calledWith('myQueue')) var msg = JSON.parse(stubs.ch.sendToQueue.args[0][1].toString()); assert.equal(msg.Hello, 'World'); done(); }); });
it('should make async HTTP request', () => { const sample = getSample(); sample.program.helloAsync(); assert.strictEqual( sample.mocks.nodeFetch.calledWith('https://www.example.com'), true ); });
it('throws error if current directory is not writable', function () { const accessStub = sinon.stub(fs, 'access').rejects(); const installFolderPermissions = require(modulePath).task; return installFolderPermissions({}).then(() => { expect(false, 'error should have been thrown').to.be.true; }).catch((error) => { expect(error).to.be.an.instanceof(errors.SystemError); expect(error.message).to.match(/is not writable by your user/); expect(accessStub.calledOnce).to.be.true; expect(accessStub.calledWith(process.cwd())).to.be.true; }); });
it('should receive a call', () => { const {supertest, mocks} = getSample(); return supertest .post('/call/receive') .send() .expect(200) .expect(() => { assert(mocks.twilio.say.calledWith('Hello from Google App Engine.')); }); });
it('should receive an SMS message', () => { const {supertest, mocks} = getSample(); return supertest .post('/sms/receive') .send({From: 'Bob', Body: 'hi'}) .type('form') .expect(200) .expect(() => { assert(mocks.twilio.message.calledWith('Hello, Bob, you said: hi')); }); });
it('should log trace', () => { logger.set('t') const s = sinon.stub() logger.listen(s) logger('test').t('test') expect(s.calledWith('t', 'test', 'test')).equals(true) })
it('should log error', () => { logger.set('e') const s = sinon.stub() logger.listen(s) logger('test').e('test') expect(s.calledWith('e', 'test', 'test')).equals(true) })
it('should log info', () => { logger.set('i') const s = sinon.stub() logger.listen(s) logger('test').i('test') expect(s.calledWith('i', 'test', 'test')).equals(true) })
it('should log debug', () => { logger.set('d') const s = sinon.stub() logger.listen(s) logger('test').d('test') expect(s.calledWith('d', 'test', 'test')).equals(true) })