usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [26/41] git commit: Fixed issues with Usergrid.Client.prototype.createGroup. Added more tests
Date Tue, 11 Feb 2014 23:21:10 GMT
Fixed issues with Usergrid.Client.prototype.createGroup. Added more tests


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

Branch: refs/heads/master
Commit: 49783334d2886fa4f42eccf0bc126986b5ddab99
Parents: e104c3e
Author: ryan bridges <rbridges@apigee.com>
Authored: Mon Feb 10 19:16:21 2014 -0500
Committer: ryan bridges <rbridges@apigee.com>
Committed: Mon Feb 10 19:16:21 2014 -0500

----------------------------------------------------------------------
 sdks/html5-javascript/Gruntfile.js          |  6 +-
 sdks/html5-javascript/lib/Usergrid.js       |  6 +-
 sdks/html5-javascript/lib/modules/Client.js | 10 +---
 sdks/html5-javascript/tests/mocha/test.js   | 71 ++++++++++++++++++++++--
 sdks/html5-javascript/usergrid.js           | 19 ++-----
 sdks/html5-javascript/usergrid.min.js       |  2 +-
 6 files changed, 82 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/49783334/sdks/html5-javascript/Gruntfile.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/Gruntfile.js b/sdks/html5-javascript/Gruntfile.js
