2013-06-10 16:02:29 -04:00
|
|
|
define(['js/dao/lawnchair-dao'], function(jsonDao) {
|
|
|
|
'use strict';
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-06-10 16:02:29 -04:00
|
|
|
module("Lawnchair DAO");
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-06-10 16:02:29 -04:00
|
|
|
var lawnchairdaoTest = {
|
|
|
|
user: 'lawnchair@test.com'
|
|
|
|
};
|
|
|
|
|
|
|
|
asyncTest("Init", 2, function() {
|
|
|
|
// init dependencies
|
2013-09-26 07:26:57 -04:00
|
|
|
jsonDao.init(lawnchairdaoTest.user, function() {
|
|
|
|
ok(true, 'init db');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-09-26 07:26:57 -04:00
|
|
|
// clear db before test
|
|
|
|
jsonDao.clear(function() {
|
|
|
|
ok(true, 'cleared db');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-09-26 07:26:57 -04:00
|
|
|
start();
|
|
|
|
});
|
2013-06-10 16:02:29 -04:00
|
|
|
});
|
2013-05-23 17:14:30 -04:00
|
|
|
});
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-09-28 13:04:15 -04:00
|
|
|
asyncTest("CRUD object literal", 5, function() {
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-09-28 13:04:15 -04:00
|
|
|
var key = 'type_1';
|
2013-06-10 16:02:29 -04:00
|
|
|
var data = {
|
2013-09-28 13:04:15 -04:00
|
|
|
name: 'testName1',
|
|
|
|
type: 'testType1'
|
|
|
|
};
|
|
|
|
|
|
|
|
var key2 = 'type_2';
|
|
|
|
var data2 = {
|
|
|
|
name: 'testName2',
|
|
|
|
type: 'testType2'
|
2013-06-10 16:02:29 -04:00
|
|
|
};
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-06-10 16:02:29 -04:00
|
|
|
// create
|
|
|
|
jsonDao.persist(key, data, function() {
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-06-10 16:02:29 -04:00
|
|
|
// read
|
|
|
|
jsonDao.read(key, function(read) {
|
|
|
|
equal(data.name, read.name, 'Create, Read');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-06-10 16:02:29 -04:00
|
|
|
// list all
|
|
|
|
jsonDao.list('type', 0, null, function(list) {
|
|
|
|
ok(list.length === 1, 'List');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-06-10 16:02:29 -04:00
|
|
|
// update
|
|
|
|
var newName = 'updatedName';
|
|
|
|
read.name = newName;
|
|
|
|
jsonDao.persist(key, read, function() {
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-06-10 16:02:29 -04:00
|
|
|
// read again
|
|
|
|
jsonDao.read(key, function(updated) {
|
|
|
|
equal(updated.name, newName, 'Update');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-09-28 13:04:15 -04:00
|
|
|
// persist 2nd type
|
|
|
|
jsonDao.persist(key2, data2, function() {
|
|
|
|
|
|
|
|
// delete all items of 2nd type
|
|
|
|
jsonDao.removeList(key2, function() {
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-09-28 13:04:15 -04:00
|
|
|
jsonDao.list('type', 0, null, function(newList) {
|
|
|
|
ok(newList.length === 1, 'List');
|
2013-05-23 17:14:30 -04:00
|
|
|
|
2013-09-28 13:04:15 -04:00
|
|
|
// delete
|
|
|
|
jsonDao.remove(key, function() {
|
|
|
|
|
|
|
|
// should read empty
|
|
|
|
jsonDao.read(key, function(lastRead) {
|
|
|
|
equal(lastRead, undefined, 'Delete');
|
|
|
|
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-06-10 16:02:29 -04:00
|
|
|
});
|
2013-05-23 17:14:30 -04:00
|
|
|
});
|
2013-06-10 16:02:29 -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-06-10 16:02:29 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|