Skip to content

Instantly share code, notes, and snippets.

@sdesai
Created July 20, 2012 17:12
Show Gist options
  • Save sdesai/3151955 to your computer and use it in GitHub Desktop.
Save sdesai/3151955 to your computer and use it in GitHub Desktop.
YUI.add("transaction-integration-tests", function(Y, module) {
var WAIT_TIMEOUT = Y.BridgeIntegrationTests.WAIT_TIMEOUT,
DB_HANDLE_ID,
DB_INSTANCE;
Y.BridgeIntegrationTests.add(new Y.Test.Case({
id : module,
name : "Transaction Integration Tests",
"test new Y.DB() Success" : function() {
var test = this;
DB_INSTANCE = new Y.DB({
name:"Foo",
version:"0",
displayName:"My Database",
on : {
success: function(o) {
test.resume(function() {
Y.Assert.isString(o.connectionId, "Invalid connection id");
});
},
failure : function(o) {
test.resume(function() {
Y.Assert.fail("Wasn't expecting error to be called");
});
}
}
});
test.wait(WAIT_TIMEOUT);
},
"test db.addStore()" : function() {
var test = this;
DB_INSTANCE.addStore("test", {
name : '',
surname : {
asc : true,
text : true
},
id : {
primary : true,
required : true
}
},
null,
function(o) {
test.resume(function() {
Y.Assert.pass();
});
},
function(o) {
test.resume(function() {
Y.Assert.fail("Wasn't expecting error to be called");
});
});
test.wait(WAIT_TIMEOUT);
},
"test db.addObjects()" : function(){
var test = this;
DB_INSTANCE.addObjects("test", [{
name: 'Satyen',
surname: 'Desai',
id: 'sdesai'
}],
function(o) {
test.resume(function() {
Y.Assert.areEqual(1, o.rowsAffected, "Expected 1 rows affected");
});
},
function(o) {
test.resume(function() {
Y.Assert.fail("Wasn't expecting error to be called");
});
});
test.wait(WAIT_TIMEOUT);
},
"test db transaction updateObjects()" : function() {
var test = this,
tx = DB_INSTANCE.transaction(function(o) {
// BUG: Should get a transactionId back, but we're not
// Y.Assert.areEqual(tx, o.transactionId);
test.resume(function() {
tx.getObjects("test", null, function(o) {
test.resume(function() {
Y.Assert.areEqual(1, o.results.length);
Y.Assert.areEqual("Desai", o.result[0].surname, "Expected Desai");
Y.Assert.areEqual("Satyen", o.result[0].name, "Expected Satyen");
tx.commit(function() {
test.resume(Y.Assert.pass);
}, function() {
test.resume(Y.Assert.fail);
});
test.wait(WAIT_TIMEOUT);
});
}, function(o) {
test.resume(function() {
tx.rollback(function() {
test.resume(function() {Y.Assert.fail("select failed. Rolling Back")});
}, function() {
test.resume(function() {Y.Assert.fail("select failed. Rollback failed")});
});
test.wait(WAIT_TIMEOUT);
});
});
test.wait(WAIT_TIMEOUT);
});
}, function(o) {
test.resume(function() {
Y.Assert.fail(o.message);
});
});
test.wait(WAIT_TIMEOUT);
},
"test db.removeStore()" : function() {
var test = this;
DB_INSTANCE.removeStore("test",
function(o) {
test.resume(function() {
Y.Assert.pass();
});
},
function(o) {
test.resume(function() {
Y.Assert.fail("Wasn't expecting error to be called");
});
});
test.wait(WAIT_TIMEOUT);
}
}));
}, "1.0.0", {requires: ["test", "bridge-integration-tests", "db"]});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment