From 4b81bc1fdbf08b115f49bc8e0d33c002a1b30ca7 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 16 Jun 2014 17:40:59 -0300 Subject: [PATCH] add tests --- test/mocks/FakeWallet.js | 6 ++++++ test/unit/services/servicesSpec.js | 21 +++++++++++++++++++++ util/build.js | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/test/mocks/FakeWallet.js b/test/mocks/FakeWallet.js index ec7f4fade..cfdcc75b9 100644 --- a/test/mocks/FakeWallet.js +++ b/test/mocks/FakeWallet.js @@ -3,6 +3,7 @@ var FakeWallet = function(){ this.balance=10000; this.safeBalance=1000; this.balanceByAddr={'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000}; + this.name = 'myTESTwullet'; }; FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr){ @@ -28,6 +29,11 @@ FakeWallet.prototype.getBalance=function(cb){ return cb(null, this.balance, this.balanceByAddr, this.safeBalance); }; + +FakeWallet.prototype.toEncryptedObj = function() { + return 'SUPERENCRYPTEDSICRITSTUFF'; +}; + // This mock is meant for karma, module.exports is not necesary. try { module.exports = require('soop')(FakeWallet); diff --git a/test/unit/services/servicesSpec.js b/test/unit/services/servicesSpec.js index f272d51dd..65fed5a81 100644 --- a/test/unit/services/servicesSpec.js +++ b/test/unit/services/servicesSpec.js @@ -87,3 +87,24 @@ describe("Unit: controllerUtils", function() { }); + + +describe("Unit: Backup Service", function() { + var sinon = require('../sinon'); + beforeEach(angular.mock.module('copayApp.services')); + it('should contain a backup service', inject(function(backupService) { + expect(backupService).not.to.equal(null); + })); + it('should backup in file', inject(function(backupService) { + var mock = sinon.mock(window); + var expectation = mock.expects('saveAs'); + backupService.download(new FakeWallet()); + expectation.once(); + })); + it('should backup by email', inject(function(backupService) { + var mock = sinon.mock(window); + var expectation = mock.expects('open'); + backupService.sendEmail('fake@test.com', new FakeWallet()); + expectation.once(); + })); +}); diff --git a/util/build.js b/util/build.js index 7a1be5ffe..220162f47 100755 --- a/util/build.js +++ b/util/build.js @@ -80,6 +80,11 @@ var createBundle = function(opts) { expose: '../js/models/core/Passphrase' }); + if (opts.dontminify) { + b.require('sinon', { + expose: '../sinon' + }); + } if (!opts.dontminify) { b.transform({ global: true