usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [28/41] git commit: finished fleshing out Client tests with a few exceptions.
Date Tue, 11 Feb 2014 23:21:12 GMT
finished fleshing out Client tests with a few exceptions.


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

Branch: refs/heads/master
Commit: 8dcc1de8c7862148f5abe0a82d68ab4a707df6f3
Parents: 4978333
Author: ryan bridges <rbridges@apigee.com>
Authored: Tue Feb 11 00:50:36 2014 -0500
Committer: ryan bridges <rbridges@apigee.com>
Committed: Tue Feb 11 00:50:36 2014 -0500

----------------------------------------------------------------------
 sdks/html5-javascript/lib/Usergrid.js       |   4 +-
 sdks/html5-javascript/lib/modules/Client.js |  43 +++---
 sdks/html5-javascript/lib/modules/Entity.js |   2 +-
 sdks/html5-javascript/tests/mocha/test.js   | 173 +++++++++++++++++++++--
 sdks/html5-javascript/usergrid.js           |  53 ++++---
 sdks/html5-javascript/usergrid.min.js       |   4 +-
 6 files changed, 207 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8dcc1de8/sdks/html5-javascript/lib/Usergrid.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/Usergrid.js b/sdks/html5-javascript/lib/Usergrid.js
index 3fca37a..7b28d4f 100644
--- a/sdks/html5-javascript/lib/Usergrid.js
+++ b/sdks/html5-javascript/lib/Usergrid.js
@@ -172,9 +172,9 @@ function doCallback(callback, params, context) {
         /*
          Validate our input
          */
-        this.endpoint=endpoint;
+        this.endpoint=endpoint+'?'+encodeParams(query_params);
         this.method = method.toUpperCase();
-        this.query_params = query_params;
+        //this.query_params = query_params;
         this.data = ("object" === typeof data) ? JSON.stringify(data) : data;
 
         if (VALID_REQUEST_METHODS.indexOf(this.method) === -1) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8dcc1de8/sdks/html5-javascript/lib/modules/Client.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/modules/Client.js b/sdks/html5-javascript/lib/modules/Client.js
index 4efae5a..683b78c 100644
--- a/sdks/html5-javascript/lib/modules/Client.js
+++ b/sdks/html5-javascript/lib/modules/Client.js
@@ -62,9 +62,8 @@
     } else {
       uri = this.URI + '/' + orgName + '/' + appName + '/' + endpoint;
     }
