1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-10 19:25:03 -05:00
mail/test/unit/email-dao-test.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-03-13 11:58:46 -04:00
module("Email DAO");
var emaildao_test = {
user: 'test@atlasdev.onmicrosoft.com',
password: 'Xoza76645',
keySize: 128,
ivSize: 104
};
2013-04-01 17:23:25 -04:00
asyncTest("Init", 2, function() {
2013-03-13 11:58:46 -04:00
// init dependencies
var util = new app.crypto.Util(window, uuid);
var jsonDao = new app.dao.LawnchairDAO(window);
emaildao_test.crypto = new app.crypto.Crypto(window, util);
emaildao_test.storage = new app.dao.DeviceStorage(util, emaildao_test.crypto, jsonDao, null);
2013-03-13 11:58:46 -04:00
// cloud storage stub
var cloudstorageStub = {
2013-04-01 17:23:25 -04:00
getUserSecretKey: function(emailAdress, callback) {
callback();
}
2013-03-13 11:58:46 -04:00
};
emaildao_test.emailDao = new app.dao.EmailDAO(_, emaildao_test.crypto, emaildao_test.storage, cloudstorageStub);
2013-04-01 17:23:25 -04:00
2013-03-13 11:58:46 -04:00
// generate test data
emaildao_test.list = new TestData().getEmailCollection(100);
2013-04-01 17:23:25 -04:00
2013-03-13 11:58:46 -04:00
var account = new app.model.Account({
emailAddress: emaildao_test.user,
symKeySize: emaildao_test.keySize,
symIvSize: emaildao_test.ivSize
});
2013-04-01 17:23:25 -04:00
2013-03-13 11:58:46 -04:00
emaildao_test.emailDao.init(account, emaildao_test.password, function() {
equal(emaildao_test.emailDao.account.get('emailAddress'), emaildao_test.user, 'Email DAO Account');
2013-04-01 17:23:25 -04:00
2013-03-13 11:58:46 -04:00
// clear db before tests
jsonDao.clear(function(err) {
ok(!err, 'DB cleared. Error status: ' + err);
2013-04-01 17:23:25 -04:00
2013-03-13 11:58:46 -04:00
start();
});
});
});
2013-04-01 17:23:25 -04:00
asyncTest("Persist test emails", 2, function() {
2013-03-13 11:58:46 -04:00
emaildao_test.crypto.aesEncryptListForUser(emaildao_test.list.toJSON(), function(encryptedList) {
equal(encryptedList.length, emaildao_test.list.length, 'Encrypt list');
2013-04-01 17:23:25 -04:00
// add sent date to encrypted items
for (var i = 0; i < encryptedList.length; i++) {
encryptedList[i].sentDate = emaildao_test.list.at(i).get('sentDate');
}
2013-04-01 17:23:25 -04:00
2013-03-13 11:58:46 -04:00
emaildao_test.storage.storeEcryptedList(encryptedList, 'email_inbox', function() {
ok(true, 'Store encrypted list');
start();
});
2013-04-01 17:23:25 -04:00
});
2013-03-13 11:58:46 -04:00
});
asyncTest("List Email models", 1, function() {
emaildao_test.emailDao.listItems('inbox', 0, emaildao_test.list.length, function(collection) {
var gotten = collection.toJSON(),
reference = emaildao_test.list.toJSON();
2013-04-01 17:23:25 -04:00
deepEqual(gotten, reference, 'Compare collection');
2013-04-01 17:23:25 -04:00
2013-03-13 11:58:46 -04:00
start();
});
});
asyncTest("Get item", 1, function() {
var item = emaildao_test.list.toJSON()[0];
var mail = emaildao_test.emailDao.getItem('inbox', item.id);
deepEqual(mail.toJSON(), item, 'Item correct');
start();
2013-04-01 17:23:25 -04:00
});