fix tests

This commit is contained in:
Tankred Hase 2014-02-28 14:45:10 +01:00
parent 441562285c
commit 220a112091
4 changed files with 152 additions and 42 deletions

View File

@ -2536,7 +2536,7 @@ define(function(require) {
pgpMailerStub.send.withArgs({
encrypt: true,
cleartextMessage: str.message,
cleartextMessage: str.message + str.signature,
mail: dummyDecryptedMail,
publicKeysArmored: publicKeys
}).yields();
@ -2579,17 +2579,6 @@ define(function(require) {
});
});
describe('reEncrypt', function() {
it('should re-encrypt', function(done) {
pgpBuilderStub.reEncrypt.yields();
dao.reEncrypt({}, function() {
expect(pgpBuilderStub.reEncrypt.calledOnce).to.be.true;
done();
});
});
});
describe('syncOutbox', function() {
it('should sync the outbox', function(done) {
var folder = 'FOLDAAAA';

View File

@ -10,7 +10,7 @@ define(function(require) {
chai.Assertion.includeStack = true;
describe('Outbox Business Object unit test', function() {
var outbox, emailDaoStub, devicestorageStub, invitationDaoStub, keychainStub,
var outbox, emailDaoStub, devicestorageStub, keychainStub,
dummyUser = 'spiderpig@springfield.com';
beforeEach(function() {
@ -24,7 +24,7 @@ define(function(require) {
};
devicestorageStub = sinon.createStubInstance(DeviceStorageDAO);
keychainStub = sinon.createStubInstance(KeychainDAO);
outbox = new OutboxBO(emailDaoStub, keychainStub, devicestorageStub, invitationDaoStub);
outbox = new OutboxBO(emailDaoStub, keychainStub, devicestorageStub);
});
afterEach(function() {});
@ -149,6 +149,7 @@ define(function(require) {
name: 'member',
address: 'member'
}],
encrypted: true,
publicKeysArmored: ['ARMORED KEY OF MEMBER'],
unregisteredUsers: []
};
@ -185,6 +186,7 @@ define(function(require) {
name: 'newlyjoined',
address: 'newlyjoined'
}],
encrypted: true,
publicKeysArmored: [],
unregisteredUsers: [{
name: 'newlyjoined',
@ -199,10 +201,6 @@ define(function(require) {
devicestorageStub.listItems.yieldsAsync(null, dummyMails);
keychainStub.getReceiverPublicKey.withArgs(invited.unregisteredUsers[0].address).yieldsAsync();
keychainStub.getReceiverPublicKey.withArgs(notinvited.unregisteredUsers[0].address).yieldsAsync();
keychainStub.getReceiverPublicKey.withArgs(newlyjoined.unregisteredUsers[0].address).yieldsAsync(null, newlyjoinedKey);
emailDaoStub.sendPlaintext.yieldsAsync();
emailDaoStub.sendEncrypted.withArgs({
@ -213,22 +211,18 @@ define(function(require) {
email: member
}).yieldsAsync();
devicestorageStub.storeList.withArgs([newlyjoined]).yieldsAsync();
devicestorageStub.removeList.withArgs('email_OUTBOX_' + member.id).yieldsAsync();
devicestorageStub.removeList.withArgs('email_OUTBOX_' + newlyjoined.id).yieldsAsync();
devicestorageStub.removeList.yieldsAsync();
function onOutboxUpdate(err, count) {
expect(err).to.not.exist;
expect(count).to.equal(2);
expect(count).to.equal(0);
expect(outbox._outboxBusy).to.be.false;
expect(emailDaoStub.sendEncrypted.calledTwice).to.be.true;
expect(emailDaoStub.reEncrypt.calledOnce).to.be.true;
expect(emailDaoStub.sendPlaintext.calledOnce).to.be.true;
expect(devicestorageStub.listItems.calledOnce).to.be.true;
expect(keychainStub.getReceiverPublicKey.calledThrice).to.be.true;
expect(invitationDaoStub.check.calledTwice).to.be.true;
expect(emailDaoStub.sendEncrypted.callCount).to.equal(2);
expect(emailDaoStub.sendPlaintext.callCount).to.equal(2);
expect(devicestorageStub.listItems.callCount).to.equal(1);
expect(devicestorageStub.removeList.callCount).to.equal(4);
expect(keychainStub.getReceiverPublicKey.callCount).to.equal(0);
done();
}

View File

@ -4,12 +4,39 @@ define(function(require) {
var expect = chai.expect,
angular = require('angular'),
mocks = require('angularMocks'),
ReadCtrl = require('js/controller/read');
KeychainDAO = require('js/dao/keychain-dao'),
InvitationDAO = require('js/dao/invitation-dao'),
PGP = require('js/crypto/pgp'),
ReadCtrl = require('js/controller/read'),
OutboxBO = require('js/bo/outbox'),
appController = require('js/app-controller');
describe('Read Controller unit test', function() {
var scope, ctrl;
var scope, ctrl,
origKeychain, keychainMock,
origInvitation, invitationMock,
origCrypto, cryptoMock,
origOutbox, outboxMock,
origEmailDao;
beforeEach(function() {
origKeychain = appController._keychain;
appController._keychain = keychainMock = sinon.createStubInstance(KeychainDAO);
origInvitation = appController._invitationDao;
appController._invitationDao = invitationMock = sinon.createStubInstance(InvitationDAO);
origCrypto = appController._crypto;
appController._crypto = cryptoMock = sinon.createStubInstance(PGP);
origOutbox = appController._outboxBo;
appController._outboxBo = outboxMock = sinon.createStubInstance(OutboxBO);
origEmailDao = appController._emailDao;
appController._emailDao = {
_account: 'sender@example.com'
};
angular.module('readtest', []);
mocks.module('readtest');
mocks.inject(function($rootScope, $controller) {
@ -21,7 +48,13 @@ define(function(require) {
});
});
afterEach(function() {});
afterEach(function() {
appController._keychain = origKeychain;
appController._invitationDao = origInvitation;
appController._crypto = origCrypto;
appController._outboxBo = origOutbox;
appController._emailDao = origEmailDao;
});
describe('scope variables', function() {
it('should be set correctly', function() {
@ -40,5 +73,98 @@ define(function(require) {
expect(scope.state.read.open).to.be.false;
});
});
describe('getKeyId', function() {
var address = 'asfd@asdf.com';
it('should show searching on error', function() {
expect(scope.keyId).to.equal('No key found.');
keychainMock.getReceiverPublicKey.yields(42);
scope.onError = function(err) {
expect(err).to.equal(42);
expect(scope.keyId).to.equal('Searching...');
};
scope.getKeyId(address);
});
it('should allow invitation on empty key', function() {
keychainMock.getReceiverPublicKey.yields();
scope.onError = function(err) {
expect(err).not.exist;
expect(scope.keyId).to.equal('User has no key. Click to invite.');
};
scope.getKeyId(address);
});
it('should show searching on error', function() {
keychainMock.getReceiverPublicKey.yields(null, {
publicKey: 'PUBLIC KEY'
});
cryptoMock.getFingerprint.returns('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
scope.onError = function(err) {
expect(err).to.not.exist;
expect(scope.keyId).to.equal('PGP key: XXXXXXXX');
};
scope.getKeyId(address);
});
});
describe('invite', function() {
it('not allow invitation for secure users', function() {
expect(scope.keyId).to.equal('No key found.');
scope.invite({
secure: true,
address: 'asdf@asdf.de'
});
expect(scope.keyId).to.equal('No key found.');
});
it('should show error on invitation dao invite error', function() {
invitationMock.invite.yields(42);
scope.onError = function(err) {
expect(err).to.equal(42);
};
scope.invite({
address: 'asdf@asdf.de'
});
});
it('should show error on outbox put error', function() {
invitationMock.invite.yields();
outboxMock.put.yields(42);
scope.onError = function(err) {
expect(err).to.equal(42);
};
scope.invite({
address: 'asdf@asdf.de'
});
});
it('should work', function() {
invitationMock.invite.yields();
outboxMock.put.yields();
scope.onError = function(err) {
expect(err).to.not.exist;
};
scope.invite({
address: 'asdf@asdf.de'
});
});
});
});
});

View File

@ -169,7 +169,7 @@ define(function(require) {
expect(recipient.key).to.be.undefined;
expect(recipient.secure).to.be.undefined;
expect(scope.checkSendStatus.calledOnce).to.be.true;
expect(scope.checkSendStatus.callCount).to.equal(2);
expect(keychainMock.getReceiverPublicKey.called).to.be.false;
});
@ -184,7 +184,7 @@ define(function(require) {
scope.onError = function() {
expect(recipient.key).to.be.undefined;
expect(recipient.secure).to.be.false;
expect(scope.checkSendStatus.called).to.be.false;
expect(scope.checkSendStatus.callCount).to.equal(1);
expect(keychainMock.getReceiverPublicKey.calledOnce).to.be.true;
done();
};
@ -205,7 +205,7 @@ define(function(require) {
userId: 'asdf@example.com'
});
expect(recipient.secure).to.be.true;
expect(scope.checkSendStatus.calledOnce).to.be.true;
expect(scope.checkSendStatus.callCount).to.equal(2);
expect(keychainMock.getReceiverPublicKey.calledOnce).to.be.true;
done();
};
@ -229,28 +229,29 @@ define(function(require) {
expect(scope.sendBtnSecure).to.be.undefined;
});
it('should not be to invite 1 user', function() {
it('should be able to send plaintext', function() {
scope.to = [{
address: 'asdf@asdf.de'
}];
scope.checkSendStatus();
expect(scope.okToSend).to.be.true;
expect(scope.sendBtnText).to.equal('Invite & send securely');
expect(scope.sendBtnText).to.equal('Send');
expect(scope.sendBtnSecure).to.be.false;
});
it('should not be able to invite multiple recipients', function() {
it('should send plaintext if one receiver is not secure', function() {
scope.to = [{
address: 'asdf@asdf.de'
address: 'asdf@asdf.de',
secure: true
}, {
address: 'asdf@asdfg.de'
}];
scope.checkSendStatus();
expect(scope.okToSend).to.be.false;
expect(scope.sendBtnText).to.be.undefined;
expect(scope.sendBtnSecure).to.be.undefined;
expect(scope.okToSend).to.be.true;
expect(scope.sendBtnText).to.equal('Send');
expect(scope.sendBtnSecure).to.be.false;
});
it('should be able to send securely to multiple recipients', function() {