Permalink
Browse files

Merge branch 'hotfix/0.3.4'

  • Loading branch information...
2 parents bd096fe + 17f9742 commit cc1501a4997c6add32d4d789edc55ea788d30b5a @stomita committed Oct 19, 2012
Showing with 24 additions and 8 deletions.
  1. +5 −2 lib/connection.js
  2. +1 −1 package.json
  3. +18 −5 test/salesforce.test.js
View
@@ -98,9 +98,11 @@ Connection.prototype._request = function(params, callback, noContentResponse) {
self.emit('response', response.statusCode, response.body, response);
// if authorization required, refresh when oauth2 info and refresh token is available
if (response.statusCode === 401 && self.oauth2 && self.refreshToken) {
- self.suspended = true;
+ if (!self.suspended) {
+ self.suspended = true;
+ self._refresh();
+ }
self.once('resume', onResume);
- self._refresh();
return;
}
if (response.statusCode >= 400) {
@@ -141,6 +143,7 @@ Connection.prototype._refresh = function() {
instanceUrl : res.instance_url,
accessToken : res.access_token
});
+ self.emit("refresh", res.access_token, res);
}
self.suspended = false;
self.emit('resume', err);
View
@@ -4,7 +4,7 @@
"description": "Salesforce API Connection Library for Node.js Applications",
"keywords": [ "salesforce", "salesforce.com", "sfdc", "force.com", "database.com" ],
"homepage": "http://github.com/stomita/node-salesforce",
- "version": "0.3.3",
+ "version": "0.3.4",
"repository": {
"type": "git",
"url": "git://github.com/stomita/node-salesforce.git"
View
@@ -9,6 +9,7 @@ var vows = require('vows')
var conn = new sf.Connection();
var browser = new zombie.Browser();
+var context = {};
vows.describe("salesforce").addBatch({
"login" : {
@@ -22,6 +23,7 @@ vows.describe("salesforce").addBatch({
}).addBatch({
+
"query accounts" : {
topic : function() {
conn.query("SELECT Id, Name FROM Account", this.callback);
@@ -365,21 +367,30 @@ vows.describe("salesforce").addBatch({
", then expire access token and query user" : {
topic : function() {
+ context.refreshCount = 0;
conn.accessToken = "invalid access token";
- /*
- conn.on('auth', function(){ console.log('auth requested'); });
- conn.on('resume', function(){ console.log('resumed'); });
- conn.on('request', function(method, url){ console.log(method + ", " + url); });
- */
+ conn.removeAllListeners("refresh");
+ conn.on("refresh", function(at) {
+ context.newAccessToken = at;
+ context.refreshCount++;
+ });
conn.query("SELECT Id FROM User", this.callback);
},
"should return records" : function(res) {
+ assert.equal(context.refreshCount, 1);
+ assert.isString(context.newAccessToken);
assert.isArray(res.records);
},
", then again expire access token and call api in parallel" : {
topic : function() {
+ context.refreshCount = 0;
conn.accessToken = "invalid access token";
+ conn.removeAllListeners("refresh");
+ conn.on("refresh", function(at) {
+ context.newAccessToken = at;
+ context.refreshCount++;
+ });
async.parallel([
function(cb) {
conn.query('SELECT Id FROM User', cb);
@@ -394,6 +405,8 @@ vows.describe("salesforce").addBatch({
},
"should return responces" : function(results) {
+ assert.equal(context.refreshCount, 1);
+ assert.isString(context.newAccessToken);
assert.isArray(results);
assert.isArray(results[0].records);
assert.isArray(results[1].sobjects);

0 comments on commit cc1501a

Please sign in to comment.