1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-17 14:45:02 -05:00
mail/test/unit/lawnchair-dao-test.js

69 lines
1.3 KiB
JavaScript
Raw Normal View History

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
jsonDao.init(lawnchairdaoTest.user);
ok(jsonDao, 'LanwchairDAO');
2013-05-23 17:14:30 -04:00
2013-06-10 16:02:29 -04:00
// clear db before test
jsonDao.clear(function() {
ok(true, 'cleared db');
2013-05-23 17:14:30 -04:00
2013-06-10 16:02:29 -04:00
start();
});
2013-05-23 17:14:30 -04:00
});
2013-03-13 11:58:46 -04:00
2013-06-10 16:02:29 -04:00
asyncTest("CRUD object literal", 4, function() {
2013-05-23 17:14:30 -04:00
2013-06-10 16:02:29 -04:00
var key = 'type_asdf';
var data = {
name: 'testName',
type: 'testType'
};
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-06-10 16:02:29 -04:00
// delete
jsonDao.remove(key, function() {
2013-05-23 17:14:30 -04:00
2013-06-10 16:02:29 -04:00
// should read empty
jsonDao.read(key, function(lastRead) {
2013-08-23 10:47:36 -04:00
equal(lastRead, undefined, 'Delete');
2013-05-23 17:14:30 -04:00
2013-06-10 16:02:29 -04:00
start();
});
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
});