UNPKG

cloudboost-tv

Version:

Database Service that does Storage, Search, Real-time and a whole lot more.

172 lines (148 loc) 5.13 kB
describe("Version Test",function(done){ it("should set the Modified array",function(done){ var obj = new CB.CloudObject('sample'); obj.set('expires',0); obj.set('name','vipul'); if(obj.get('_modifiedColumns').length > 0) { done(); }else{ throw "Unable to set Modified Array"; } }); var obj = new CB.CloudObject('Sample'); it("should save.", function(done) { this.timeout(20000); obj.set('name', 'sample'); obj.save({ success : function(newObj){ if(obj.get('name') !== 'sample'){ throw 'name is not equal to what was saved.'; } if(!obj.id){ throw 'id is not updated after save.'; } done(); }, error : function(error){ throw 'Error saving the object'; } }); }); it("should get the saved CO with version",function(done){ this.timeout(20000); var query = new CB.CloudQuery('Sample'); query.findById(obj.get('id')).then(function(list){ var version = list.get('_version'); if(version>=0){ done(); }else{ throw "unable to get Version"; } },function(){ throw "unable to find saved object"; }); }); it("should update the version of a saved object", function (done) { this.timeout(15000); var query = new CB.CloudQuery('Sample'); query.equalTo('id',obj.get('id')); query.find().then(function(list){ list[0].set('name','abcd'); list[0].save().then(function(){ var query1 = new CB.CloudQuery('Sample'); query1.equalTo('id',obj.get('id')); query1.find().then(function(list){ if(list[0].get('_version') === 1){ done(); }else{ throw "version number should update"; } },function(){ throw "unable to find saved object"; }) }, function () { throw "unable to save object"; }) },function(){ throw "unable to find saved object"; }) }); var username = util.makeString(); var passwd = "abcd"; var user = new CB.CloudUser(); it("Should create new user with version", function (done) { if(CB._isNode){ console.log('Skipped, Not meant for NodeJS'); done(); return; } this.timeout(20000); user.set('username', username); user.set('password',passwd); user.set('email',util.makeEmail()); user.signUp().then(function(list) { if(list.get('username') === username && list.get('_version')>=0){ done(); } else throw "create user error" }, function () { throw "user create error"; }); }); var roleName1 = util.makeString(); it("Should create a role with version", function (done) { this.timeout(20000); var role = new CB.CloudRole(roleName1); role.save().then(function (list) { if (!list) throw "Should retrieve the cloud role"; if (list.get('_version') >= 0) done(); else throw "Unable to save version number with CloudRole"; }, function () { throw "Should retrieve the cloud role"; }); }); var parent = new CB.CloudObject('Custom4'); var child = new CB.CloudObject('student1'); it("Should Store a relation with version",function(done){ this.timeout(20000); child.set('name','vipul'); parent.set('newColumn7',[child]); parent.save().then(function(list){ if(list) done(); },function(err){ throw "should save the relation"; }); }); it("Should retrieve a saved user object",function(done){ if(CB._isNode){ console.log('Skipped, Not meant for NodeJS'); done(); return; } this.timeout(20000); var query = new CB.CloudQuery('User'); query.get(user.get('id')).then(function (user) { if(user.get('username') === username) done(); }, function () { throw "unable to get a doc"; }); }); it("Should save object with a relation and don't have a child object",function(done){ this.timeout(20000); var obj = new CB.CloudObject('Sample'); obj.set('name','vipul'); obj.save().then(function(obj1){ if(obj1.get('name') === 'vipul') done(); else throw "unable to save the object"; },function(){ throw "unable to save object"; }); }); });