2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
var Keychain = require('../../../../src/js/service/keychain'),
|
|
|
|
InvitationDAO = require('../../../../src/js/service/invitation'),
|
|
|
|
Email = require('../../../../src/js/email/email'),
|
|
|
|
PGP = require('../../../../src/js/crypto/pgp'),
|
|
|
|
ReadCtrl = require('../../../../src/js/controller/app/read'),
|
|
|
|
Outbox = require('../../../../src/js/email/outbox'),
|
|
|
|
Dialog = require('../../../../src/js/util/dialog'),
|
|
|
|
Auth = require('../../../../src/js/service/auth'),
|
|
|
|
Download = require('../../../../src/js/util/download');
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
describe('Read Controller unit test', function() {
|
2014-12-18 09:19:06 -05:00
|
|
|
var scope, ctrl, keychainMock, invitationMock, emailMock, pgpMock, outboxMock, dialogMock, authMock, downloadMock;
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2014-11-25 12:19:40 -05:00
|
|
|
keychainMock = sinon.createStubInstance(Keychain);
|
|
|
|
invitationMock = sinon.createStubInstance(InvitationDAO);
|
|
|
|
pgpMock = sinon.createStubInstance(PGP);
|
|
|
|
outboxMock = sinon.createStubInstance(Outbox);
|
|
|
|
emailMock = sinon.createStubInstance(Email);
|
|
|
|
dialogMock = sinon.createStubInstance(Dialog);
|
|
|
|
authMock = sinon.createStubInstance(Auth);
|
|
|
|
downloadMock = sinon.createStubInstance(Download);
|
|
|
|
|
|
|
|
angular.module('readtest', ['woServices']);
|
|
|
|
angular.mock.module('readtest');
|
|
|
|
angular.mock.inject(function($rootScope, $controller) {
|
2014-10-07 14:32:23 -04:00
|
|
|
scope = $rootScope.$new();
|
|
|
|
scope.state = {};
|
|
|
|
ctrl = $controller(ReadCtrl, {
|
2014-11-25 12:19:40 -05:00
|
|
|
$scope: scope,
|
2014-12-18 09:19:06 -05:00
|
|
|
$q: window.qMock,
|
2014-11-25 12:19:40 -05:00
|
|
|
email: emailMock,
|
|
|
|
invitation: invitationMock,
|
|
|
|
outbox: outboxMock,
|
|
|
|
pgp: pgpMock,
|
|
|
|
keychain: keychainMock,
|
|
|
|
download: downloadMock,
|
|
|
|
auth: authMock,
|
|
|
|
dialog: dialogMock
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
afterEach(function() {});
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('scope variables', function() {
|
|
|
|
it('should be set correctly', function() {
|
|
|
|
expect(scope.state.read).to.exist;
|
|
|
|
expect(scope.state.read.open).to.be.false;
|
|
|
|
expect(scope.state.read.toggle).to.exist;
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('open/close read view', function() {
|
|
|
|
it('should open/close', function() {
|
|
|
|
expect(scope.state.read.open).to.be.false;
|
|
|
|
scope.state.read.toggle(true);
|
|
|
|
expect(scope.state.read.open).to.be.true;
|
|
|
|
scope.state.read.toggle(false);
|
|
|
|
expect(scope.state.read.open).to.be.false;
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2015-03-31 09:43:42 -04:00
|
|
|
describe('decrypt', function() {
|
|
|
|
it('should decrypt a message', function(done) {
|
|
|
|
var msg = {};
|
|
|
|
|
|
|
|
emailMock.decryptBody.withArgs({
|
|
|
|
message: msg
|
|
|
|
}).returns(resolves());
|
|
|
|
|
|
|
|
scope.decrypt(msg).then(function() {
|
|
|
|
expect(emailMock.decryptBody.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('getKeyId', function() {
|
|
|
|
var address = 'asfd@asdf.com';
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should show searching on error', function(done) {
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(scope.keyId).to.equal('No key found.');
|
2014-12-18 09:19:06 -05:00
|
|
|
keychainMock.getReceiverPublicKey.returns(rejects(42));
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
scope.getKeyId(address).then(function() {
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true;
|
|
|
|
expect(scope.keyId).to.equal('Searching...');
|
|
|
|
done();
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should allow invitation on empty key', function(done) {
|
|
|
|
keychainMock.getReceiverPublicKey.returns(resolves());
|
2014-11-25 12:19:40 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
scope.getKeyId(address).then(function() {
|
|
|
|
expect(scope.keyId).to.equal('User has no key. Click to invite.');
|
|
|
|
done();
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should show searching on error', function(done) {
|
|
|
|
keychainMock.getReceiverPublicKey.returns(resolves({
|
2014-10-07 14:32:23 -04:00
|
|
|
publicKey: 'PUBLIC KEY'
|
2014-12-18 09:19:06 -05:00
|
|
|
}));
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
pgpMock.getFingerprint.returns('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
scope.getKeyId(address).then(function() {
|
|
|
|
expect(scope.keyId).to.equal('PGP key: XXXXXXXX');
|
|
|
|
done();
|
|
|
|
});
|
2014-02-28 08:45:10 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('invite', function() {
|
|
|
|
it('not allow invitation for secure users', function() {
|
|
|
|
expect(scope.keyId).to.equal('No key found.');
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.invite({
|
|
|
|
secure: true,
|
|
|
|
address: 'asdf@asdf.de'
|
2014-02-28 08:45:10 -05:00
|
|
|
});
|
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(scope.keyId).to.equal('No key found.');
|
|
|
|
});
|
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should show error on invitation dao invite error', function(done) {
|
|
|
|
invitationMock.invite.returns(rejects(42));
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.invite({
|
|
|
|
address: 'asdf@asdf.de'
|
2014-12-18 09:19:06 -05:00
|
|
|
}).then(function() {
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true;
|
|
|
|
done();
|
2014-02-28 08:45:10 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should show error on outbox put error', function(done) {
|
|
|
|
invitationMock.invite.returns(resolves());
|
|
|
|
outboxMock.put.returns(rejects(42));
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.invite({
|
|
|
|
address: 'asdf@asdf.de'
|
2014-12-18 09:19:06 -05:00
|
|
|
}).then(function() {
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true;
|
|
|
|
done();
|
2014-02-28 08:45:10 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should work', function(done) {
|
|
|
|
invitationMock.invite.returns(resolves());
|
|
|
|
outboxMock.put.returns(resolves());
|
2014-02-28 08:45:10 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.invite({
|
|
|
|
address: 'asdf@asdf.de'
|
2014-12-18 09:19:06 -05:00
|
|
|
}).then(function() {
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.false;
|
|
|
|
done();
|
2014-02-28 08:45:10 -05:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-04-23 12:23:46 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('parseConversation', function() {
|
|
|
|
it.skip('should work', function() {
|
|
|
|
var body = 'foo\n' +
|
|
|
|
'\n' +
|
|
|
|
'> bar\n' +
|
|
|
|
'>\n' +
|
|
|
|
'> foofoo\n' +
|
|
|
|
'>> foofoobar\n' +
|
|
|
|
'\ncomment\n' +
|
|
|
|
'>> barbar';
|
|
|
|
|
|
|
|
var nodes = scope.parseConversation({
|
|
|
|
body: body
|
2014-04-23 12:23:46 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(nodes).to.exist;
|
|
|
|
|
|
|
|
var expectedJson = '{"children":["foo\\n",{"children":["bar\\n\\nfoofoo",{"children":["foofoobar"]}]},"\\ncomment",{"children":[{"children":["barbar"]}]}]}';
|
|
|
|
var json = JSON.stringify(nodes);
|
|
|
|
expect(json).to.equal(expectedJson);
|
2014-04-23 12:23:46 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var expectedHtml = '<div class="view-read-body"><div class="line"><span>foo</span><br></div><div class="line empty-line"><span></span><br></div><div class="prev-message"><div class="line"><span>bar</span><br></div><div class="line empty-line"><span></span><br></div><div class="line"><span>foofoo</span><br></div></div><div class="prev-message"><div class="prev-message"><div class="line"><span>foofoobar</span><br></div></div></div><div class="line empty-line"><span></span><br></div><div class="line"><span>comment</span><br></div><div class="prev-message"><div class="prev-message"><div class="line"><span>barbar</span><br></div></div></div></div>';
|
|
|
|
var html = scope.renderNodes(nodes);
|
|
|
|
expect(html).to.equal(expectedHtml);
|
|
|
|
});
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|