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')); }); });
test('#initConnection :: add event hooks', t => { const connection = { on: stub(), write: stub() } const err = { on: stub() } p2p.initConnection(connection) t.deepEqual(p2p.peers, [connection]) t.is(connection.on.callCount, 2) t.is(connection.on.firstCall.args[0], 'data') t.is(connection.on.secondCall.args[0], 'error') })
test('#initConnection :: write event', t => { const connection = { on: stub(), write: stub() } const payload = JSON.stringify(messages.getQueryChainLengthMsg()) p2p.initConnection(connection) t.is(connection.write.callCount, 1) t.is(connection.write.firstCall.args[0], payload) })
it('Calls "end" if no events', async () => { const sample = getSample(); const mocks = getMocks(); mocks.req.method = method; mocks.req.headers.authorization = auth; mocks.req.body = undefined; await sample.program.sendgridWebhook(mocks.req, mocks.res); assert.strictEqual(mocks.res.end.callCount, 1); assert.deepStrictEqual(mocks.res.end.firstCall.args, []); });
it("should by default send an `accept` application/json header", () => { const client = new ServiceClient(clientOptions); return client.request().then(() => { assert.equal( requestStub.firstCall.args[0].headers.accept, "application/json" ); }); });
it('http:helloContent: should handle application/x-www-form-urlencoded', () => { const mocks = getMocks(); const httpSample = getSample(); mocks.req.headers['content-type'] = 'application/x-www-form-urlencoded'; mocks.req.body = {name: 'John'}; httpSample.sample.helloContent(mocks.req, mocks.res); assert.strictEqual(mocks.res.status.calledOnce, true); assert.strictEqual(mocks.res.status.firstCall.args[0], 200); assert.strictEqual(mocks.res.send.calledOnce, true); assert.strictEqual(mocks.res.send.firstCall.args[0], 'Hello John!'); });
it('outputs message to proper stream', function () { const stdout = {write: sinon.stub()}; const stderr = {write: sinon.stub()}; const ui = new UI({stdout: stdout, stderr: stderr}); ui.log('Error', null, true); ui.log('Good', null, false); expect(stdout.write.calledOnce).to.be.true; expect(stderr.write.calledOnce).to.be.true; expect(stderr.write.firstCall.args[0]).to.equal('Error\n'); expect(stdout.write.firstCall.args[0]).to.equal('Good\n'); });
it('should make a promise request', async () => { const sample = getSample(); const data = { endpoint: 'foo.com', }; const result = await sample.program.helloPromise(data); assert.deepStrictEqual(sample.mocks.nodeFetch.firstCall.args, ['foo.com']); assert.strictEqual(result, 'test'); });
it('should handle list error', () => { const error = new Error('error'); const sample = getSample(); const callback = sinon.stub(); sample.mocks.storagetransfer.transferOperations.list.yields(error); sample.program.listTransferOperations(undefined, callback); assert.strictEqual(callback.calledOnce, true); assert.deepStrictEqual(callback.firstCall.args, [error]); });
it('should handle auth error', () => { const error = new Error('error'); const sample = getSample(); const callback = sinon.stub(); sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.getTransferJob(jobName, callback); assert.strictEqual(callback.calledOnce, true); assert.deepStrictEqual(callback.firstCall.args, [error]); });
it('helloHttp: should print hello world', () => { // Mock ExpressJS 'req' and 'res' parameters const req = { body: {}, }; const res = {send: sinon.stub()}; // Call tested function helloHttp(req, res); // Verify behavior of tested function assert.ok(res.send.calledOnce); assert.deepStrictEqual(res.send.firstCall.args, ['Hello World!']); });
it('should handle pause error', () => { const error = new Error('error'); const sample = getSample(); const callback = sinon.stub(); sample.mocks.storagetransfer.transferOperations.pause.yields(error); sample.program.pauseTransferOperation(jobName, callback); assert.strictEqual(callback.calledOnce, true); assert.deepStrictEqual(callback.firstCall.args, [error]); });
it('should handle auth error', () => { const error = new Error('error'); const sample = getSample(); const callback = sinon.stub(); sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.listTransferOperations(undefined, callback); assert.strictEqual(callback.calledOnce, true); assert.deepStrictEqual(callback.firstCall.args, [error]); });
it('should handle auth error', () => { const error = new Error('error'); const sample = getSample(); const callback = sinon.stub(); sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.getTransferOperation(jobName, callback); assert.strictEqual(callback.calledOnce, true); assert.deepStrictEqual(callback.firstCall.args, [error]); });