Skip to content

Instantly share code, notes, and snippets.

@cnandreu
Last active August 29, 2015 14:01
Show Gist options
  • Save cnandreu/e589d62ce589e18eee6f to your computer and use it in GitHub Desktop.
Save cnandreu/e589d62ce589e18eee6f to your computer and use it in GitHub Desktop.
asyncTest('StackOverflow Question', function () {
var collections1 = {
people : {
searchFields : {name: 'string', age: 'integer'}
}
};
var options1 = {
username: 'ad2tst',
password: '607c04ef944b36ec939d39f7c6b24757776918b8425e5a3b912738d6dea0ebea',
localKeyGen: true,
clear: false
};
WL.JSONStore.destroy()
.then(function () {
var collections2 = {
orders : {
searchFields: {item : 'string'}
}
};
var options2 = {
username: 'ad1tst',
password: 'b5de1dfbbd09c5f8cf78d858eb4ed09e3b9826f9c35c950d164e8accf7775082',
localKeyGen: true,
clear: false
};
return WL.JSONStore.init(collections2, options2);
})
.then(function (res) {
deepEqual(typeof res, 'object', 'first init');
return WL.JSONStore.get('orders').add([{item: 'candy'}]);
})
.then(function (res) {
deepEqual(res, 1, 'first add');
return WL.JSONStore.get('orders').findAll();
})
.then(function (res) {
deepEqual(res[0].json.item, 'candy', 'first find - candy');
return WL.JSONStore.closeAll();
})
.then(function (res) {
deepEqual(res, 0, 'closeall');
return WL.JSONStore.init(collections1, options1);
})
.then(function (res) {
deepEqual(typeof res, 'object', 'second init');
return WL.JSONStore.get('people').add([{name: 'carlos', age: 10}, {name: 'mike', age: 5}]);
})
.then(function (res) {
deepEqual(res, 2, 'second add');
return WL.JSONStore.closeAll();
})
.then(function (res) {
deepEqual(res, 0, 'closeAll');
return WL.JSONStore.init(collections1, options1);
})
.then(function (res) {
deepEqual(typeof res, 'object', 'third init');
return WL.JSONStore.get('people').findAll();
})
.then(function (res) {
deepEqual(res[0].json.name, 'carlos', 'find all');
start();
})
.fail(function (errorObject) {
ok(false, "Failed with:" + errorObject.toString());
start();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment