Added optional bool to not set as current user when calling 
client.authenticateUser()


Project: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/commit/c87f073b
Tree: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/tree/c87f073b
Diff: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/diff/c87f073b

Branch: refs/heads/master
Commit: c87f073b0cd1b71b535b5714023b3e3eb87b3556
Parents: 3ffee11
Author: brandon <bran...@behemoth.ca>
Authored: Wed Feb 10 09:37:46 2016 -0800
Committer: brandon <bran...@behemoth.ca>
Committed: Wed Feb 10 09:37:46 2016 -0800

----------------------------------------------------------------------
 lib/client.js                 |  7 ++++---
 tests/lib/client.auth.test.js | 16 ++++++++++++++--
 2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c87f073b/lib/client.js
----------------------------------------------------------------------
diff --git a/lib/client.js b/lib/client.js
index c337484..509b50c 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -107,12 +107,13 @@ UsergridClient.prototype = {
     },
     authenticateUser: function(options) {
         var self = this
-        var callback = helpers.cb(helpers.args(arguments))
-
+        var args = helpers.args(arguments)
+        var callback = helpers.cb(args)
+        var setAsCurrentUser = (_.last(args.filter(_.isBoolean))) !== 
undefined ? _.last(args.filter(_.isBoolean)) : true
         var UsergridUser = require('./user')
         var currentUser = new UsergridUser(options)
         currentUser.login(self, function(error, usergridResponse, token) {
-            if (usergridResponse.ok) {
+            if (usergridResponse.ok && setAsCurrentUser) {
                 self.currentUser = currentUser
             }
             callback(error, usergridResponse, token)

http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c87f073b/tests/lib/client.auth.test.js
----------------------------------------------------------------------
diff --git a/tests/lib/client.auth.test.js b/tests/lib/client.auth.test.js
index c7f6bad..ad33987 100644
--- a/tests/lib/client.auth.test.js
+++ b/tests/lib/client.auth.test.js
@@ -202,8 +202,8 @@ describe('authenticateUser()', function() {
 
     it('should fail when called without a email (or username) and password', 
function() {
         should(function() {
-            var client = new UsergridClient()
-            client.authenticateUser({})
+            var badClient = new UsergridClient()
+            badClient.authenticateUser({})
         }).throw()
     })
 
@@ -238,6 +238,18 @@ describe('authenticateUser()', function() {
         client.currentUser.auth.should.not.have.property('password')
     })
 
+    it('should support an optional bool to not set as current user', 
function(done) {
+        var noCurrentUserClient = new UsergridClient()
+        noCurrentUserClient.authenticateUser({
+            username: config.test.username,
+            password: config.test.password,
+            email: email
+        }, false, function(err, r, t) {
+            should(noCurrentUserClient.currentUser).be.undefined()
+            done()
+        })
+    })
+
     it('should support passing a UsergridUserAuth instance with a custom ttl', 
function(done) {
         var newClient = new UsergridClient()
         var ttlInMilliseconds = 500000

Reply via email to