mirror of
https://github.com/moparisthebest/mail
synced 2024-11-21 16:35:04 -05:00
Fix conrtoller unit tests
This commit is contained in:
parent
383761e6cb
commit
6a8c24d813
@ -85,7 +85,6 @@ var ContactsCtrl = function($scope, $q, keychain, pgp, dialog) {
|
||||
return $scope.listKeys();
|
||||
}).catch(dialog.error);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
module.exports = ContactsCtrl;
|
@ -52,6 +52,9 @@ var PrivateKeyUploadCtrl = function($scope, $q, keychain, pgp, dialog, auth) {
|
||||
keyId: keyParams._id
|
||||
});
|
||||
|
||||
}).then(function(privateKeySynced) {
|
||||
return privateKeySynced ? privateKeySynced : undefined;
|
||||
|
||||
}).catch(dialog.error);
|
||||
};
|
||||
|
||||
|
@ -43,6 +43,7 @@ describe('Account Controller unit test', function() {
|
||||
scope.state = {};
|
||||
accountCtrl = $controller(AccountCtrl, {
|
||||
$scope: scope,
|
||||
$q: window.qMock,
|
||||
auth: authStub,
|
||||
keychain: keychainStub,
|
||||
pgp: pgpStub,
|
||||
@ -63,8 +64,8 @@ describe('Account Controller unit test', function() {
|
||||
});
|
||||
});
|
||||
describe('export to key file', function() {
|
||||
it('should work', function() {
|
||||
keychainStub.getUserKeyPair.withArgs(emailAddress).yields(null, {
|
||||
it('should work', function(done) {
|
||||
keychainStub.getUserKeyPair.withArgs(emailAddress).returns(resolves({
|
||||
publicKey: {
|
||||
_id: dummyKeyId,
|
||||
publicKey: 'a'
|
||||
@ -72,24 +73,26 @@ describe('Account Controller unit test', function() {
|
||||
privateKey: {
|
||||
encryptedKey: 'b'
|
||||
}
|
||||
});
|
||||
}));
|
||||
downloadStub.createDownload.withArgs(sinon.match(function(arg) {
|
||||
return arg.content === 'a\r\nb' && arg.filename === 'whiteout_mail_' + emailAddress + '_' + expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
||||
})).returns();
|
||||
|
||||
scope.exportKeyFile();
|
||||
|
||||
expect(scope.state.lightbox).to.equal(undefined);
|
||||
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
||||
expect(downloadStub.createDownload.calledOnce).to.be.true;
|
||||
scope.exportKeyFile().then(function() {
|
||||
expect(scope.state.lightbox).to.equal(undefined);
|
||||
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
||||
expect(downloadStub.createDownload.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not work when key export failed', function() {
|
||||
keychainStub.getUserKeyPair.yields(new Error());
|
||||
it('should not work when key export failed', function(done) {
|
||||
keychainStub.getUserKeyPair.returns(rejects(new Error()));
|
||||
|
||||
scope.exportKeyFile();
|
||||
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
scope.exportKeyFile().then(function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -33,6 +33,7 @@ describe('Action Bar Controller unit test', function() {
|
||||
|
||||
actionBarCtrl = $controller(ActionBarCtrl, {
|
||||
$scope: scope,
|
||||
$q: window.qMock,
|
||||
email: emailMock,
|
||||
dialog: dialogMock,
|
||||
status: statusMock
|
||||
@ -47,13 +48,14 @@ describe('Action Bar Controller unit test', function() {
|
||||
scope.deleteMessage();
|
||||
});
|
||||
|
||||
it('should delete the selected mail', function() {
|
||||
emailMock.deleteMessage.yields();
|
||||
it('should delete the selected mail', function(done) {
|
||||
emailMock.deleteMessage.returns(resolves());
|
||||
|
||||
scope.deleteMessage({});
|
||||
|
||||
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
||||
expect(emailMock.deleteMessage.calledOnce).to.be.true;
|
||||
scope.deleteMessage({}).then(function() {
|
||||
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
||||
expect(emailMock.deleteMessage.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -79,13 +81,14 @@ describe('Action Bar Controller unit test', function() {
|
||||
scope.moveMessage();
|
||||
});
|
||||
|
||||
it('should move the selected mail', function() {
|
||||
emailMock.moveMessage.yields();
|
||||
it('should move the selected mail', function(done) {
|
||||
emailMock.moveMessage.returns(resolves());
|
||||
|
||||
scope.moveMessage({}, {});
|
||||
|
||||
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
||||
expect(emailMock.moveMessage.calledOnce).to.be.true;
|
||||
scope.moveMessage({}, {}).then(function() {
|
||||
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
||||
expect(emailMock.moveMessage.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -144,22 +147,24 @@ describe('Action Bar Controller unit test', function() {
|
||||
}, true);
|
||||
});
|
||||
|
||||
it('should mark the selected mail', function() {
|
||||
emailMock.setFlags.yields();
|
||||
it('should mark the selected mail', function(done) {
|
||||
emailMock.setFlags.returns(resolves());
|
||||
|
||||
scope.markMessage({}, true);
|
||||
|
||||
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
||||
expect(emailMock.setFlags.calledOnce).to.be.true;
|
||||
scope.markMessage({}, true).then(function() {
|
||||
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
||||
expect(emailMock.setFlags.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark the selected mail and close read mode', function() {
|
||||
emailMock.setFlags.yields();
|
||||
it('should mark the selected mail and close read mode', function(done) {
|
||||
emailMock.setFlags.returns(resolves());
|
||||
|
||||
scope.markMessage({}, true, true);
|
||||
|
||||
expect(statusMock.setReading.calledOnce).to.be.false;
|
||||
expect(emailMock.setFlags.calledOnce).to.be.true;
|
||||
scope.markMessage({}, true, true).then(function() {
|
||||
expect(statusMock.setReading.calledOnce).to.be.false;
|
||||
expect(emailMock.setFlags.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -196,11 +201,11 @@ describe('Action Bar Controller unit test', function() {
|
||||
});
|
||||
|
||||
it('should flag the selected mail', function() {
|
||||
emailMock.setFlags.yields();
|
||||
emailMock.setFlags.returns(resolves());
|
||||
|
||||
scope.flagMessage({}, true);
|
||||
|
||||
expect(emailMock.setFlags.calledOnce).to.be.true;
|
||||
scope.flagMessage({}, true).then(function() {
|
||||
expect(emailMock.setFlags.calledOnce).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -20,6 +20,7 @@ describe('Contacts Controller unit test', function() {
|
||||
scope.state = {};
|
||||
contactsCtrl = $controller(ContactsCtrl, {
|
||||
$scope: scope,
|
||||
$q: window.qMock,
|
||||
keychain: keychainStub,
|
||||
pgp: pgpStub,
|
||||
dialog: dialogStub
|
||||
@ -36,28 +37,30 @@ describe('Contacts Controller unit test', function() {
|
||||
});
|
||||
|
||||
describe('listKeys', function() {
|
||||
it('should fail due to error in keychain.listLocalPublicKeys', function() {
|
||||
keychainStub.listLocalPublicKeys.yields(42);
|
||||
it('should fail due to error in keychain.listLocalPublicKeys', function(done) {
|
||||
keychainStub.listLocalPublicKeys.returns(rejects(42));
|
||||
|
||||
scope.listKeys();
|
||||
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
scope.listKeys().then(function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work', function() {
|
||||
keychainStub.listLocalPublicKeys.yields(null, [{
|
||||
it('should work', function(done) {
|
||||
keychainStub.listLocalPublicKeys.returns(resolves([{
|
||||
_id: '12345'
|
||||
}]);
|
||||
}]));
|
||||
pgpStub.getKeyParams.returns({
|
||||
fingerprint: 'asdf'
|
||||
});
|
||||
|
||||
expect(scope.keys).to.not.exist;
|
||||
scope.listKeys();
|
||||
|
||||
expect(scope.keys.length).to.equal(1);
|
||||
expect(scope.keys[0]._id).to.equal('12345');
|
||||
expect(scope.keys[0].fingerprint).to.equal('asdf');
|
||||
scope.listKeys().then(function() {
|
||||
expect(scope.keys.length).to.equal(1);
|
||||
expect(scope.keys[0]._id).to.equal('12345');
|
||||
expect(scope.keys[0].fingerprint).to.equal('asdf');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -89,13 +92,13 @@ describe('Contacts Controller unit test', function() {
|
||||
userIds: [],
|
||||
publicKey: '-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||
imported: true
|
||||
}).yields();
|
||||
}).returns(resolves());
|
||||
|
||||
scope.listKeys = function() {
|
||||
scope.listKeys = function() {};
|
||||
|
||||
scope.importKey(keyArmored).then(function() {
|
||||
done();
|
||||
};
|
||||
|
||||
scope.importKey(keyArmored);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail due to invalid armored key', function() {
|
||||
@ -115,7 +118,7 @@ describe('Contacts Controller unit test', function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
});
|
||||
|
||||
it('should fail due to error in keychain.saveLocalPublicKey', function() {
|
||||
it('should fail due to error in keychain.saveLocalPublicKey', function(done) {
|
||||
var keyArmored = '-----BEGIN PGP PUBLIC KEY BLOCK-----';
|
||||
|
||||
pgpStub.getKeyParams.returns({
|
||||
@ -123,11 +126,12 @@ describe('Contacts Controller unit test', function() {
|
||||
userId: 'max@example.com'
|
||||
});
|
||||
|
||||
keychainStub.saveLocalPublicKey.yields(42);
|
||||
keychainStub.saveLocalPublicKey.returns(rejects(42));
|
||||
|
||||
scope.importKey(keyArmored);
|
||||
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
scope.importKey(keyArmored).then(function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -137,25 +141,26 @@ describe('Contacts Controller unit test', function() {
|
||||
_id: '12345'
|
||||
};
|
||||
|
||||
keychainStub.removeLocalPublicKey.withArgs('12345').yields();
|
||||
keychainStub.removeLocalPublicKey.withArgs('12345').returns(resolves());
|
||||
|
||||
scope.listKeys = function() {
|
||||
scope.listKeys = function() {};
|
||||
|
||||
scope.removeKey(key).then(function() {
|
||||
done();
|
||||
};
|
||||
|
||||
scope.removeKey(key);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail due to error in keychain.removeLocalPublicKey', function() {
|
||||
it('should fail due to error in keychain.removeLocalPublicKey', function(done) {
|
||||
var key = {
|
||||
_id: '12345'
|
||||
};
|
||||
|
||||
keychainStub.removeLocalPublicKey.withArgs('12345').yields(42);
|
||||
keychainStub.removeLocalPublicKey.withArgs('12345').returns(rejects(42));
|
||||
|
||||
scope.removeKey(key);
|
||||
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
scope.removeKey(key).then(function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -44,6 +44,7 @@ describe('Mail List controller unit test', function() {
|
||||
ctrl = $controller(MailListCtrl, {
|
||||
$scope: scope,
|
||||
$location: location,
|
||||
$q: window.qMock,
|
||||
status: statusMock,
|
||||
notification: notificationMock,
|
||||
email: emailMock,
|
||||
@ -207,15 +208,17 @@ describe('Mail List controller unit test', function() {
|
||||
});
|
||||
|
||||
describe('getBody', function() {
|
||||
it('should get the mail content', function() {
|
||||
it('should get the mail content', function(done) {
|
||||
scope.state.nav = {
|
||||
currentFolder: {
|
||||
type: 'asd',
|
||||
}
|
||||
};
|
||||
|
||||
scope.getBody();
|
||||
expect(emailMock.getBody.calledOnce).to.be.true;
|
||||
scope.getBody().then(function() {
|
||||
expect(emailMock.getBody.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -245,7 +248,7 @@ describe('Mail List controller unit test', function() {
|
||||
});
|
||||
|
||||
describe('select', function() {
|
||||
it('should decrypt, focus mark an unread mail as read', function() {
|
||||
it('should decrypt, focus mark an unread mail as read', function(done) {
|
||||
scope.pendingNotifications = ['asd'];
|
||||
sinon.stub(notificationMock, 'close');
|
||||
|
||||
@ -272,20 +275,21 @@ describe('Mail List controller unit test', function() {
|
||||
|
||||
keychainMock.refreshKeyForUserId.withArgs({
|
||||
userId: mail.from[0].address
|
||||
}).yields();
|
||||
}).returns(resolves());
|
||||
|
||||
scope.select(mail);
|
||||
scope.select(mail).then(function() {
|
||||
expect(emailMock.decryptBody.calledOnce).to.be.true;
|
||||
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
|
||||
expect(scope.state.mailList.selected).to.equal(mail);
|
||||
expect(notificationMock.close.calledWith('asd')).to.be.true;
|
||||
expect(notificationMock.close.calledOnce).to.be.true;
|
||||
|
||||
expect(emailMock.decryptBody.calledOnce).to.be.true;
|
||||
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
|
||||
expect(scope.state.mailList.selected).to.equal(mail);
|
||||
expect(notificationMock.close.calledWith('asd')).to.be.true;
|
||||
expect(notificationMock.close.calledOnce).to.be.true;
|
||||
|
||||
notificationMock.close.restore();
|
||||
notificationMock.close.restore();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should decrypt and focus a read mail', function() {
|
||||
it('should decrypt and focus a read mail', function(done) {
|
||||
var mail = {
|
||||
from: [{
|
||||
address: 'asd'
|
||||
@ -307,13 +311,14 @@ describe('Mail List controller unit test', function() {
|
||||
|
||||
keychainMock.refreshKeyForUserId.withArgs({
|
||||
userId: mail.from[0].address
|
||||
}).yields();
|
||||
}).returns(resolves());
|
||||
|
||||
scope.select(mail);
|
||||
|
||||
expect(emailMock.decryptBody.calledOnce).to.be.true;
|
||||
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
|
||||
expect(scope.state.mailList.selected).to.equal(mail);
|
||||
scope.select(mail).then(function() {
|
||||
expect(emailMock.decryptBody.calledOnce).to.be.true;
|
||||
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
|
||||
expect(scope.state.mailList.selected).to.equal(mail);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -41,6 +41,7 @@ describe('Navigation Controller unit test', function() {
|
||||
ctrl = $controller(NavigationCtrl, {
|
||||
$scope: scope,
|
||||
$routeParams: {},
|
||||
$q: window.qMock,
|
||||
account: accountMock,
|
||||
email: emailDaoMock,
|
||||
outbox: outboxBoMock,
|
||||
|
@ -23,6 +23,7 @@ describe('Private Key Upload Controller unit test', function() {
|
||||
ctrl = $controller(PrivateKeyUploadCtrl, {
|
||||
$location: location,
|
||||
$scope: scope,
|
||||
$q: window.qMock,
|
||||
keychain: keychainMock,
|
||||
pgp: pgpStub,
|
||||
dialog: dialogStub,
|
||||
@ -41,14 +42,15 @@ describe('Private Key Upload Controller unit test', function() {
|
||||
_id: 'keyId',
|
||||
};
|
||||
|
||||
it('should fail', function() {
|
||||
it('should fail', function(done) {
|
||||
pgpStub.getKeyParams.returns(keyParams);
|
||||
keychainMock.hasPrivateKey.yields(42);
|
||||
keychainMock.hasPrivateKey.returns(rejects(42));
|
||||
|
||||
scope.checkServerForKey();
|
||||
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
expect(keychainMock.hasPrivateKey.calledOnce).to.be.true;
|
||||
scope.checkServerForKey().then(function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
expect(keychainMock.hasPrivateKey.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true', function(done) {
|
||||
@ -56,9 +58,9 @@ describe('Private Key Upload Controller unit test', function() {
|
||||
keychainMock.hasPrivateKey.withArgs({
|
||||
userId: keyParams.userId,
|
||||
keyId: keyParams._id
|
||||
}).yields(null, true);
|
||||
}).returns(resolves(true));
|
||||
|
||||
scope.checkServerForKey(function(privateKeySynced) {
|
||||
scope.checkServerForKey().then(function(privateKeySynced) {
|
||||
expect(privateKeySynced).to.be.true;
|
||||
done();
|
||||
});
|
||||
@ -69,9 +71,9 @@ describe('Private Key Upload Controller unit test', function() {
|
||||
keychainMock.hasPrivateKey.withArgs({
|
||||
userId: keyParams.userId,
|
||||
keyId: keyParams._id
|
||||
}).yields(null, false);
|
||||
}).returns(resolves(false));
|
||||
|
||||
scope.checkServerForKey(function(privateKeySynced) {
|
||||
scope.checkServerForKey().then(function(privateKeySynced) {
|
||||
expect(privateKeySynced).to.be.undefined;
|
||||
done();
|
||||
});
|
||||
@ -110,27 +112,27 @@ describe('Private Key Upload Controller unit test', function() {
|
||||
|
||||
describe('setDeviceName', function() {
|
||||
it('should work', function(done) {
|
||||
keychainMock.setDeviceName.yields();
|
||||
scope.setDeviceName(done);
|
||||
keychainMock.setDeviceName.returns(resolves());
|
||||
scope.setDeviceName().then(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('encryptAndUploadKey', function() {
|
||||
it('should fail due to keychain.registerDevice', function() {
|
||||
keychainMock.registerDevice.yields(42);
|
||||
it('should fail due to keychain.registerDevice', function(done) {
|
||||
keychainMock.registerDevice.returns(rejects(42));
|
||||
|
||||
scope.encryptAndUploadKey();
|
||||
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
expect(keychainMock.registerDevice.calledOnce).to.be.true;
|
||||
scope.encryptAndUploadKey().then(function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
expect(keychainMock.registerDevice.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work', function(done) {
|
||||
keychainMock.registerDevice.yields();
|
||||
keychainMock.uploadPrivateKey.yields();
|
||||
keychainMock.registerDevice.returns(resolves());
|
||||
keychainMock.uploadPrivateKey.returns(resolves());
|
||||
|
||||
scope.encryptAndUploadKey(function(err) {
|
||||
expect(err).to.not.exist;
|
||||
scope.encryptAndUploadKey().then(function() {
|
||||
expect(keychainMock.registerDevice.calledOnce).to.be.true;
|
||||
expect(keychainMock.uploadPrivateKey.calledOnce).to.be.true;
|
||||
done();
|
||||
@ -185,36 +187,39 @@ describe('Private Key Upload Controller unit test', function() {
|
||||
expect(scope.step).to.equal(2);
|
||||
});
|
||||
|
||||
it('should fail for 3 due to error in setDeviceName', function() {
|
||||
it('should fail for 3 due to error in setDeviceName', function(done) {
|
||||
scope.step = 3;
|
||||
setDeviceNameStub.yields(42);
|
||||
setDeviceNameStub.returns(rejects(42));
|
||||
|
||||
scope.goForward();
|
||||
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
expect(scope.step).to.equal(3);
|
||||
scope.goForward().then(function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
expect(scope.step).to.equal(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail for 3 due to error in encryptAndUploadKey', function() {
|
||||
it('should fail for 3 due to error in encryptAndUploadKey', function(done) {
|
||||
scope.step = 3;
|
||||
setDeviceNameStub.yields();
|
||||
encryptAndUploadKeyStub.yields(42);
|
||||
setDeviceNameStub.returns(resolves());
|
||||
encryptAndUploadKeyStub.returns(rejects(42));
|
||||
|
||||
scope.goForward();
|
||||
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
expect(scope.step).to.equal(4);
|
||||
scope.goForward().then(function() {
|
||||
expect(dialogStub.error.calledOnce).to.be.true;
|
||||
expect(scope.step).to.equal(4);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work for 3', function() {
|
||||
it('should work for 3', function(done) {
|
||||
scope.step = 3;
|
||||
setDeviceNameStub.yields();
|
||||
encryptAndUploadKeyStub.yields();
|
||||
setDeviceNameStub.returns(resolves());
|
||||
encryptAndUploadKeyStub.returns(resolves());
|
||||
|
||||
scope.goForward();
|
||||
|
||||
expect(dialogStub.info.calledOnce).to.be.true;
|
||||
expect(scope.step).to.equal(4);
|
||||
scope.goForward().then(function() {
|
||||
expect(dialogStub.info.calledOnce).to.be.true;
|
||||
expect(scope.step).to.equal(4);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -11,8 +11,7 @@ var Keychain = require('../../../../src/js/service/keychain'),
|
||||
Download = require('../../../../src/js/util/download');
|
||||
|
||||
describe('Read Controller unit test', function() {
|
||||
var scope, ctrl, keychainMock, invitationMock, emailMock, pgpMock, outboxMock, dialogMock, authMock, downloadMock,
|
||||
emailAddress = 'sender@example.com';
|
||||
var scope, ctrl, keychainMock, invitationMock, emailMock, pgpMock, outboxMock, dialogMock, authMock, downloadMock;
|
||||
|
||||
beforeEach(function() {
|
||||
keychainMock = sinon.createStubInstance(Keychain);
|
||||
@ -31,6 +30,7 @@ describe('Read Controller unit test', function() {
|
||||
scope.state = {};
|
||||
ctrl = $controller(ReadCtrl, {
|
||||
$scope: scope,
|
||||
$q: window.qMock,
|
||||
email: emailMock,
|
||||
invitation: invitationMock,
|
||||
outbox: outboxMock,
|
||||
@ -66,33 +66,37 @@ describe('Read Controller unit test', function() {
|
||||
describe('getKeyId', function() {
|
||||
var address = 'asfd@asdf.com';
|
||||
|
||||
it('should show searching on error', function() {
|
||||
it('should show searching on error', function(done) {
|
||||
expect(scope.keyId).to.equal('No key found.');
|
||||
keychainMock.getReceiverPublicKey.yields(42);
|
||||
keychainMock.getReceiverPublicKey.returns(rejects(42));
|
||||
|
||||
scope.getKeyId(address);
|
||||
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
expect(scope.keyId).to.equal('Searching...');
|
||||
});
|
||||
|
||||
it('should allow invitation on empty key', function() {
|
||||
keychainMock.getReceiverPublicKey.yields();
|
||||
|
||||
scope.getKeyId(address);
|
||||
|
||||
expect(scope.keyId).to.equal('User has no key. Click to invite.');
|
||||
});
|
||||
|
||||
it('should show searching on error', function() {
|
||||
keychainMock.getReceiverPublicKey.yields(null, {
|
||||
publicKey: 'PUBLIC KEY'
|
||||
scope.getKeyId(address).then(function() {
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
expect(scope.keyId).to.equal('Searching...');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow invitation on empty key', function(done) {
|
||||
keychainMock.getReceiverPublicKey.returns(resolves());
|
||||
|
||||
scope.getKeyId(address).then(function() {
|
||||
expect(scope.keyId).to.equal('User has no key. Click to invite.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should show searching on error', function(done) {
|
||||
keychainMock.getReceiverPublicKey.returns(resolves({
|
||||
publicKey: 'PUBLIC KEY'
|
||||
}));
|
||||
|
||||
pgpMock.getFingerprint.returns('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
|
||||
|
||||
scope.getKeyId(address);
|
||||
expect(scope.keyId).to.equal('PGP key: XXXXXXXX');
|
||||
scope.getKeyId(address).then(function() {
|
||||
expect(scope.keyId).to.equal('PGP key: XXXXXXXX');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -108,36 +112,39 @@ describe('Read Controller unit test', function() {
|
||||
expect(scope.keyId).to.equal('No key found.');
|
||||
});
|
||||
|
||||
it('should show error on invitation dao invite error', function() {
|
||||
invitationMock.invite.yields(42);
|
||||
it('should show error on invitation dao invite error', function(done) {
|
||||
invitationMock.invite.returns(rejects(42));
|
||||
|
||||
scope.invite({
|
||||
address: 'asdf@asdf.de'
|
||||
}).then(function() {
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
});
|
||||
|
||||
it('should show error on outbox put error', function() {
|
||||
invitationMock.invite.yields();
|
||||
outboxMock.put.yields(42);
|
||||
it('should show error on outbox put error', function(done) {
|
||||
invitationMock.invite.returns(resolves());
|
||||
outboxMock.put.returns(rejects(42));
|
||||
|
||||
scope.invite({
|
||||
address: 'asdf@asdf.de'
|
||||
}).then(function() {
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
});
|
||||
|
||||
it('should work', function() {
|
||||
invitationMock.invite.yields();
|
||||
outboxMock.put.yields();
|
||||
it('should work', function(done) {
|
||||
invitationMock.invite.returns(resolves());
|
||||
outboxMock.put.returns(resolves());
|
||||
|
||||
scope.invite({
|
||||
address: 'asdf@asdf.de'
|
||||
}).then(function() {
|
||||
expect(dialogMock.error.calledOnce).to.be.false;
|
||||
done();
|
||||
});
|
||||
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -40,6 +40,7 @@ describe('Set Passphrase Controller unit test', function() {
|
||||
scope.state = {};
|
||||
setPassphraseCtrl = $controller(SetPassphraseCtrl, {
|
||||
$scope: scope,
|
||||
$q: window.qMock,
|
||||
pgp: pgpStub,
|
||||
keychain: keychainStub,
|
||||
dialog: dialogStub
|
||||
@ -49,31 +50,32 @@ describe('Set Passphrase Controller unit test', function() {
|
||||
|
||||
afterEach(function() {});
|
||||
|
||||
describe('setPassphrase', function() {
|
||||
describe('setPassphrase', function(done) {
|
||||
it('should work', function() {
|
||||
scope.oldPassphrase = 'old';
|
||||
scope.newPassphrase = 'new';
|
||||
|
||||
keychainStub.lookupPrivateKey.withArgs(dummyKeyId).yields(null, {
|
||||
keychainStub.lookupPrivateKey.withArgs(dummyKeyId).returns(resolves({
|
||||
encryptedKey: 'encrypted'
|
||||
});
|
||||
}));
|
||||
|
||||
pgpStub.changePassphrase.withArgs({
|
||||
privateKeyArmored: 'encrypted',
|
||||
oldPassphrase: 'old',
|
||||
newPassphrase: 'new'
|
||||
}).yields(null, 'newArmoredKey');
|
||||
}).returns(resolves('newArmoredKey'));
|
||||
|
||||
keychainStub.saveLocalPrivateKey.withArgs({
|
||||
_id: dummyKeyId,
|
||||
userId: emailAddress,
|
||||
userIds: [],
|
||||
encryptedKey: 'newArmoredKey'
|
||||
}).yields();
|
||||
}).returns(resolves());
|
||||
|
||||
scope.setPassphrase();
|
||||
|
||||
expect(dialogStub.info.calledOnce).to.be.true;
|
||||
scope.setPassphrase().then(function() {
|
||||
expect(dialogStub.info.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -36,6 +36,7 @@ describe('Write controller unit test', function() {
|
||||
scope.state = {};
|
||||
ctrl = $controller(WriteCtrl, {
|
||||
$scope: scope,
|
||||
$q: window.qMock,
|
||||
auth: authMock,
|
||||
keychain: keychainMock,
|
||||
pgp: pgpMock,
|
||||
@ -183,24 +184,25 @@ describe('Write controller unit test', function() {
|
||||
expect(keychainMock.getReceiverPublicKey.called).to.be.false;
|
||||
});
|
||||
|
||||
it('should not work for error in keychain', function() {
|
||||
it('should not work for error in keychain', function(done) {
|
||||
var recipient = {
|
||||
address: 'asds@example.com'
|
||||
};
|
||||
|
||||
keychainMock.refreshKeyForUserId.withArgs({
|
||||
userId: recipient.address
|
||||
}).yields({
|
||||
}).returns(rejects({
|
||||
errMsg: '404 not found yadda yadda'
|
||||
}));
|
||||
|
||||
scope.verify(recipient).then(function() {
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
expect(recipient.key).to.be.undefined;
|
||||
expect(recipient.secure).to.be.false;
|
||||
expect(scope.checkSendStatus.callCount).to.equal(1);
|
||||
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.verify(recipient);
|
||||
|
||||
expect(dialogMock.error.calledOnce).to.be.true;
|
||||
expect(recipient.key).to.be.undefined;
|
||||
expect(recipient.secure).to.be.false;
|
||||
expect(scope.checkSendStatus.callCount).to.equal(1);
|
||||
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
|
||||
});
|
||||
|
||||
it('should work for main userId', function(done) {
|
||||
@ -210,11 +212,11 @@ describe('Write controller unit test', function() {
|
||||
|
||||
keychainMock.refreshKeyForUserId.withArgs({
|
||||
userId: recipient.address
|
||||
}).yields(null, {
|
||||
}).returns(resolves({
|
||||
userId: 'asdf@example.com'
|
||||
});
|
||||
}));
|
||||
|
||||
scope.$digest = function() {
|
||||
scope.verify(recipient).then(function() {
|
||||
expect(recipient.key).to.deep.equal({
|
||||
userId: 'asdf@example.com'
|
||||
});
|
||||
@ -222,9 +224,7 @@ describe('Write controller unit test', function() {
|
||||
expect(scope.checkSendStatus.callCount).to.equal(2);
|
||||
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
|
||||
done();
|
||||
};
|
||||
|
||||
scope.verify(recipient);
|
||||
});
|
||||
});
|
||||
|
||||
it('should work for secondary userId', function(done) {
|
||||
@ -240,17 +240,15 @@ describe('Write controller unit test', function() {
|
||||
|
||||
keychainMock.refreshKeyForUserId.withArgs({
|
||||
userId: recipient.address
|
||||
}).yields(null, key);
|
||||
}).returns(resolves(key));
|
||||
|
||||
scope.$digest = function() {
|
||||
scope.verify(recipient).then(function() {
|
||||
expect(recipient.key).to.deep.equal(key);
|
||||
expect(recipient.secure).to.be.true;
|
||||
expect(scope.checkSendStatus.callCount).to.equal(2);
|
||||
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
|
||||
done();
|
||||
};
|
||||
|
||||
scope.verify(recipient);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -311,7 +309,7 @@ describe('Write controller unit test', function() {
|
||||
});
|
||||
|
||||
describe('send to outbox', function() {
|
||||
it('should work', function() {
|
||||
it('should work', function(done) {
|
||||
scope.to = [{
|
||||
address: 'pity@dafool'
|
||||
}];
|
||||
@ -341,25 +339,26 @@ describe('Write controller unit test', function() {
|
||||
expect(mail.sentDate).to.exist;
|
||||
|
||||
return true;
|
||||
})).yields();
|
||||
emailMock.setFlags.yields();
|
||||
})).returns(resolves());
|
||||
emailMock.setFlags.returns(resolves());
|
||||
|
||||
scope.sendToOutbox();
|
||||
|
||||
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
||||
expect(outboxMock.put.calledOnce).to.be.true;
|
||||
expect(emailMock.setFlags.calledOnce).to.be.true;
|
||||
expect(scope.state.lightbox).to.be.undefined;
|
||||
expect(scope.replyTo.answered).to.be.true;
|
||||
scope.sendToOutbox().then(function() {
|
||||
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
||||
expect(outboxMock.put.calledOnce).to.be.true;
|
||||
expect(emailMock.setFlags.calledOnce).to.be.true;
|
||||
expect(scope.state.lightbox).to.be.undefined;
|
||||
expect(scope.replyTo.answered).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('lookupAddressBook', function() {
|
||||
it('should work', function(done) {
|
||||
keychainMock.listLocalPublicKeys.yields(null, [{
|
||||
keychainMock.listLocalPublicKeys.returns(resolves([{
|
||||
userId: 'test@asdf.com',
|
||||
publicKey: 'KEY'
|
||||
}]);
|
||||
}]));
|
||||
|
||||
var result = scope.lookupAddressBook('test');
|
||||
|
||||
@ -369,7 +368,6 @@ describe('Write controller unit test', function() {
|
||||
}]);
|
||||
done();
|
||||
});
|
||||
scope.$digest();
|
||||
});
|
||||
|
||||
it('should work with cache', function(done) {
|
||||
@ -387,7 +385,6 @@ describe('Write controller unit test', function() {
|
||||
}]);
|
||||
done();
|
||||
});
|
||||
scope.$digest();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -29,6 +29,7 @@ describe('Login Private Key Download Controller unit test', function() {
|
||||
$location: location,
|
||||
$scope: scope,
|
||||
$routeParams: {},
|
||||
$q: window.qMock,
|
||||
auth: authMock,
|
||||
email: emailDaoMock,
|
||||
keychain: keychainMock
|
||||
@ -46,74 +47,57 @@ describe('Login Private Key Download Controller unit test', function() {
|
||||
});
|
||||
|
||||
describe('checkToken', function() {
|
||||
var verifyRecoveryTokenStub;
|
||||
|
||||
beforeEach(function() {
|
||||
verifyRecoveryTokenStub = sinon.stub(scope, 'verifyRecoveryToken');
|
||||
});
|
||||
afterEach(function() {
|
||||
verifyRecoveryTokenStub.restore();
|
||||
});
|
||||
|
||||
it('should fail for empty recovery token', function() {
|
||||
scope.tokenForm.$invalid = true;
|
||||
|
||||
scope.checkToken();
|
||||
|
||||
expect(verifyRecoveryTokenStub.calledOnce).to.be.false;
|
||||
expect(scope.errMsg).to.exist;
|
||||
});
|
||||
|
||||
it('should work', function() {
|
||||
verifyRecoveryTokenStub.yields();
|
||||
|
||||
scope.checkToken();
|
||||
|
||||
expect(verifyRecoveryTokenStub.calledOnce).to.be.true;
|
||||
expect(scope.step).to.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('verifyRecoveryToken', function() {
|
||||
var testKeypair = {
|
||||
publicKey: {
|
||||
_id: 'id'
|
||||
}
|
||||
};
|
||||
|
||||
it('should fail in keychain.getUserKeyPair', function() {
|
||||
keychainMock.getUserKeyPair.yields(new Error('asdf'));
|
||||
it('should fail for empty recovery token', function() {
|
||||
scope.tokenForm.$invalid = true;
|
||||
|
||||
scope.verifyRecoveryToken();
|
||||
scope.checkToken();
|
||||
|
||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.false;
|
||||
expect(scope.errMsg).to.exist;
|
||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||
});
|
||||
|
||||
it('should fail in keychain.downloadPrivateKey', function() {
|
||||
keychainMock.getUserKeyPair.yields(null, testKeypair);
|
||||
keychainMock.downloadPrivateKey.yields(new Error('asdf'));
|
||||
scope.recoveryToken = 'token';
|
||||
it('should fail in keychain.getUserKeyPair', function(done) {
|
||||
keychainMock.getUserKeyPair.returns(rejects(new Error('asdf')));
|
||||
|
||||
scope.verifyRecoveryToken();
|
||||
|
||||
expect(scope.errMsg).to.exist;
|
||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||
expect(keychainMock.downloadPrivateKey.calledOnce).to.be.true;
|
||||
scope.checkToken().then(function() {
|
||||
expect(scope.errMsg).to.exist;
|
||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work', function() {
|
||||
keychainMock.getUserKeyPair.yields(null, testKeypair);
|
||||
keychainMock.downloadPrivateKey.yields(null, 'encryptedPrivateKey');
|
||||
it('should fail in keychain.downloadPrivateKey', function(done) {
|
||||
keychainMock.getUserKeyPair.returns(resolves(testKeypair));
|
||||
keychainMock.downloadPrivateKey.returns(rejects(new Error('asdf')));
|
||||
scope.recoveryToken = 'token';
|
||||
|
||||
scope.verifyRecoveryToken(function() {});
|
||||
scope.checkToken().then(function() {
|
||||
expect(scope.errMsg).to.exist;
|
||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||
expect(keychainMock.downloadPrivateKey.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
expect(scope.encryptedPrivateKey).to.equal('encryptedPrivateKey');
|
||||
it('should work', function(done) {
|
||||
keychainMock.getUserKeyPair.returns(resolves(testKeypair));
|
||||
keychainMock.downloadPrivateKey.returns(resolves('encryptedPrivateKey'));
|
||||
scope.recoveryToken = 'token';
|
||||
|
||||
scope.checkToken().then(function() {
|
||||
expect(scope.encryptedPrivateKey).to.equal('encryptedPrivateKey');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('decryptAndStorePrivateKeyLocally', function() {
|
||||
describe('checkCode', function() {
|
||||
beforeEach(function() {
|
||||
scope.code = '012345';
|
||||
|
||||
@ -125,48 +109,50 @@ describe('Login Private Key Download Controller unit test', function() {
|
||||
_id: 'keyId'
|
||||
}
|
||||
};
|
||||
|
||||
sinon.stub(scope, 'goTo');
|
||||
});
|
||||
afterEach(function() {
|
||||
scope.goTo.restore();
|
||||
});
|
||||
|
||||
it('should fail on decryptAndStorePrivateKeyLocally', function() {
|
||||
keychainMock.decryptAndStorePrivateKeyLocally.yields(new Error('asdf'));
|
||||
it('should fail on decryptAndStorePrivateKeyLocally', function(done) {
|
||||
keychainMock.decryptAndStorePrivateKeyLocally.returns(rejects(new Error('asdf')));
|
||||
|
||||
scope.decryptAndStorePrivateKeyLocally();
|
||||
|
||||
expect(scope.errMsg).to.exist;
|
||||
expect(keychainMock.decryptAndStorePrivateKeyLocally.calledOnce).to.be.true;
|
||||
scope.checkCode().then(function() {
|
||||
expect(scope.errMsg).to.exist;
|
||||
expect(keychainMock.decryptAndStorePrivateKeyLocally.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should goto /login-existing on emailDao.unlock fail', function(done) {
|
||||
keychainMock.decryptAndStorePrivateKeyLocally.yields(null, {
|
||||
keychainMock.decryptAndStorePrivateKeyLocally.returns(resolves({
|
||||
encryptedKey: 'keyArmored'
|
||||
});
|
||||
emailDaoMock.unlock.yields(new Error('asdf'));
|
||||
}));
|
||||
emailDaoMock.unlock.returns(rejects(new Error('asdf')));
|
||||
|
||||
scope.goTo = function(location) {
|
||||
expect(location).to.equal('/login-existing');
|
||||
scope.checkCode().then(function() {
|
||||
expect(scope.goTo.withArgs('/login-existing').calledOnce).to.be.true;
|
||||
expect(keychainMock.decryptAndStorePrivateKeyLocally.calledOnce).to.be.true;
|
||||
expect(emailDaoMock.unlock.calledOnce).to.be.true;
|
||||
done();
|
||||
};
|
||||
|
||||
scope.decryptAndStorePrivateKeyLocally();
|
||||
});
|
||||
});
|
||||
|
||||
it('should goto /account on emailDao.unlock success', function(done) {
|
||||
keychainMock.decryptAndStorePrivateKeyLocally.yields(null, {
|
||||
keychainMock.decryptAndStorePrivateKeyLocally.returns(resolves({
|
||||
encryptedKey: 'keyArmored'
|
||||
});
|
||||
emailDaoMock.unlock.yields();
|
||||
authMock.storeCredentials.yields();
|
||||
}));
|
||||
emailDaoMock.unlock.returns(resolves());
|
||||
authMock.storeCredentials.returns(resolves());
|
||||
|
||||
scope.goTo = function(location) {
|
||||
expect(location).to.equal('/account');
|
||||
scope.checkCode().then(function() {
|
||||
expect(scope.goTo.withArgs('/account').calledOnce).to.be.true;
|
||||
expect(keychainMock.decryptAndStorePrivateKeyLocally.calledOnce).to.be.true;
|
||||
expect(emailDaoMock.unlock.calledOnce).to.be.true;
|
||||
done();
|
||||
};
|
||||
|
||||
scope.decryptAndStorePrivateKeyLocally();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -40,6 +40,7 @@ describe('Login (Set Credentials) Controller unit test', function() {
|
||||
setCredentialsCtrl = $controller(SetCredentialsCtrl, {
|
||||
$scope: scope,
|
||||
$routeParams: {},
|
||||
$q: window.qMock,
|
||||
auth: auth,
|
||||
connectionDoctor: doctor
|
||||
});
|
||||
@ -49,7 +50,7 @@ describe('Login (Set Credentials) Controller unit test', function() {
|
||||
afterEach(function() {});
|
||||
|
||||
describe('set credentials', function() {
|
||||
it('should work', function() {
|
||||
it('should work', function(done) {
|
||||
scope.emailAddress = 'emailemailemailemail';
|
||||
scope.password = 'passwdpasswdpasswdpasswd';
|
||||
scope.smtpHost = 'hosthosthost';
|
||||
@ -80,14 +81,16 @@ describe('Login (Set Credentials) Controller unit test', function() {
|
||||
}
|
||||
};
|
||||
|
||||
doctor.check.yields(); // synchronous yields!
|
||||
doctor.check.returns(resolves()); // synchronous yields!
|
||||
|
||||
scope.test();
|
||||
scope.test().then(function() {
|
||||
expect(doctor.check.calledOnce).to.be.true;
|
||||
expect(doctor.configure.calledOnce).to.be.true;
|
||||
expect(doctor.configure.calledWith(expectedCredentials)).to.be.true;
|
||||
expect(auth.setCredentials.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
|
||||
expect(doctor.check.calledOnce).to.be.true;
|
||||
expect(doctor.configure.calledOnce).to.be.true;
|
||||
expect(doctor.configure.calledWith(expectedCredentials)).to.be.true;
|
||||
expect(auth.setCredentials.calledOnce).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
@ -34,6 +34,7 @@ describe('Validate Phone Controller unit test', function() {
|
||||
$location: location,
|
||||
$scope: scope,
|
||||
$routeParams: {},
|
||||
$q: window.qMock,
|
||||
mailConfig: mailConfigMock,
|
||||
auth: authStub,
|
||||
admin: adminStub
|
||||
@ -59,55 +60,53 @@ describe('Validate Phone Controller unit test', function() {
|
||||
it('should fail to error creating user', function(done) {
|
||||
scope.form.$invalid = false;
|
||||
scope.token = 'asfd';
|
||||
adminStub.validateUser.yieldsAsync(new Error('asdf'));
|
||||
adminStub.validateUser.returns(rejects(new Error('asdf')));
|
||||
|
||||
scope.$apply = function() {
|
||||
scope.validateUser().then(function() {
|
||||
expect(scope.busy).to.be.false;
|
||||
expect(scope.errMsg).to.equal('asdf');
|
||||
expect(adminStub.validateUser.calledOnce).to.be.true;
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
scope.validateUser();
|
||||
expect(scope.busy).to.be.true;
|
||||
});
|
||||
|
||||
it('should work', function(done) {
|
||||
scope.form.$invalid = false;
|
||||
scope.token = 'asfd';
|
||||
adminStub.validateUser.yieldsAsync();
|
||||
adminStub.validateUser.returns(resolves());
|
||||
|
||||
scope.login = function() {
|
||||
scope.login = function() {};
|
||||
|
||||
scope.validateUser().then(function() {
|
||||
expect(scope.busy).to.be.true;
|
||||
expect(scope.errMsg).to.be.undefined;
|
||||
expect(adminStub.validateUser.calledOnce).to.be.true;
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
scope.validateUser();
|
||||
expect(scope.busy).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('login', function() {
|
||||
it('should work', inject(function($q, $rootScope) {
|
||||
it('should work', function(done) {
|
||||
scope.form.$invalid = false;
|
||||
authStub.setCredentials.returns();
|
||||
|
||||
var deferred = $q.defer();
|
||||
sinon.stub(mailConfigMock, 'get').returns(deferred.promise);
|
||||
deferred.resolve({
|
||||
sinon.stub(mailConfigMock, 'get').returns(resolves({
|
||||
imap: {},
|
||||
smtp: {}
|
||||
}));
|
||||
|
||||
scope.login().then(function() {
|
||||
expect(mailConfigMock.get.calledOnce).to.be.true;
|
||||
expect(authStub.setCredentials.calledOnce).to.be.true;
|
||||
expect(location.path.calledWith('/login')).to.be.true;
|
||||
done();
|
||||
});
|
||||
|
||||
scope.login();
|
||||
|
||||
$rootScope.$apply();
|
||||
expect(mailConfigMock.get.calledOnce).to.be.true;
|
||||
expect(authStub.setCredentials.calledOnce).to.be.true;
|
||||
expect(location.path.calledWith('/login')).to.be.true;
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user