Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "rest", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "./rest.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
{ | ||
"name": "rest", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "RESTful HTTP client library", | ||
@@ -5,0 +5,0 @@ "keywords": ["rest", "http", "client", "rest-template", "spring", "cujojs"], |
@@ -232,2 +232,5 @@ rest.js | ||
1.0.2 | ||
- restore client.chain() to the default client | ||
1.0.1 | ||
@@ -234,0 +237,0 @@ - handle exceptions thrown from MIME converters |
12
rest.js
@@ -81,2 +81,14 @@ /* | ||
/** | ||
* Applies the interceptor behavior to the default client, resulting in | ||
* a new client | ||
* @param {Inteceptor} interceptor the interceptor behavior to apply to | ||
* the default client | ||
* @param {*} [config] optional configuration for the interceptor | ||
* @returns {Client} the newly wrapped client | ||
*/ | ||
defaultClient.chain = function chain(interceptor, config) { | ||
return interceptor(defaultClient, config); | ||
}; | ||
/** | ||
* Change the default client | ||
@@ -83,0 +95,0 @@ * @param {Client} client the new default client |
@@ -18,9 +18,18 @@ /* | ||
var rest = require('rest'); | ||
var rest = require('rest'), | ||
interceptor = require('rest/interceptor'); | ||
function client(request) { | ||
function stubClient(request) { | ||
return { request: request }; | ||
} | ||
var stubInterceptor = interceptor(); | ||
buster.testCase('rest', { | ||
setUp: function () { | ||
rest.resetDefaultClient(); | ||
}, | ||
tearDown: function () { | ||
rest.resetDefaultClient(); | ||
}, | ||
'should return a client by default': function () { | ||
@@ -30,10 +39,18 @@ assert.equals('function', typeof rest.getDefaultClient()); | ||
'should use the provided client as a default': function () { | ||
rest.setDefaultClient(client); | ||
assert.same(client, rest.getDefaultClient()); | ||
rest.setDefaultClient(stubClient); | ||
assert.same(stubClient, rest.getDefaultClient()); | ||
assert.equals('request', rest('request').request); | ||
}, | ||
'should restore the platform default client': function () { | ||
rest.setDefaultClient(client); | ||
var client = rest.getDefaultClient(); | ||
rest.setDefaultClient(stubClient); | ||
refute.same(client, rest.getDefaultClient()); | ||
rest.resetDefaultClient(); | ||
refute.same(client, rest.getDefaultClient()); | ||
assert.same(client, rest.getDefaultClient()); | ||
}, | ||
'should chain off the default client, using the lastest default client': function () { | ||
var client = rest.chain(stubInterceptor); | ||
rest.setDefaultClient(stubClient); | ||
refute.same(client, stubClient); | ||
assert.equals('request', rest('request').request); | ||
} | ||
@@ -40,0 +57,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
375904
8062
317