Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #42 from vernak2539/module-level-headers
Browse files Browse the repository at this point in the history
Module level headers
  • Loading branch information
vernak2539 committed Mar 29, 2015
2 parents 2081612 + 04cb5de commit d5381e5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"define": true,
"describe": true,
"it": true,
"expect": true
"expect": true,
"Promise": true
}
}
4 changes: 2 additions & 2 deletions lib/fuel-rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
24 changes: 14 additions & 10 deletions test/specs/function-apiRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
17 changes: 17 additions & 0 deletions test/specs/general-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ 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 );

expect(RestClient.defaultHeaders.test).to.equal(1);
});

it( 'should have apiRequest on prototype', function() {
expect( FuelRest.prototype.apiRequest ).to.be.a( 'function' );
});
Expand Down

0 comments on commit d5381e5

Please sign in to comment.