@trayio/threadneedle
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -16,5 +16,5 @@ /* | ||
.then(function () { | ||
if (_.isFunction(threadneedle._globalOptions.afterFailure) && config.globals !== false) { | ||
return when(threadneedle._globalOptions.afterFailure(body, params)); | ||
} | ||
if (_.isFunction(threadneedle._globalOptions.afterFailure) && !require('./localOnly')(config, 'afterFailure')) { | ||
return when(threadneedle._globalOptions.afterFailure(body, params)); | ||
} | ||
}) | ||
@@ -21,0 +21,0 @@ |
@@ -16,5 +16,5 @@ /* | ||
.then(function () { | ||
if (_.isFunction(threadneedle._globalOptions.afterSuccess) && config.globals !== false) { | ||
if (_.isFunction(threadneedle._globalOptions.afterSuccess) && !require('./localOnly')(config, 'afterSuccess')) { | ||
return when(threadneedle._globalOptions.afterSuccess(body, params, res)); | ||
} | ||
} | ||
}) | ||
@@ -21,0 +21,0 @@ |
@@ -14,3 +14,3 @@ /* | ||
var subbedUrl = substitute(config.url, params); | ||
// Add the URL | ||
@@ -20,3 +20,3 @@ if (_.isString(subbedGlobalUrl) && | ||
!startsWith(subbedUrl, 'https://') && | ||
config.globals !== false) { | ||
!require('./localOnly')(config, 'baseUrl')) { | ||
return subbedGlobalUrl + subbedUrl; | ||
@@ -23,0 +23,0 @@ } |
/* | ||
* Run the global `before` method, and then the local method. | ||
* | ||
* | ||
* Note that this is most often used to set/update parameters in the `params` | ||
* object - need to ensure that variables are passed and saved correctly in the | ||
* object - need to ensure that variables are passed and saved correctly in the | ||
* tests pre substitution. | ||
@@ -20,5 +20,5 @@ */ | ||
.then(function () { | ||
if (_.isFunction(threadneedle._globalOptions.before) && config.globals !== false) { | ||
if (_.isFunction(threadneedle._globalOptions.before) && !require('./localOnly')(config, 'before')) { | ||
return when(threadneedle._globalOptions.before(params)); | ||
} | ||
} | ||
}) | ||
@@ -40,2 +40,2 @@ | ||
}); | ||
}; | ||
}; |
@@ -16,3 +16,3 @@ /* | ||
.then(function () { | ||
if (_.isFunction(threadneedle._globalOptions.beforeRequest)) { | ||
if (_.isFunction(threadneedle._globalOptions.beforeRequest) && !require('./localOnly')(config, 'beforeRequest')) { | ||
return when(threadneedle._globalOptions.beforeRequest(request, params)); | ||
@@ -19,0 +19,0 @@ } |
@@ -16,3 +16,3 @@ /* | ||
// If globals disabled, only pass back local expects in an array of one | ||
if (config.globals === false) { | ||
if (require('./localOnly')(config, 'expects')) { | ||
return [ localExpects ]; | ||
@@ -19,0 +19,0 @@ } |
@@ -16,3 +16,3 @@ /* | ||
// If globals are false, just return the local not expects | ||
if (config.globals === false) { | ||
if (require('./localOnly')(config, 'notExpects')) { | ||
return [ localNotExpects ]; | ||
@@ -19,0 +19,0 @@ } |
@@ -17,3 +17,3 @@ /* | ||
if (config.globals === false) { | ||
if (require('./localOnly')(config, key)) { | ||
return subbedObject; | ||
@@ -23,3 +23,3 @@ } else { | ||
} | ||
}; |
{ | ||
"name": "@trayio/threadneedle", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "A framework for simplifying working with HTTP-based APIs.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -100,2 +100,7 @@ var assert = require('assert'); | ||
); | ||
assert.strictEqual( | ||
globalize.baseUrl.call(sample, { url: '/mypath', globals: { baseUrl: false } }, {}), | ||
'/mypath' | ||
); | ||
}); | ||
@@ -217,2 +222,17 @@ | ||
); | ||
assert.deepEqual( | ||
globalize.object.call(sample, 'data', { | ||
globals: { | ||
data: false | ||
}, | ||
data: { | ||
age: 25, | ||
height: 180 | ||
} | ||
}, {}), { | ||
age: 25, | ||
height: 180 | ||
} | ||
); | ||
}); | ||
@@ -304,2 +324,13 @@ | ||
assert.deepEqual(params, { id: '123' }); | ||
}); | ||
globalize.before.call(sample, { | ||
globals: { | ||
before: false | ||
}, | ||
url: '/mydomain/{{id}}' | ||
}, { | ||
id: '123' | ||
}).done(function (params) { | ||
assert.deepEqual(params, { id: '123' }); | ||
done(); | ||
@@ -442,2 +473,25 @@ }); | ||
it('should not run global when globals.expects is false', function () { | ||
var sample = { | ||
_globalOptions: { | ||
expects: 200 | ||
} | ||
}; | ||
assert.deepEqual(globalize.expects.call(sample, {}), [{ statusCode: [200] }]); | ||
var sample = { | ||
_globalOptions: { | ||
expects: { | ||
statusCode: [200, 201], | ||
body: 'chris' | ||
} | ||
} | ||
}; | ||
assert.deepEqual(globalize.expects.call(sample, { | ||
globals: { | ||
expects: false | ||
} | ||
}), [{}]); | ||
}); | ||
}); | ||
@@ -500,2 +554,3 @@ | ||
}; | ||
assert.deepEqual(globalize.notExpects.call(sample, { | ||
@@ -509,2 +564,13 @@ notExpects: { | ||
}]); | ||
assert.deepEqual(globalize.notExpects.call(sample, { | ||
notExpects: { | ||
body: 'steve' | ||
}, | ||
globals: { | ||
notExpects: false | ||
} | ||
}), [{ | ||
body: ['steve'] | ||
}]); | ||
}); | ||
@@ -627,2 +693,11 @@ | ||
assert.deepEqual(body, {}); | ||
//done(); | ||
}); | ||
globalize.afterSuccess.call(sample, { | ||
globals: { | ||
afterSuccess: false | ||
} | ||
}, {}).done(function (body) { | ||
assert.deepEqual(body, {}); | ||
done(); | ||
@@ -707,2 +782,11 @@ }); | ||
assert.deepEqual(err, {}); | ||
//done(); | ||
}); | ||
globalize.afterFailure.call(sample, { | ||
globals: { | ||
afterFailure: false | ||
} | ||
}, {}).done(function (err) { | ||
assert.deepEqual(err, {}); | ||
done(); | ||
@@ -709,0 +793,0 @@ }); |
102114
37
2530