1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 10:52:17 -05:00

fix tests

This commit is contained in:
Felix Hammerl 2014-02-06 11:55:24 +01:00
parent 20f36285b6
commit 6cd57fa0f6
8 changed files with 278 additions and 155 deletions

View File

@ -12,7 +12,7 @@
"dependencies": { "dependencies": {
"crypto-lib": "https://github.com/whiteout-io/crypto-lib/tarball/master", "crypto-lib": "https://github.com/whiteout-io/crypto-lib/tarball/master",
"imap-client": "https://github.com/whiteout-io/imap-client/tarball/dev/attachments", "imap-client": "https://github.com/whiteout-io/imap-client/tarball/dev/attachments",
"pgpmailer": "https://github.com/whiteout-io/pgpmailer/tarball/master", "pgpmailer": "https://github.com/whiteout-io/pgpmailer/tarball/dev/attachments",
"requirejs": "2.1.10" "requirejs": "2.1.10"
}, },
"devDependencies": { "devDependencies": {

View File

@ -96,7 +96,7 @@ define(function(require) {
self._outboxBusy = true; self._outboxBusy = true;
// get last item from outbox // get last item from outbox
self._emailDao.list(function(err, pending) { self._emailDao.listForOutbox(function(err, pending) {
if (err) { if (err) {
self._outboxBusy = false; self._outboxBusy = false;
callback(err); callback(err);

View File

@ -254,7 +254,7 @@ define(function(require) {
} }
// persist the email locally for later smtp transmission // persist the email locally for later smtp transmission
emailDao.store(email, function(err) { emailDao.storeForOutbox(email, function(err) {
if (err) { if (err) {
$scope.onError(err); $scope.onError(err);
return; return;

View File

@ -86,6 +86,9 @@ define(function(require) {
} }
}; };
// connect the pgpmailer
self._pgpmailerLogin();
// connect to newly created imap client // connect to newly created imap client
self._imapLogin(function(err) { self._imapLogin(function(err) {
if (err) { if (err) {
@ -964,38 +967,6 @@ define(function(require) {
// Internal API // Internal API
// //
// Encryption API
EmailDAO.prototype._encrypt = function(options, callback) {
var self = this,
pt = options.email.body;
options.keys = options.keys || [];
// get own public key so send message can be read
self._crypto.exportKeys(function(err, ownKeys) {
if (err) {
callback(err);
return;
}
// add own public key to receiver list
options.keys.push(ownKeys.publicKeyArmored);
// encrypt the email
self._crypto.encrypt(pt, options.keys, function(err, ct) {
if (err) {
callback(err);
return;
}
// replace plaintext body with pgp message
options.email.body = ct;
callback(null, options.email);
});
});
};
// Local Storage API // Local Storage API
EmailDAO.prototype._localListMessages = function(options, callback) { EmailDAO.prototype._localListMessages = function(options, callback) {
@ -1023,6 +994,16 @@ define(function(require) {
}; };
// PGP Mailer API
/**
* Login the smtp client
*/
EmailDAO.prototype._pgpmailerLogin = function() {
this._pgpMailer.login();
};
// IMAP API // IMAP API
/** /**
@ -1199,29 +1180,48 @@ define(function(require) {
} }
}; };
// to be removed and solved with IMAP! /**
EmailDAO.prototype.store = function(email, callback) { * Persists an email object for the outbox, encrypted with the user's public key
* @param {Object} email The email object
* @param {Function} callback(error) Invoked when the email was encrypted and persisted, contains information in case of an error
*/
EmailDAO.prototype.storeForOutbox = function(email, callback) {
var self = this, var self = this,
dbType = 'email_OUTBOX'; dbType = 'email_OUTBOX',
plaintext = email.body;
// give the email a random identifier (used for storage)
email.id = util.UUID(); email.id = util.UUID();
// encrypt // get own public key so send message can be read
self._encrypt({ self._crypto.exportKeys(function(err, ownKeys) {
email: email
}, function(err, email) {
if (err) { if (err) {
callback(err); callback(err);
return; return;
} }
// encrypt the email with the user's public key
self._crypto.encrypt(plaintext, [ownKeys.publicKeyArmored], function(err, ciphertext) {
if (err) {
callback(err);
return;
}
// replace plaintext body with pgp message
email.body = ciphertext;
// store to local storage // store to local storage
self._devicestorage.storeList([email], dbType, callback); self._devicestorage.storeList([email], dbType, callback);
});
}); });
}; };
// to be removed and solved with IMAP! /**
EmailDAO.prototype.list = function(callback) { * Reads and decrypts persisted email objects for the outbox
* @param {Function} callback(error, emails) Invoked when the email was encrypted and persisted, contains information in case of an error
*/
EmailDAO.prototype.listForOutbox = function(callback) {
var self = this, var self = this,
dbType = 'email_OUTBOX'; dbType = 'email_OUTBOX';

View File

@ -50,13 +50,20 @@ define(function(require) {
mocks.module('addaccounttest'); mocks.module('addaccounttest');
mocks.inject(function($controller, $rootScope, $location) { mocks.inject(function($controller, $rootScope, $location) {
location = $location; location = $location;
scope = $rootScope.$new();
scope.state = {};
sinon.stub(location, 'path', function(path) { sinon.stub(location, 'path', function(path) {
expect(path).to.equal('/login'); expect(path).to.equal('/login');
expect(fetchOAuthTokenStub.calledOnce).to.be.true; expect(fetchOAuthTokenStub.calledOnce).to.be.true;
location.path.restore();
scope.$apply.restore();
done(); done();
}); });
scope = $rootScope.$new();
scope.state = {}; sinon.stub(scope, '$apply', function() {});
ctrl = $controller(AddAccountCtrl, { ctrl = $controller(AddAccountCtrl, {
$location: location, $location: location,
$scope: scope $scope: scope

View File

@ -4,14 +4,15 @@ define(function(require) {
var EmailDAO = require('js/dao/email-dao'), var EmailDAO = require('js/dao/email-dao'),
KeychainDAO = require('js/dao/keychain-dao'), KeychainDAO = require('js/dao/keychain-dao'),
ImapClient = require('imap-client'), ImapClient = require('imap-client'),
SmtpClient = require('smtp-client'), PgpMailer = require('pgpmailer'),
PGP = require('js/crypto/pgp'), PGP = require('js/crypto/pgp'),
DeviceStorageDAO = require('js/dao/devicestorage-dao'), DeviceStorageDAO = require('js/dao/devicestorage-dao'),
str = require('js/app-config').string,
expect = chai.expect; expect = chai.expect;
describe('Email DAO unit tests', function() { describe('Email DAO unit tests', function() {
var dao, keychainStub, imapClientStub, smtpClientStub, pgpStub, devicestorageStub; var dao, keychainStub, imapClientStub, pgpMailerStub, pgpStub, devicestorageStub;
var emailAddress, passphrase, asymKeySize, mockkeyId, dummyEncryptedMail, var emailAddress, passphrase, asymKeySize, mockkeyId, dummyEncryptedMail,
dummyDecryptedMail, dummyLegacyDecryptedMail, mockKeyPair, account, publicKey, verificationMail, verificationUuid, dummyDecryptedMail, dummyLegacyDecryptedMail, mockKeyPair, account, publicKey, verificationMail, verificationUuid,
@ -124,7 +125,7 @@ define(function(require) {
keychainStub = sinon.createStubInstance(KeychainDAO); keychainStub = sinon.createStubInstance(KeychainDAO);
imapClientStub = sinon.createStubInstance(ImapClient); imapClientStub = sinon.createStubInstance(ImapClient);
smtpClientStub = sinon.createStubInstance(SmtpClient); pgpMailerStub = sinon.createStubInstance(PgpMailer);
pgpStub = sinon.createStubInstance(PGP); pgpStub = sinon.createStubInstance(PGP);
devicestorageStub = sinon.createStubInstance(DeviceStorageDAO); devicestorageStub = sinon.createStubInstance(DeviceStorageDAO);
@ -144,7 +145,7 @@ define(function(require) {
dao.onConnect({ dao.onConnect({
imapClient: imapClientStub, imapClient: imapClientStub,
smtpClient: smtpClientStub pgpMailer: pgpMailerStub
}, function(err) { }, function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(dao._account.online).to.be.true; expect(dao._account.online).to.be.true;
@ -289,11 +290,12 @@ define(function(require) {
}); });
describe('onConnect', function() { describe('onConnect', function() {
var imapLoginStub, imapListFoldersStub; var imapLoginStub, imapListFoldersStub, pgpmailerLoginStub;
beforeEach(function(done) { beforeEach(function(done) {
// imap login // imap login
imapLoginStub = sinon.stub(dao, '_imapLogin'); imapLoginStub = sinon.stub(dao, '_imapLogin');
pgpmailerLoginStub = sinon.stub(dao, '_pgpmailerLogin');
imapListFoldersStub = sinon.stub(dao, '_imapListFolders'); imapListFoldersStub = sinon.stub(dao, '_imapListFolders');
dao.onDisconnect(null, function(err) { dao.onDisconnect(null, function(err) {
@ -307,17 +309,20 @@ define(function(require) {
afterEach(function() { afterEach(function() {
imapLoginStub.restore(); imapLoginStub.restore();
pgpmailerLoginStub.restore();
imapListFoldersStub.restore(); imapListFoldersStub.restore();
}); });
it('should fail due to error in imap login', function(done) { it('should fail due to error in imap login', function(done) {
imapLoginStub.yields({}); imapLoginStub.yields({});
pgpmailerLoginStub.returns();
dao.onConnect({ dao.onConnect({
imapClient: imapClientStub, imapClient: imapClientStub,
smtpClient: smtpClientStub pgpMailer: pgpMailerStub
}, function(err) { }, function(err) {
expect(err).to.exist; expect(err).to.exist;
expect(pgpmailerLoginStub.calledOnce).to.be.true;
expect(imapLoginStub.calledOnce).to.be.true; expect(imapLoginStub.calledOnce).to.be.true;
expect(dao._account.online).to.be.false; expect(dao._account.online).to.be.false;
done(); done();
@ -327,10 +332,11 @@ define(function(require) {
it('should work when folder already initiated', function(done) { it('should work when folder already initiated', function(done) {
dao._account.folders = []; dao._account.folders = [];
imapLoginStub.yields(); imapLoginStub.yields();
pgpmailerLoginStub.returns();
dao.onConnect({ dao.onConnect({
imapClient: imapClientStub, imapClient: imapClientStub,
smtpClient: smtpClientStub pgpMailer: pgpMailerStub
}, function(err) { }, function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(dao._account.online).to.be.true; expect(dao._account.online).to.be.true;
@ -343,11 +349,12 @@ define(function(require) {
it('should work when folder not yet initiated', function(done) { it('should work when folder not yet initiated', function(done) {
var folders = []; var folders = [];
imapLoginStub.yields(); imapLoginStub.yields();
pgpmailerLoginStub.returns();
imapListFoldersStub.yields(null, folders); imapListFoldersStub.yields(null, folders);
dao.onConnect({ dao.onConnect({
imapClient: imapClientStub, imapClient: imapClientStub,
smtpClient: smtpClientStub pgpMailer: pgpMailerStub
}, function(err) { }, function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(dao._account.online).to.be.true; expect(dao._account.online).to.be.true;
@ -498,6 +505,20 @@ define(function(require) {
}); });
}); });
describe('_pgpmailerLogin', function() {
it('should work', function() {
// called once in onConnect
expect(pgpMailerStub.login.calledOnce).to.be.true;
pgpMailerStub.login.returns();
dao._pgpmailerLogin();
expect(pgpMailerStub.login.calledTwice).to.be.true;
});
});
describe('_imapLogin', function() { describe('_imapLogin', function() {
it('should fail when disconnected', function(done) { it('should fail when disconnected', function(done) {
dao.onDisconnect(null, function(err) { dao.onDisconnect(null, function(err) {
@ -2459,13 +2480,27 @@ define(function(require) {
describe('sendPlaintext', function() { describe('sendPlaintext', function() {
it('should work', function(done) { it('should work', function(done) {
smtpClientStub.send.withArgs(dummyEncryptedMail).yields(); pgpMailerStub.send.withArgs({
mail: dummyEncryptedMail
}).yields();
dao.sendPlaintext({ dao.sendPlaintext({
email: dummyEncryptedMail email: dummyEncryptedMail
}, function(err) { }, function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(smtpClientStub.send.calledOnce).to.be.true; expect(pgpMailerStub.send.calledOnce).to.be.true;
done();
});
});
it('should not work when pgpmailer fails', function(done) {
pgpMailerStub.send.yields({});
dao.sendPlaintext({
email: dummyEncryptedMail
}, function(err) {
expect(err).to.exist;
expect(pgpMailerStub.send.calledOnce).to.be.true;
done(); done();
}); });
}); });
@ -2473,101 +2508,76 @@ define(function(require) {
describe('sendEncrypted', function() { describe('sendEncrypted', function() {
it('should work', function(done) { it('should work', function(done) {
var encryptStub = sinon.stub(dao, '_encrypt').yields(null, {});
smtpClientStub.send.yields();
dao.sendEncrypted({
email: dummyDecryptedMail
}, function(err) {
expect(err).to.not.exist;
expect(encryptStub.calledOnce).to.be.true;
expect(smtpClientStub.send.calledOnce).to.be.true;
done();
});
});
it('should not work when encryption fails', function(done) {
var encryptStub = sinon.stub(dao, '_encrypt').yields({});
dao.sendEncrypted({
email: dummyDecryptedMail
}, function(err) {
expect(err).to.exist;
expect(encryptStub.calledOnce).to.be.true;
expect(smtpClientStub.send.called).to.be.false;
done();
});
});
it('should not work without recipients', function(done) {
var encryptStub = sinon.stub(dao, '_encrypt');
delete dummyDecryptedMail.to;
dao.sendEncrypted({
email: dummyDecryptedMail
}, function(err) {
expect(err).to.exist;
expect(encryptStub.called).to.be.false;
expect(smtpClientStub.send.called).to.be.false;
done();
});
});
it('should not work with without sender', function(done) {
var encryptStub = sinon.stub(dao, '_encrypt');
delete dummyDecryptedMail.from;
dao.sendEncrypted({
email: dummyDecryptedMail
}, function(err) {
expect(err).to.exist;
expect(encryptStub.called).to.be.false;
expect(smtpClientStub.send.called).to.be.false;
done();
});
});
});
describe('_encrypt', function() {
it('should work without attachments', function(done) {
var ct = 'OMGSOENCRYPTED';
pgpStub.exportKeys.yields(null, { pgpStub.exportKeys.yields(null, {
privateKeyArmored: mockKeyPair.privateKey.encryptedKey, privateKeyArmored: mockKeyPair.privateKey.encryptedKey,
publicKeyArmored: mockKeyPair.publicKey.publicKey publicKeyArmored: mockKeyPair.publicKey.publicKey
}); });
pgpStub.encrypt.yields(null, ct);
dao._encrypt({ pgpMailerStub.send.withArgs({
encrypt: true,
cleartextMessage: str.message,
mail: dummyDecryptedMail,
publicKeysArmored: dummyDecryptedMail.receiverKeys
}).yields();
dao.sendEncrypted({
email: dummyDecryptedMail email: dummyDecryptedMail
}, function(err) { }, function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(pgpStub.exportKeys.calledOnce).to.be.true; expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpStub.encrypt.calledOnce).to.be.true; expect(pgpMailerStub.send.calledOnce).to.be.true;
expect(dummyDecryptedMail.body).to.contain(ct);
done();
});
});
it('should not work when pgpmailer fails', function(done) {
pgpStub.exportKeys.yields(null, {
privateKeyArmored: mockKeyPair.privateKey.encryptedKey,
publicKeyArmored: mockKeyPair.publicKey.publicKey
});
pgpMailerStub.send.yields({});
dao.sendEncrypted({
email: dummyDecryptedMail
}, function(err) {
expect(err).to.exist;
expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpMailerStub.send.calledOnce).to.be.true;
done();
});
});
it('should not work when sender key export fails', function(done) {
pgpStub.exportKeys.yields({});
dao.sendEncrypted({
email: dummyDecryptedMail
}, function(err) {
expect(err).to.exist;
expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpMailerStub.send.calledOnce).to.be.false;
done(); done();
}); });
}); });
}); });
describe('store', function() { describe('storeForOutbox', function() {
it('should work', function(done) { it('should work', function(done) {
pgpStub.exportKeys.yields(null, { var key = 'omgsocrypto';
publicKeyArmored: 'omgsocrypto'
});
pgpStub.encrypt.yields(null, 'asdfasfd');
devicestorageStub.storeList.yields();
dao.store(dummyDecryptedMail, function(err) { pgpStub.exportKeys.yields(null, {
publicKeyArmored: key
});
pgpStub.encrypt.withArgs(dummyDecryptedMail.body, [key]).yields(null, 'asdfasfd');
devicestorageStub.storeList.withArgs([dummyDecryptedMail], 'email_OUTBOX').yields();
dao.storeForOutbox(dummyDecryptedMail, function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(pgpStub.exportKeys.calledOnce).to.be.true; expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpStub.encrypt.calledOnce).to.be.true; expect(pgpStub.encrypt.calledOnce).to.be.true;
expect(devicestorageStub.storeList.calledOnce).to.be.true; expect(devicestorageStub.storeList.calledOnce).to.be.true;
@ -2575,17 +2585,72 @@ define(function(require) {
done(); done();
}); });
}); });
});
describe('list', function() { it('should work when store fails', function(done) {
it('should work', function(done) { var key = 'omgsocrypto';
devicestorageStub.listItems.yields(null, [dummyEncryptedMail]);
pgpStub.exportKeys.yields(null, { pgpStub.exportKeys.yields(null, {
publicKeyArmored: 'omgsocrypto' publicKeyArmored: key
}); });
pgpStub.decrypt.yields(null, dummyDecryptedMail.body); pgpStub.encrypt.yields(null, 'asdfasfd');
devicestorageStub.storeList.yields({});
dao.list(function(err, mails) { dao.storeForOutbox(dummyDecryptedMail, function(err) {
expect(err).to.exist;
expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpStub.encrypt.calledOnce).to.be.true;
expect(devicestorageStub.storeList.calledOnce).to.be.true;
done();
});
});
it('should work when encryption fails', function(done) {
var key = 'omgsocrypto';
pgpStub.exportKeys.yields(null, {
publicKeyArmored: key
});
pgpStub.encrypt.yields({});
dao.storeForOutbox(dummyDecryptedMail, function(err) {
expect(err).to.exist;
expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpStub.encrypt.calledOnce).to.be.true;
expect(devicestorageStub.storeList.called).to.be.false;
done();
});
});
it('should work when key export fails', function(done) {
pgpStub.exportKeys.yields({});
dao.storeForOutbox(dummyDecryptedMail, function(err) {
expect(err).to.exist;
expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpStub.encrypt.called).to.be.false;
expect(devicestorageStub.storeList.called).to.be.false;
done();
});
});
});
describe('listForOutbox', function() {
it('should work', function(done) {
var key = 'omgsocrypto';
devicestorageStub.listItems.withArgs('email_OUTBOX', 0, null).yields(null, [dummyEncryptedMail]);
pgpStub.exportKeys.yields(null, {
publicKeyArmored: key
});
pgpStub.decrypt.withArgs(dummyEncryptedMail.body, key).yields(null, dummyDecryptedMail.body);
dao.listForOutbox(function(err, mails) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(devicestorageStub.listItems.calledOnce).to.be.true; expect(devicestorageStub.listItems.calledOnce).to.be.true;
@ -2593,12 +2658,63 @@ define(function(require) {
expect(pgpStub.decrypt.calledOnce).to.be.true; expect(pgpStub.decrypt.calledOnce).to.be.true;
expect(mails.length).to.equal(1); expect(mails.length).to.equal(1);
expect(mails[0].body).to.equal(dummyDecryptedMail.body); expect(mails[0].body).to.equal(dummyDecryptedMail.body);
expect(mails[0].subject).to.equal(dummyDecryptedMail.subject);
done();
});
});
it('should not work when decryption fails', function(done) {
var key = 'omgsocrypto',
errMsg = 'THIS IS AN ERROR!';
devicestorageStub.listItems.yields(null, [dummyEncryptedMail]);
pgpStub.exportKeys.yields(null, {
publicKeyArmored: key
});
pgpStub.decrypt.yields({errMsg: errMsg});
dao.listForOutbox(function(err, mails) {
expect(err).to.not.exist;
expect(mails[0].body).to.equal(errMsg);
expect(devicestorageStub.listItems.calledOnce).to.be.true;
expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpStub.decrypt.calledOnce).to.be.true;
done();
});
});
it('should not work when key export fails', function(done) {
devicestorageStub.listItems.yields(null, [dummyEncryptedMail]);
pgpStub.exportKeys.yields({});
dao.listForOutbox(function(err, mails) {
expect(err).to.exist;
expect(mails).to.not.exist;
expect(devicestorageStub.listItems.calledOnce).to.be.true;
expect(pgpStub.exportKeys.calledOnce).to.be.true;
expect(pgpStub.decrypt.called).to.be.false;
done();
});
});
it('should not work when list from storage fails', function(done) {
devicestorageStub.listItems.yields({});
dao.listForOutbox(function(err, mails) {
expect(err).to.exist;
expect(mails).to.not.exist;
expect(devicestorageStub.listItems.calledOnce).to.be.true;
expect(pgpStub.exportKeys.called).to.be.false;
expect(pgpStub.decrypt.called).to.be.false;
done(); done();
}); });
}); });
}); });
}); });
}); });

View File

@ -85,7 +85,7 @@ define(function(require) {
}; };
dummyMails = [member, invited, notinvited]; dummyMails = [member, invited, notinvited];
emailDaoStub.list.yieldsAsync(null, dummyMails); emailDaoStub.listForOutbox.yieldsAsync(null, dummyMails);
emailDaoStub.sendEncrypted.withArgs(sinon.match(function(opts) { emailDaoStub.sendEncrypted.withArgs(sinon.match(function(opts) {
return typeof opts.email !== 'undefined' && opts.email.to.address === member.to.address; return typeof opts.email !== 'undefined' && opts.email.to.address === member.to.address;
})).yieldsAsync(); })).yieldsAsync();
@ -111,7 +111,7 @@ define(function(require) {
expect(outbox._outboxBusy).to.be.false; expect(outbox._outboxBusy).to.be.false;
expect(unsentCount).to.equal(2); expect(unsentCount).to.equal(2);
expect(emailDaoStub.list.callCount).to.equal(1); expect(emailDaoStub.listForOutbox.callCount).to.equal(1);
expect(emailDaoStub.sendEncrypted.callCount).to.equal(1); expect(emailDaoStub.sendEncrypted.callCount).to.equal(1);
expect(emailDaoStub.sendPlaintext.callCount).to.equal(1); expect(emailDaoStub.sendPlaintext.callCount).to.equal(1);
expect(devicestorageStub.removeList.callCount).to.equal(1); expect(devicestorageStub.removeList.callCount).to.equal(1);
@ -136,7 +136,7 @@ define(function(require) {
it('should not process outbox in offline mode', function(done) { it('should not process outbox in offline mode', function(done) {
emailDaoStub._account.online = false; emailDaoStub._account.online = false;
emailDaoStub.list.yieldsAsync(null, [{ emailDaoStub.listForOutbox.yieldsAsync(null, [{
id: '123', id: '123',
to: [{ to: [{
name: 'member', name: 'member',
@ -147,7 +147,7 @@ define(function(require) {
outbox._processOutbox(function(err, count) { outbox._processOutbox(function(err, count) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(count).to.equal(1); expect(count).to.equal(1);
expect(emailDaoStub.list.callCount).to.equal(1); expect(emailDaoStub.listForOutbox.callCount).to.equal(1);
expect(outbox._outboxBusy).to.be.false; expect(outbox._outboxBusy).to.be.false;
done(); done();
}); });

View File

@ -277,13 +277,13 @@ define(function(require) {
scope.onError = function(err) { scope.onError = function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(scope.state.writer.open).to.be.false; expect(scope.state.writer.open).to.be.false;
expect(emailDaoMock.store.calledOnce).to.be.true; expect(emailDaoMock.storeForOutbox.calledOnce).to.be.true;
expect(emailDaoMock.sync.calledOnce).to.be.true; expect(emailDaoMock.sync.calledOnce).to.be.true;
done(); done();
}; };
emailDaoMock.store.yields(); emailDaoMock.storeForOutbox.yields();
emailDaoMock.sync.yields({ emailDaoMock.sync.yields({
code: 42 code: 42
}); });
@ -310,13 +310,13 @@ define(function(require) {
scope.onError = function(err) { scope.onError = function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(scope.state.writer.open).to.be.false; expect(scope.state.writer.open).to.be.false;
expect(emailDaoMock.store.calledOnce).to.be.true; expect(emailDaoMock.storeForOutbox.calledOnce).to.be.true;
expect(emailDaoMock.sync.calledOnce).to.be.true; expect(emailDaoMock.sync.calledOnce).to.be.true;
done(); done();
}; };
emailDaoMock.store.yields(); emailDaoMock.storeForOutbox.yields();
emailDaoMock.sync.yields(); emailDaoMock.sync.yields();
scope.state.writer.write(re); scope.state.writer.write(re);
@ -341,13 +341,13 @@ define(function(require) {
scope.onError = function(err) { scope.onError = function(err) {
expect(err).to.exist; expect(err).to.exist;
expect(scope.state.writer.open).to.be.false; expect(scope.state.writer.open).to.be.false;
expect(emailDaoMock.store.calledOnce).to.be.true; expect(emailDaoMock.storeForOutbox.calledOnce).to.be.true;
expect(emailDaoMock.sync.calledOnce).to.be.true; expect(emailDaoMock.sync.calledOnce).to.be.true;
done(); done();
}; };
emailDaoMock.store.yields(); emailDaoMock.storeForOutbox.yields();
emailDaoMock.sync.yields({}); emailDaoMock.sync.yields({});
scope.state.writer.write(re); scope.state.writer.write(re);
@ -367,7 +367,7 @@ define(function(require) {
scope.subject = 'yaddablabla'; scope.subject = 'yaddablabla';
scope.toKey = 'Public Key'; scope.toKey = 'Public Key';
emailDaoMock.store.withArgs(sinon.match(function(mail) { emailDaoMock.storeForOutbox.withArgs(sinon.match(function(mail) {
return mail.from[0].address === emailAddress && mail.to.length === 1 && mail.receiverKeys.length === 1; return mail.from[0].address === emailAddress && mail.to.length === 1 && mail.receiverKeys.length === 1;
})).yields({ })).yields({
errMsg: 'snafu' errMsg: 'snafu'
@ -376,7 +376,7 @@ define(function(require) {
scope.onError = function(err) { scope.onError = function(err) {
expect(err).to.exist; expect(err).to.exist;
expect(scope.state.writer.open).to.be.true; expect(scope.state.writer.open).to.be.true;
expect(emailDaoMock.store.calledOnce).to.be.true; expect(emailDaoMock.storeForOutbox.calledOnce).to.be.true;
done(); done();
}; };
scope.sendToOutbox(); scope.sendToOutbox();