2013-03-13 11:58:46 -04:00
|
|
|
module("Lawnchair DAO");
|
|
|
|
|
|
|
|
var lawnchairdao_test = {};
|
|
|
|
|
2013-05-23 17:14:30 -04:00
|
|
|
asyncTest("Init", 2, function() {
|
2013-03-13 11:58:46 -04:00
|
|
|
// init dependencies
|
|
|
|
lawnchairdao_test.jsonDao = new app.dao.LawnchairDAO(window);
|
|
|
|
ok(lawnchairdao_test.jsonDao, 'LanwchairDAO');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// clear db before test
|
|
|
|
lawnchairdao_test.jsonDao.clear(function() {
|
|
|
|
ok(true, 'cleared db');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
start();
|
2013-05-23 17:14:30 -04:00
|
|
|
});
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest("CRUD object literal", 4, function() {
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
var key = 'type_asdf';
|
|
|
|
var data = {
|
2013-05-23 17:14:30 -04:00
|
|
|
name: 'testName',
|
|
|
|
type: 'testType'
|
2013-03-13 11:58:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// create
|
2013-05-23 17:14:30 -04:00
|
|
|
lawnchairdao_test.jsonDao.persist(key, data, function() {
|
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// read
|
|
|
|
lawnchairdao_test.jsonDao.read(key, function(read) {
|
|
|
|
equal(data.name, read.name, 'Create, Read');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// list all
|
2013-05-23 17:14:30 -04:00
|
|
|
lawnchairdao_test.jsonDao.list('type', 0, null, function(list) {
|
2013-03-13 11:58:46 -04:00
|
|
|
ok(list.length === 1, 'List');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// update
|
|
|
|
var newName = 'updatedName';
|
|
|
|
read.name = newName;
|
|
|
|
lawnchairdao_test.jsonDao.persist(key, read, function() {
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// read again
|
|
|
|
lawnchairdao_test.jsonDao.read(key, function(updated) {
|
|
|
|
equal(updated.name, newName, 'Update');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// delete
|
|
|
|
lawnchairdao_test.jsonDao.remove(key, function() {
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// should read empty
|
|
|
|
lawnchairdao_test.jsonDao.read(key, function(lastRead) {
|
|
|
|
equal(lastRead, null, 'Delete');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
start();
|
2013-05-23 17:14:30 -04:00
|
|
|
});
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|
|
|
|
});
|
2013-05-23 17:14:30 -04:00
|
|
|
});
|
|
|
|
});
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|
|
|
|
});
|