From 39c6f6eb4743e56c884f30a7efd15269682ba468 Mon Sep 17 00:00:00 2001 From: Alex Vernacchia Date: Tue, 17 Mar 2015 10:53:56 +0000 Subject: [PATCH 1/3] update fuel-auth dep to v1.0.0 --- .jshintrc | 3 ++- package.json | 3 ++- test/specs/function-apiRequest.js | 24 ++++++++++++++---------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.jshintrc b/.jshintrc index 4ea8d4e..d54b268 100644 --- a/.jshintrc +++ b/.jshintrc @@ -23,6 +23,7 @@ "define": true, "describe": true, "it": true, - "expect": true + "expect": true, + "Promise": true } } diff --git a/package.json b/package.json index 2e0e1c9..414f7c3 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,11 @@ "grunt-contrib-jshint": "~0.11.0", "grunt": "~0.4.5", "mocha": "~2.2.1", + "promise": "~6.1.0", "sinon": "~1.13.0" }, "dependencies": { - "fuel-auth": "~0.5.3", + "fuel-auth": "~1.0.0", "lodash": "~3.5.0", "request": "~2.53.0" } diff --git a/test/specs/function-apiRequest.js b/test/specs/function-apiRequest.js index d71fca0..9f5fad3 100644 --- a/test/specs/function-apiRequest.js +++ b/test/specs/function-apiRequest.js @@ -25,12 +25,14 @@ */ var expect = require( 'chai' ).expect; -var sinon = require( 'sinon' ); -var mockServer = require( '../mock-server' ); -var FuelRest = require( '../../lib/fuel-rest' ); var FuelAuth = require( 'fuel-auth' ); +var FuelRest = require( '../../lib/fuel-rest' ); +var mockServer = require( '../mock-server' ); var port = 4550; -var localhost = 'http://127.0.0.1:' + port; +var Promiser = (typeof Promise === 'undefined') ? require('promise') : Promise; +var sinon = require( 'sinon' ); + +var localhost = 'http://127.0.0.1:' + port; describe( 'apiRequest method', function() { 'use strict'; @@ -226,9 +228,10 @@ describe( 'apiRequest method', function() { it( 'should handle an error from the Auth Client', function( done ) { // stubbing response from auth client with no access token - sinon.stub( FuelAuth.prototype, '_requestToken', function( requestOptions, callback ) { - callback( new Error( 'error from auth client' ), null ); - return; + sinon.stub( FuelAuth.prototype, '_requestToken', function() { + return new Promiser(function(resolve, reject) { + reject(new Error( 'error from auth client' )); + }); }); // creating local rest client so we can use stubbed auth function @@ -263,9 +266,10 @@ describe( 'apiRequest method', function() { it( 'should try request again if 401 stating token is invalid', function( done ) { var requestSpy = sinon.spy( FuelRest.prototype, 'apiRequest' ); - sinon.stub( FuelAuth.prototype, '_requestToken', function( requestOptions, callback ) { - callback( null, { accessToken: 'testing', expiresIn: 3600 } ); - return; + sinon.stub( FuelAuth.prototype, '_requestToken', function() { + return new Promiser(function(resolve) { + resolve({ accessToken: 'testing', expiresIn: 3600 }); + }); }); // creating local rest client so we can use stubbed auth function var initOptions = { From 3a565a9de3e6a9c0486cb6956210a7f60759acaa Mon Sep 17 00:00:00 2001 From: Alex Vernacchia Date: Sun, 29 Mar 2015 15:43:45 +0100 Subject: [PATCH 2/3] adding module level header option. Fixes #41 --- lib/fuel-rest.js | 4 ++-- test/specs/general-tests.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/fuel-rest.js b/lib/fuel-rest.js index b41a3ed..585bdfb 100644 --- a/lib/fuel-rest.js +++ b/lib/fuel-rest.js @@ -51,10 +51,10 @@ var FuelRest = function( options ) { this.version = version; // setting up default headers - this.defaultHeaders = { + this.defaultHeaders = _.merge({ 'User-Agent': 'node-fuel/' + this.version , 'Content-Type': 'application/json' - }; + }, options.headers); this.origin = options.origin || options.restEndpoint || 'https://www.exacttargetapis.com'; }; diff --git a/test/specs/general-tests.js b/test/specs/general-tests.js index 83547d9..826f2d9 100644 --- a/test/specs/general-tests.js +++ b/test/specs/general-tests.js @@ -93,6 +93,26 @@ describe( 'General Tests', function() { expect( RestClient.origin ).to.equal( 'https://www.exacttarget.com' ); }); + it('should merge module level headers into default headers', function() { + var options = { + auth: { + clientId: 'testing' + , clientSecret: 'testing' + } + , headers: { + 'test': 1 + } + }; + + // testing default initialization + var RestClient = new FuelRest( options ); + + console.log(RestClient.defaultHeaders); + + + expect(RestClient.defaultHeaders.test).to.equal(1); + }); + it( 'should have apiRequest on prototype', function() { expect( FuelRest.prototype.apiRequest ).to.be.a( 'function' ); }); From 04cb5de5031e4e0c4f346c3edca61d6c2e7b289c Mon Sep 17 00:00:00 2001 From: Alex Vernacchia Date: Sun, 29 Mar 2015 15:46:30 +0100 Subject: [PATCH 3/3] removing extra console.log --- test/specs/general-tests.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/specs/general-tests.js b/test/specs/general-tests.js index 826f2d9..98c9e2f 100644 --- a/test/specs/general-tests.js +++ b/test/specs/general-tests.js @@ -107,9 +107,6 @@ describe( 'General Tests', function() { // testing default initialization var RestClient = new FuelRest( options ); - console.log(RestClient.defaultHeaders); - - expect(RestClient.defaultHeaders.test).to.equal(1); });