From 04a3ab2a34dec953ca468c428e6a70c23e92c17e Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 3 Jun 2013 04:26:17 +0200 Subject: [PATCH] different lawnchair for each user --- src/js/dao/lawnchair-dao.js | 20 ++++++++++++++------ test/integration/cloudstorage-dao-test.js | 6 ++++-- test/unit/devicestorage-test.js | 5 ++++- test/unit/email-dao-test.js | 1 + test/unit/keychain-dao-test.js | 6 ++++-- test/unit/lawnchair-dao-test.js | 5 ++++- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/js/dao/lawnchair-dao.js b/src/js/dao/lawnchair-dao.js index 5ec3ba8..bc07b88 100644 --- a/src/js/dao/lawnchair-dao.js +++ b/src/js/dao/lawnchair-dao.js @@ -4,13 +4,21 @@ app.dao.LawnchairDAO = function(Lawnchair) { 'use strict'; - var db = new Lawnchair({ - name: 'dataStore' - }, function(lc) { - if (!lc) { - throw new Error('Lawnchair init failed!'); + var db; + + this.init = function(dbName) { + if (!dbName) { + throw new Error('Lawnchair DB name must be specified!'); } - }); + + db = new Lawnchair({ + name: dbName + }, function(lc) { + if (!lc) { + throw new Error('Lawnchair init failed!'); + } + }); + }; /** * Create or update an object diff --git a/test/integration/cloudstorage-dao-test.js b/test/integration/cloudstorage-dao-test.js index 5aa0aa4..854d10c 100644 --- a/test/integration/cloudstorage-dao-test.js +++ b/test/integration/cloudstorage-dao-test.js @@ -34,6 +34,7 @@ asyncTest("Init", 1, function() { // init dependencies cloudstoragedao_test.util = new cryptoLib.Util(window, uuid); var jsonDao = new app.dao.LawnchairDAO(Lawnchair); + jsonDao.init(cloudstoragedao_test.user); cloudstoragedao_test.crypto = new app.crypto.Crypto(window, cloudstoragedao_test.util); cloudstoragedao_test.storage = new app.dao.DeviceStorage(cloudstoragedao_test.util, cloudstoragedao_test.crypto, jsonDao, null); cloudstoragedao_test.cloudstorage = new app.dao.CloudStorage(window, $); @@ -121,8 +122,9 @@ asyncTest("Get User Keypair", 2, function() { asyncTest("Get Public Keys", 2, function() { var pubkeyIds = [{ - _id: cloudstoragedao_test.keypair.publicKey._id - }]; + _id: cloudstoragedao_test.keypair.publicKey._id + } + ]; cloudstoragedao_test.keychain.getPublicKeys(pubkeyIds, function(err, pubkeys) { ok(!err); deepEqual(pubkeys[0], cloudstoragedao_test.keypair.publicKey, "Fetch public key"); diff --git a/test/unit/devicestorage-test.js b/test/unit/devicestorage-test.js index 3cecb69..927f902 100644 --- a/test/unit/devicestorage-test.js +++ b/test/unit/devicestorage-test.js @@ -12,6 +12,7 @@ asyncTest("Init", 3, function() { // init dependencies devicestorage_test.util = new cryptoLib.Util(window, uuid); devicestorage_test.jsonDao = new app.dao.LawnchairDAO(Lawnchair); + devicestorage_test.jsonDao.init(devicestorage_test.user); devicestorage_test.crypto = new app.crypto.Crypto(window, devicestorage_test.util); devicestorage_test.storage = new app.dao.DeviceStorage(devicestorage_test.util, devicestorage_test.crypto, devicestorage_test.jsonDao, null); ok(devicestorage_test.storage, 'DeviceStorageDAO'); @@ -47,7 +48,9 @@ asyncTest("Encrypt list for user", 2, function() { equal(encryptedList.length, devicestorage_test.list.length, 'Encrypt list'); encryptedList.forEach(function(i) { - i.sentDate = _.findWhere(devicestorage_test.list, {id: i.id}).sentDate; + i.sentDate = _.findWhere(devicestorage_test.list, { + id: i.id + }).sentDate; }); devicestorage_test.encryptedList = encryptedList; diff --git a/test/unit/email-dao-test.js b/test/unit/email-dao-test.js index bf79d70..fe96c82 100644 --- a/test/unit/email-dao-test.js +++ b/test/unit/email-dao-test.js @@ -12,6 +12,7 @@ asyncTest("Init", 3, function() { // init dependencies var util = new cryptoLib.Util(window, uuid); var jsonDao = new app.dao.LawnchairDAO(Lawnchair); + jsonDao.init(emaildao_test.user); emaildao_test.crypto = new app.crypto.Crypto(window, util); emaildao_test.storage = new app.dao.DeviceStorage(util, emaildao_test.crypto, jsonDao, null); // cloud storage stub diff --git a/test/unit/keychain-dao-test.js b/test/unit/keychain-dao-test.js index 486cdfc..e6ac566 100644 --- a/test/unit/keychain-dao-test.js +++ b/test/unit/keychain-dao-test.js @@ -12,6 +12,7 @@ asyncTest("Init", 2, function() { // init dependencies var util = new cryptoLib.Util(window, uuid); var jsonDao = new app.dao.LawnchairDAO(Lawnchair); + jsonDao.init(keychaindao_test.user); var crypto = new app.crypto.Crypto(window, util); // cloud storage stub var cloudstorageStub = { @@ -68,8 +69,9 @@ asyncTest("Get User Keypair", 2, function() { asyncTest("Get Public Keys", 2, function() { var pubkeyIds = [{ - _id: keychaindao_test.keypair.publicKey._id - }]; + _id: keychaindao_test.keypair.publicKey._id + } + ]; keychaindao_test.keychainDao.getPublicKeys(pubkeyIds, function(err, pubkeys) { ok(!err); deepEqual(pubkeys[0], keychaindao_test.keypair.publicKey, "Fetch public key"); diff --git a/test/unit/lawnchair-dao-test.js b/test/unit/lawnchair-dao-test.js index 945bab1..0d1576b 100644 --- a/test/unit/lawnchair-dao-test.js +++ b/test/unit/lawnchair-dao-test.js @@ -1,10 +1,13 @@ module("Lawnchair DAO"); -var lawnchairdao_test = {}; +var lawnchairdao_test = { + user: 'lawnchair@test.com' +}; asyncTest("Init", 2, function() { // init dependencies lawnchairdao_test.jsonDao = new app.dao.LawnchairDAO(Lawnchair); + lawnchairdao_test.jsonDao.init(lawnchairdao_test.user); ok(lawnchairdao_test.jsonDao, 'LanwchairDAO'); // clear db before test