index 527633d..cfa39e3 100644
--- a/sdks/html5-javascript/Gruntfile.js
+++ b/sdks/html5-javascript/Gruntfile.js
@@ -68,8 +68,8 @@ module.exports = function(grunt) {
             "tasks": ["default"]
         },
         "blanket_mocha": {
-            "all": tests,
-            //urls: [ 'http://localhost:8000/tests/mocha/index.html' ],
+            //"all": tests,
+            urls: [ 'http://localhost:8000/tests/mocha/index.html' ],
             "options": {
                 "dest": "report/coverage.html",
                 "reporter": "Spec",
@@ -92,6 +92,6 @@ module.exports = function(grunt) {
 	]);
 	grunt.registerTask("test", [
 		"connect:test",
-		"blanket_mocha",
+		"blanket_mocha"
 	]);
 };

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/49783334/sdks/html5-javascript/lib/Usergrid.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/Usergrid.js b/sdks/html5-javascript/lib/Usergrid.js
index ec10de1..3fca37a 100644
--- a/sdks/html5-javascript/lib/Usergrid.js
+++ b/sdks/html5-javascript/lib/Usergrid.js
@@ -138,13 +138,13 @@ function doCallback(callback, params, context) {
 		if (!params) params = [];
 		if (!context) context = this;
 		params.push(context);
-		try {
+		//try {
 			returnValue = callback.apply(context, params);
-		} catch (ex) {
+		/*} catch (ex) {
 			if (console && console.error) {
 				console.error("Callback error:", ex);
 			}
-		}
+		}*/
 	}
 	return returnValue;
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/49783334/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 88ff623..4efae5a 100644
--- a/sdks/html5-javascript/lib/modules/Client.js
+++ b/sdks/html5-javascript/lib/modules/Client.js
@@ -132,17 +132,13 @@
 
     var group = new Usergrid.Group(options);
     group.fetch(function(err, data){
-      var okToSave = (err && 'service_resource_not_found' === data.error || 'no_name_specified'
=== data.error || 'null_pointer' === data.error) || (!err && getOnExist);
+      var okToSave = (err && ['service_resource_not_found','no_name_specified','null_pointer'].indexOf(err.name)!==-1)
|| (!err && getOnExist);
       if (okToSave) {
         group.save(function(err, data){
-          if (typeof(callback) === 'function') {
-            callback(err, group);
-          }
+            doCallback(callback, [err, group, data]);
         });
       } else {
-        if(typeof(callback) === 'function') {
-          callback(err, group);
-        }
+        doCallback(callback, [null, group, data]);
       }
     });
   };

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/49783334/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 2ecf944..8bcd19a 100644
--- a/sdks/html5-javascript/tests/mocha/test.js
+++ b/sdks/html5-javascript/tests/mocha/test.js
@@ -267,24 +267,81 @@ describe('Usergrid Client', function() {
 	});
     describe('Usergrid convenience methods', function(){
         it('createEntity',function(done){
-            done();
+            client.createEntity({type:'dog',name:'createEntityTestDog'}, function(err, dog){
+                assert(!err, "createEntity returned an error")
+                assert(dog, "createEntity did not return a dog")
+                assert(dog.get("name")==='createEntityTestDog', "The dog's name is not 'createEntityTestDog'")
+                done();
+            })
         })
-        it('createCollection',function(done){
-            done();
+        it('createEntity - existing entity',function(done){
+            client.createEntity({type:'dog',name:'createEntityTestDog'}, function(err, dog){
+                assert(!err, "createEntity returned an error")
+                assert(dog, "createEntity did not return a dog")
+                assert(dog.get("name")==='createEntityTestDog', "The dog's name is not 'createEntityTestDog'")
+                done();
+            })
         })
+        it('createEntity - get on Exist',function(done){
+            client.createEntity({type:'dog',name:'createEntityTestDog', getOnExist:true},
function(err, dog){
+                assert(!err, "createEntity returned an error")
+                assert(dog, "createEntity did not return a dog")
+                assert(dog.get("uuid")!==null, "The dog's UUID was not returned")
+                done();
+            })
+        })
+        var testGroup;
         it('createGroup',function(done){
+            client.createGroup({path:'dogLovers'},function(err, group){
+                assert(!err, "createGroup returned an error: "+err);
+                assert(group, "createGroup did not return a group");
+                assert(group instanceof Usergrid.Group, "createGroup did not return a Usergrid.Group");
+                testGroup=group;
+                done();
+            })
             done();
         })
         it('buildAssetURL',function(done){
+            var assetURL='https://api.usergrid.com/yourorgname/sandbox/assets/00000000-0000-0000-000000000000/data';
+            assert(assetURL===client.buildAssetURL('00000000-0000-0000-000000000000'), "buildAssetURL
doesn't work")
             done();
         })
+        var dogEntity;
         it('getEntity',function(done){
-            done();
+            client.getEntity({type:'dog',name:'createEntityTestDog'}, function(err, dog){
+                assert(!err, "createEntity returned an error")
+                assert(dog, "createEntity returned a dog")
+                assert(dog.get("uuid")!==null, "The dog's UUID was not returned")
+                dogEntity=dog;
+                done();
+            })
         })
         it('restoreEntity',function(done){
+            var serializedDog=dogEntity.serialize();
+            var dog=client.restoreEntity(serializedDog);
+            assert(dog, "restoreEntity did not return a dog")
+            assert(dog.get("uuid")===dogEntity.get("uuid"), "The dog's UUID was not the same
as the serialized dog")
+            assert(dog.get("type")===dogEntity.get("type"), "The dog's type was not the same
as the serialized dog")
+            assert(dog.get("name")===dogEntity.get("name"), "The dog's name was not the same
as the serialized dog")
+
             done();
         })
+        var dogCollection;
+        it('createCollection',function(done){
+            client.createCollection({type:'dogs'},function(err, dogs){
+                assert(!err, "createCollection returned an error");
+                assert(dogs, "createCollection did not return a dogs collection");
+                dogCollection=dogs;
+                done();
+            })
+        })
         it('restoreCollection',function(done){
+            var serializedDogs=dogCollection.serialize();
+            var dogs=client.restoreCollection(serializedDogs);
+            console.warn('restoreCollection',dogs, dogCollection);
+            assert(dogs._type===dogCollection._type, "The dog collection type was not the
same as the serialized dog collection")
+            assert(dogs._qs==dogCollection._qs, "The query strings do not match")
+            assert(dogs._list.length===dogCollection._list.length, "The collections have
a different number of entities")
             done();
         })
         it('getFeedForUser',function(done){
@@ -344,6 +401,12 @@ describe('Usergrid Client', function() {
         it('getDisplayImage',function(done){
             done();
         })
+        after(function(done){
+            dogEntity.destroy();
+            //dogCollection.destroy();
+            //testGroup.destroy();
+            done();
+        })
     });
     describe('Usergrid Entity', function() {
 		var dog;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/49783334/sdks/html5-javascript/usergrid.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/usergrid.js b/sdks/html5-javascript/usergrid.js
index 38a8011..093e847 100644
--- a/sdks/html5-javascript/usergrid.js
+++ b/sdks/html5-javascript/usergrid.js
@@ -497,13 +497,8 @@ function doCallback(callback, params, context) {
         if (!params) params = [];
         if (!context) context = this;
         params.push(context);
-        try {
-            returnValue = callback.apply(context, params);
-        } catch (ex) {
-            if (console && console.error) {
-                console.error("Callback error:", ex);
-            }
-        }
+        //try {
+        returnValue = callback.apply(context, params);
     }
     return returnValue;
 }
@@ -738,17 +733,13 @@ function doCallback(callback, params, context) {
         };
         var group = new Usergrid.Group(options);
         group.fetch(function(err, data) {
-            var okToSave = err && "service_resource_not_found" === data.error ||
"no_name_specified" === data.error || "null_pointer" === data.error || !err && getOnExist;
+            var okToSave = err && [ "service_resource_not_found", "no_name_specified",
"null_pointer" ].indexOf(err.name) !== -1 || !err && getOnExist;
             if (okToSave) {
                 group.save(function(err, data) {
-                    if (typeof callback === "function") {
-                        callback(err, group);
-                    }
+                    doCallback(callback, [ err, group, data ]);
                 });
             } else {
-                if (typeof callback === "function") {
-                    callback(err, group);
-                }
+                doCallback(callback, [ null, group, data ]);
             }
         });
     };


Mime
View raw message