-
-    if (self.getToken()) {
-      qs.access_token = self.getToken();
+    if (this.getToken()) {
+      qs.access_token = this.getToken();
       /* //could also use headers for the token
        xhr.setRequestHeader("Authorization", "Bearer " + self.getToken());
        xhr.withCredentials = true;
@@ -277,13 +276,11 @@
     };
 
     this.request(options, function(err, data){
-      if(typeof(callback) === "function") {
         if(err) {
-          callback(err);
+            doCallback(callback, [err]);
         } else {
-          callback(err, data, data.entities);
+            doCallback(callback, [err, data, data.data.entities]);
         }
-      }
     });
   };
 
@@ -330,9 +327,7 @@
     }
     var entity = new Usergrid.Entity(options);
     entity.save(function(err, data) {
-      if (typeof(callback) === 'function') {
-        callback(err, entity);
-      }
+        doCallback(callback, [err, entity]);
     });
   };
 
@@ -491,10 +486,11 @@
         grant_type: 'password'
       }
     };
-    this.request(options, function(err, data) {
+    self.request(options, function(err, response) {
       var user = {};
-      if (err && self.logging) {
-        console.log('error trying to log user in');
+        var data=response.data;
+      if (err) {
+        if(self.logging)console.log('error trying to log user in');
       } else {
         var options = {
           client:self,
@@ -503,9 +499,7 @@
         user = new Usergrid.Entity(options);
         self.setToken(data.access_token);
       }
-      if (typeof(callback) === 'function') {
-        callback(err, data, user);
-      }
+      doCallback(callback, [err, data, user]);
     });
   };
 
@@ -523,12 +517,11 @@
       } else {
 
         //save the re-authed token and current email/username
-        self.setToken(response.access_token);
+          self.setToken(response.data.access_token);
 
       }
-      if (typeof(callback) === 'function') {
-        callback(err);
-      }
+        doCallback(callback, [err]);
+
     });
   };
 
@@ -652,7 +645,8 @@
         method:'GET',
         endpoint:'users/me'
       };
-      this.request(options, function(err, data) {
+      this.request(options, function(err, response) {
+          var data=response.data;
         if (err) {
           if (self.logging) {
             console.log('error trying to log user in');
@@ -667,7 +661,7 @@
           };
           var user = new Usergrid.Entity(options);
           if (typeof(callback) === 'function') {
-            callback(err, data, user);
+            callback(null, data, user);
           }
         }
       });
@@ -683,7 +677,8 @@
    *  @return {boolean} Returns true the user is logged in (has token and uuid), false if
not
    */
   Usergrid.Client.prototype.isLoggedIn = function () {
-    return "undefined" !== typeof this.getToken();
+      var token=this.getToken();
+    return "undefined" !== typeof token && token!==null;
   };
 
   /*
@@ -694,7 +689,7 @@
    *  @return none
    */
   Usergrid.Client.prototype.logout = function () {
-    this.setToken(null);
+    this.setToken();
   };
 
   /*

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8dcc1de8/sdks/html5-javascript/lib/modules/Entity.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/modules/Entity.js b/sdks/html5-javascript/lib/modules/Entity.js
index b1225a3..8b21bd5 100644
--- a/sdks/html5-javascript/lib/modules/Entity.js
+++ b/sdks/html5-javascript/lib/modules/Entity.js
@@ -112,7 +112,7 @@ Usergrid.Entity.prototype.getEndpoint = function () {
     var nameProperties=['uuid', 'name'];
     if (type === undefined) {
         throw new UsergridError('cannot fetch entity, no entity type specified', 'no_type_specified');
-    }else if(type==="users"){
+    }else if(type==="users"||type==="user"){
         nameProperties.unshift('username');
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8dcc1de8/sdks/html5-javascript/tests/mocha/test.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/tests/mocha/test.js b/sdks/html5-javascript/tests/mocha/test.js
index 8bcd19a..be4bdf6 100644
--- a/sdks/html5-javascript/tests/mocha/test.js
+++ b/sdks/html5-javascript/tests/mocha/test.js
@@ -344,56 +344,201 @@ describe('Usergrid Client', function() {
             assert(dogs._list.length===dogCollection._list.length, "The collections have
a different number of entities")
             done();
         })
-        it('getFeedForUser',function(done){
-            done();
+        var activityUser;
+        before(function(done){
+            activityUser=new Usergrid.Entity({client:client,data:{"type":"user",username:"testActivityUser"}});
+            activityUser.fetch(function(err, data){
+                if(err){
+                    activityUser.save(function(err, data){
+                        activityUser.set(data);
+                        done();
+                    });
+                }else{
+                    activityUser.set(data);
+                    done();
+                }
+            })
+//            client.request({
+//                method: 'GET',
+//                endpoint: 'users/testActivityUser'
+//            }, function(err, data) {
+//                if(err){
+//                    client.request({
+//                        method: 'POST',
+//                        endpoint: 'users',
+//                        body: {
+//                            username: 'testActivityUser',
+//                            password: 'secret'
+//                        }
+//                    }, function(err, data) {
+//                        activityUser=data;
+//                        console.log(activityUser);
+//                        done();
+//                    });
+//                }else{
+//                    activityUser=data;
+//                    console.log(activityUser);
+//                    done();
+//                }
+//            });
         })
         it('createUserActivity',function(done){
-            done();
+             var options = {
+               "actor" : {
+                     "displayName" :"Test Activity User",
+                         "uuid" : activityUser.get("uuid"),
+                         "username" : "testActivityUser",
+                         "email" : "usergrid@apigee.com",
+                         "image" : {
+                                 "height" : 80,
+                                 "url" : "http://placekitten.com/80/80",
+                                 "width" : 80
+                         }
+                    },
+                    "verb" : "post",
+                   "content" : "test post for createUserActivity",
+                   "lat" : 48.856614,
+                   "lon" : 2.352222
+                 };
+            client.createUserActivity("testActivityUser", options, function(err, activity){
+                assert(!err, "createUserActivity returned an error");
+                assert(activity, "createUserActivity returned no activity object")
+                done();
+            })
         })
         it('createUserActivityWithEntity',function(done){
-            done();
+                console.log(activityUser.get("username"));
+                client.createUserActivityWithEntity(activityUser, "Another test activity
with createUserActivityWithEntity", function(err, activity){
+                    assert(!err, "createUserActivityWithEntity returned an error "+err);
+                    assert(activity, "createUserActivityWithEntity returned no activity object")
+                    done();
+                })
         })
+        it('getFeedForUser',function(done){
+            client.getFeedForUser('testActivityUser', function(err, data, items){
+                console.error(err, JSON.stringify(data.data, null, 4));
+                assert(!err, "getFeedForUser returned an error");
+                assert(data, "getFeedForUser returned no data object")
+                assert(items, "getFeedForUser returned no items array")
+                done();
+            })
+        })
+        /*after(function(done){
+            client.request({
+                method: 'DELETE',
+                endpoint: 'users/testActivityUser'
+            }, function(err, data) {
+                done();
+            });
+
+        })*/
+        var testProperty="____test_item"+Math.floor(Math.random()*10000),
+            testPropertyValue="test"+Math.floor(Math.random()*10000),
+            testPropertyObjectValue={test:testPropertyValue};
         it('set',function(done){
+            client.set(testProperty, testPropertyValue);
             done();
         })
         it('get',function(done){
+            var retrievedValue=client.get(testProperty);
+            assert(retrievedValue===testPropertyValue, "Get is not working properly");
             done();
         })
         it('setObject',function(done){
+            client.set(testProperty, testPropertyObjectValue);
             done();
         })
         it('getObject',function(done){
+            var retrievedValue=client.get(testProperty);
+            assert(retrievedValue==testPropertyObjectValue, "getObject is not working properly");
             done();
         })
-        it('setToken',function(done){
+        /*it('setToken',function(done){
+            client.setToken("dummytoken");
             done();
         })
         it('getToken',function(done){
+            assert(client.getToken()==="dummytoken");
+            done();
+        })*/
+        it('remove property',function(done){
+            client.set(testProperty);
+            assert(client.get(testProperty)===null);
             done();
         })
+        var newUser;
         it('signup',function(done){
-            done();
+            client.signup("newUsergridUser", "Us3rgr1d15Aw3s0m3!", "usergrid@apigee.com",
"Another Satisfied Developer", function(err, user){
+                assert(!err, "signup returned an error");
+                assert(user, "signup returned no user object")
+                newUser=user;
+                done();
+            })
         })
         it('login',function(done){
-            done();
+            client.login("newUsergridUser", "Us3rgr1d15Aw3s0m3!", function(err, data, user){
+                assert(!err, "login returned an error");
+                assert(user, "login returned no user object")
+                done();
+            })
         })
-        it('reAuthenticateLite',function(done){
+        /*it('reAuthenticateLite',function(done){
+            client.reAuthenticateLite(function(err){
+                assert(!err, "reAuthenticateLite returned an error");
+                done();
+            })
+        })*/
+        /*it('reAuthenticate',function(done){
+            client.reAuthenticate("usergrid@apigee.com", function(err, data, user, organizations,
applications){
+                assert(!err, "reAuthenticate returned an error");
+                done();
+            })
+        })*/
+        /*it('loginFacebook',function(done){
+            assert(true, "Not sure how feasible it is to test this with Mocha")
             done();
-        })
-        it('reAuthenticate',function(done){
+        })*/
+        it('isLoggedIn',function(done){
+            assert(client.isLoggedIn()===true, "isLoggedIn is not detecting that we have
logged in.")
             done();
         })
-        it('loginFacebook',function(done){
+        it('getLoggedInUser',function(done){
+            setTimeout(function(){
+                client.getLoggedInUser(function(err, data, user){
+                    assert(!err, "getLoggedInUser returned an error");
+                    assert(user, "getLoggedInUser returned no user object")
+                    done();
+                })
+            },1000);
+        })
+        before(function(done){
+            //please enjoy this musical interlude.
+            setTimeout(function(){done()},1000);
+        })
+        it('logout',function(done){
+            client.logout();
+            assert(null===client.getToken(), "we logged out, but the token still remains.")
             done();
         })
         it('getLoggedInUser',function(done){
-            done();
+            client.getLoggedInUser(function(err, data, user){
+                assert(err, "getLoggedInUser should return an error after logout");
+                assert(!user, "getLoggedInUser should not return data after logout")
+                done();
+            })
         })
         it('isLoggedIn',function(done){
+            assert(client.isLoggedIn()===false, "isLoggedIn still returns true after logout.")
             done();
         })
-        it('logout',function(done){
-            done();
+        after(function (done) {
+            client.request({
+                method: 'DELETE',
+                endpoint: 'users/newUsergridUser'
+            }, function (err, data) {
+                done();
+            });
+
         })
         it('buildCurlCall',function(done){
             done();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8dcc1de8/sdks/html5-javascript/usergrid.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/usergrid.js b/sdks/html5-javascript/usergrid.js
index 093e847..d8a888f 100644
--- a/sdks/html5-javascript/usergrid.js
+++ b/sdks/html5-javascript/usergrid.js
@@ -1,4 +1,4 @@
-/*! usergrid@0.0.0 2014-02-10 */
+/*! usergrid@0.0.0 2014-02-11 */
 var UsergridEventable = function() {
     throw Error("'UsergridEventable' is not intended to be invoked directly");
 };
@@ -524,9 +524,9 @@ function doCallback(callback, params, context) {
         /*
          Validate our input
          */
-        this.endpoint = endpoint;
+        this.endpoint = endpoint + "?" + encodeParams(query_params);
         this.method = method.toUpperCase();
-        this.query_params = query_params;
+        //this.query_params = query_params;
         this.data = "object" === typeof data ? JSON.stringify(data) : data;
         if (VALID_REQUEST_METHODS.indexOf(this.method) === -1) {
             throw new UsergridInvalidHTTPMethodError("invalid request method '" + this.method
+ "'");
@@ -683,8 +683,8 @@ function doCallback(callback, params, context) {
         } else {
             uri = this.URI + "/" + orgName + "/" + appName + "/" + endpoint;
         }
-        if (self.getToken()) {
-            qs.access_token = self.getToken();
+        if (this.getToken()) {
+            qs.access_token = this.getToken();
         }
         var req = new Usergrid.Request(method, uri, qs, body, function(err, response) {
             if ([ "auth_expired_session_token", "auth_missing_credentials", "auth_unverified_oath",
"expired_token", "unauthorized", "auth_invalid" ].indexOf(response.error) !== -1) {
@@ -873,12 +873,10 @@ function doCallback(callback, params, context) {
             endpoint: "users/" + username + "/feed"
         };
         this.request(options, function(err, data) {
-            if (typeof callback === "function") {
-                if (err) {
-                    callback(err);
-                } else {
-                    callback(err, data, data.entities);
-                }
+            if (err) {
+                doCallback(callback, [ err ]);
+            } else {
+                doCallback(callback, [ err, data, data.data.entities ]);
             }
         });
     };
@@ -925,9 +923,7 @@ function doCallback(callback, params, context) {
         };
         var entity = new Usergrid.Entity(options);
         entity.save(function(err, data) {
-            if (typeof callback === "function") {
-                callback(err, entity);
-            }
+            doCallback(callback, [ err, entity ]);
         });
     };
     /*
@@ -1073,10 +1069,11 @@ function doCallback(callback, params, context) {
                 grant_type: "password"
             }
         };
-        this.request(options, function(err, data) {
+        self.request(options, function(err, response) {
             var user = {};
-            if (err && self.logging) {
-                console.log("error trying to log user in");
+            var data = response.data;
+            if (err) {
+                if (self.logging) console.log("error trying to log user in");
             } else {
                 var options = {
                     client: self,
@@ -1085,9 +1082,7 @@ function doCallback(callback, params, context) {
                 user = new Usergrid.Entity(options);
                 self.setToken(data.access_token);
             }
-            if (typeof callback === "function") {
-                callback(err, data, user);
-            }
+            doCallback(callback, [ err, data, user ]);
         });
     };
     Usergrid.Client.prototype.reAuthenticateLite = function(callback) {
@@ -1102,11 +1097,9 @@ function doCallback(callback, params, context) {
                 console.log("error trying to re-authenticate user");
             } else {
                 //save the re-authed token and current email/username
-                self.setToken(response.access_token);
-            }
-            if (typeof callback === "function") {
-                callback(err);
+                self.setToken(response.data.access_token);
             }
+            doCallback(callback, [ err ]);
         });
     };
     Usergrid.Client.prototype.reAuthenticate = function(email, callback) {
@@ -1220,7 +1213,8 @@ function doCallback(callback, params, context) {
                 method: "GET",
                 endpoint: "users/me"
             };
-            this.request(options, function(err, data) {
+            this.request(options, function(err, response) {
+                var data = response.data;
                 if (err) {
                     if (self.logging) {
                         console.log("error trying to log user in");
@@ -1235,7 +1229,7 @@ function doCallback(callback, params, context) {
                     };
                     var user = new Usergrid.Entity(options);
                     if (typeof callback === "function") {
-                        callback(err, data, user);
+                        callback(null, data, user);
                     }
                 }
             });
@@ -1250,7 +1244,8 @@ function doCallback(callback, params, context) {
    *  @return {boolean} Returns true the user is logged in (has token and uuid), false if
not
    */
     Usergrid.Client.prototype.isLoggedIn = function() {
-        return "undefined" !== typeof this.getToken();
+        var token = this.getToken();
+        return "undefined" !== typeof token && token !== null;
     };
     /*
    *  A public method to log out an app user - clears all user fields from client
@@ -1260,7 +1255,7 @@ function doCallback(callback, params, context) {
    *  @return none
    */
     Usergrid.Client.prototype.logout = function() {
-        this.setToken(null);
+        this.setToken();
     };
     /*
    *  A private method to build the curl call to display on the command line
@@ -1429,7 +1424,7 @@ Usergrid.Entity.prototype.getEndpoint = function() {
     var nameProperties = [ "uuid", "name" ];
     if (type === undefined) {
         throw new UsergridError("cannot fetch entity, no entity type specified", "no_type_specified");
-    } else if (type === "users") {
+    } else if (type === "users" || type === "user") {
         nameProperties.unshift("username");
     }
     var names = this.get(nameProperties).filter(function(x) {


Mime
View raw message