From f3e670e08a37f57136320cdec7d80ec23568c25d Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 9 May 2017 13:41:53 +0200 Subject: [PATCH 01/15] register active network after peers are available in login --- src/app/components/login/login.js | 5 ++++- src/app/components/main/main.js | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js index 278e5d576..2432a9fd5 100644 --- a/src/app/components/login/login.js +++ b/src/app/components/login/login.js @@ -8,7 +8,7 @@ app.component('login', { /* eslint no-param-reassign: ["error", { "props": false }] */ constructor($scope, $rootScope, $timeout, $document, $mdMedia, - $cookies, $location, Passphrase, $state, Account) { + $cookies, $location, Passphrase, $state, Account, $peers) { this.$scope = $scope; this.$rootScope = $rootScope; this.$timeout = $timeout; @@ -18,6 +18,7 @@ app.component('login', { this.$location = $location; this.$state = $state; this.account = Account; + this.$peers = $peers; this.Passphrase = Passphrase; this.generatingNewPassphrase = false; @@ -50,6 +51,8 @@ app.component('login', { passConfirmSubmit(_passphrase = this.input_passphrase) { if (this.Passphrase.normalize.constructor === Function) { + this.$peers.setActive(this.network); + this.account.set({ passphrase: this.Passphrase.normalize(_passphrase), network: this.network, diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js index cfee0596b..6ecc564f7 100644 --- a/src/app/components/main/main.js +++ b/src/app/components/main/main.js @@ -31,8 +31,6 @@ app.component('main', { this.$rootScope.prelogged = true; - this.$peers.setActive(this.account.get()); - this.update() .then(() => { this.$rootScope.prelogged = false; From c8dbda20e9ee2f94de128cc658512d10a9da1a5f Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 9 May 2017 13:44:59 +0200 Subject: [PATCH 02/15] - Send change list through onAccountChange event. - Move Api calls to a separated service. --- src/app/services/account.js | 46 +++++++++++------------------- src/app/services/api/accountApi.js | 36 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 30 deletions(-) create mode 100644 src/app/services/api/accountApi.js diff --git a/src/app/services/account.js b/src/app/services/account.js index afe408c98..5abd2a829 100644 --- a/src/app/services/account.js +++ b/src/app/services/account.js @@ -1,21 +1,35 @@ import lisk from 'lisk-js'; -app.factory('Account', function ($rootScope, $peers, $q) { +app.factory('Account', function ($rootScope, $q) { this.account = {}; const merge = (obj) => { const keys = Object.keys(obj); + const changes = {}; + keys.forEach((key) => { + changes[key] = { + old: this.account[key], + new: obj[key], + }; this.account[key] = obj[key]; if (key === 'passphrase') { const kp = lisk.crypto.getKeys(obj[key]); + + changes.account = { + old: this.account.publicKey, + new: kp.publicKey, + }; this.account.publicKey = kp.publicKey; + + changes.address = { old: this.account.address }; this.account.address = lisk.crypto.getAddress(kp.publicKey); + changes.address.new = this.account.address; } // Calling listeners with the list of changes - $rootScope.$broadcast('onAccountChange', this.account); + $rootScope.$broadcast('onAccountChange', changes); }); }; @@ -33,33 +47,5 @@ app.factory('Account', function ($rootScope, $peers, $q) { }); }; - this.getAccountPromise = (address) => { - const deferred = $q.defer(); - $peers.active.getAccount(this.account.address, (data) => { - if (data.success) { - deferred.resolve(data.account); - } else { - deferred.resolve({ - address, - balance: 0, - }); - } - }); - return deferred.promise; - }; - - this.sendLSK = (recipientId, amount, secret, secondSecret) => $peers.sendRequestPromise( - 'transactions', { recipientId, amount, secret, secondSecret }); - - this.listTransactions = (address, limit = 20, offset = 0) => $peers.sendRequestPromise('transactions', { - senderId: address, - recipientId: address, - limit, - offset, - }); - - this.setSecondSecret = (secondSecret, publicKey, secret) => $peers.sendRequestPromise( - 'signatures', { secondSecret, publicKey, secret }); - return this; }); diff --git a/src/app/services/api/accountApi.js b/src/app/services/api/accountApi.js new file mode 100644 index 000000000..9e27cdee7 --- /dev/null +++ b/src/app/services/api/accountApi.js @@ -0,0 +1,36 @@ +app.factory('AccountApi', function ($rootScope, $peers, $q, Account) { + this.get = (address) => { + const deferred = $q.defer(); + $peers.active.getAccount(Account.get().address, (data) => { + if (data.success) { + deferred.resolve(data.account); + } else { + deferred.resolve({ + address, + balance: 0, + }); + } + }); + return deferred.promise; + }; + + this.setSecondSecret = (secondSecret, publicKey, secret) => $peers.sendRequestPromise( + 'signatures', { secondSecret, publicKey, secret }); + + this.transactions = {}; + + this.transactions.create = (recipientId, amount, secret, secondSecret) => $peers.sendRequestPromise( + 'transactions', { recipientId, amount, secret, secondSecret }); + + this.transactions.get = (address, limit = 20, offset = 0) => $peers.sendRequestPromise('transactions', { + senderId: address, + recipientId: address, + limit, + offset, + }); + + return this; +}); + + + From a9df60048e5626fafa3078b5e305d1c5f796b9df Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 9 May 2017 13:45:51 +0200 Subject: [PATCH 03/15] Minor markup fixing --- src/app/components/send/send.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/send/send.pug b/src/app/components/send/send.pug index fde51cbde..c3c8e0ed4 100644 --- a/src/app/components/send/send.pug +++ b/src/app/components/send/send.pug @@ -12,7 +12,7 @@ div.dialog-send(aria-label='Send funds') div(ng-messages='$ctrl.sendForm.recipient.$error') div(ng-message='required') Required div(ng-message='pattern') Invalid -
+ .row md-input-container.md-block.flex-95 label Transaction Amount input(type='text', name='amount', ng-model='$ctrl.amount.value', required, ng-pattern='$ctrl.amount.regexp', ng-disabled='$ctrl.loading', ng-max='$ctrl.amount.max') From 80763f5ff75bcc50feea01b2d05839a2c63a1d36 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 9 May 2017 13:50:21 +0200 Subject: [PATCH 04/15] Adapt Account service usages with the new methods of AccountApi --- src/app/components/main/main.js | 5 +++-- src/app/components/main/setSecondPassDirective.js | 4 ++-- src/app/components/send/send.js | 5 +++-- src/app/components/transactions/transactions.js | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js index 6ecc564f7..637a9ee66 100644 --- a/src/app/components/main/main.js +++ b/src/app/components/main/main.js @@ -7,7 +7,7 @@ app.component('main', { controllerAs: '$ctrl', controller: class main { constructor($scope, $rootScope, $timeout, $q, $state, $peers, - dialog, SendModal, Account) { + dialog, SendModal, Account, AccountApi) { this.$scope = $scope; this.$rootScope = $rootScope; this.$timeout = $timeout; @@ -17,6 +17,7 @@ app.component('main', { this.sendModal = SendModal; this.$state = $state; this.account = Account; + this.accountApi = AccountApi; this.init(); } @@ -69,7 +70,7 @@ app.component('main', { update() { this.$rootScope.reset(); - return this.account.getAccountPromise(this.account.get().address) + return this.accountApi.get(this.account.get().address) .then((res) => { this.account.set({ balance: res.balance }); }) diff --git a/src/app/components/main/setSecondPassDirective.js b/src/app/components/main/setSecondPassDirective.js index cdfae8942..9e2f05421 100644 --- a/src/app/components/main/setSecondPassDirective.js +++ b/src/app/components/main/setSecondPassDirective.js @@ -1,6 +1,6 @@ import './secondPass.less'; -app.directive('setSecondPass', (setSecondPass, Account, $rootScope, dialog) => { +app.directive('setSecondPass', (setSecondPass, Account, $rootScope, dialog, AccountApi) => { /* eslint no-param-reassign: ["error", { "props": false }] */ const SetSecondPassLink = function (scope, element, attrs) { element.bind('click', () => { @@ -8,7 +8,7 @@ app.directive('setSecondPass', (setSecondPass, Account, $rootScope, dialog) => { }); scope.passConfirmSubmit = (secondsecret) => { - Account.setSecondSecret(secondsecret, attrs.publicKey, attrs.passphrase) + AccountApi.setSecondSecret(secondsecret, attrs.publicKey, attrs.passphrase) .then(() => { dialog.successAlert('Your second passphrase was successfully registered.'); }) diff --git a/src/app/components/send/send.js b/src/app/components/send/send.js index 9408e2fa1..59b28240f 100644 --- a/src/app/components/send/send.js +++ b/src/app/components/send/send.js @@ -10,7 +10,7 @@ app.component('send', { transferAmount: '<', }, controller: class send { - constructor($scope, $peers, lsk, dialog, $mdDialog, $q, $rootScope, Account) { + constructor($scope, $peers, lsk, dialog, $mdDialog, $q, $rootScope, Account, AccountApi) { this.$scope = $scope; this.$peers = $peers; this.dialog = dialog; @@ -18,6 +18,7 @@ app.component('send', { this.$q = $q; this.$rootScope = $rootScope; this.account = Account; + this.accountApi = AccountApi; this.recipient = { regexp: ADDRESS_VALID_RE, @@ -81,7 +82,7 @@ app.component('send', { this.promptSecondPassphrase() .then((secondPassphrase) => { - this.account.sendLSK( + this.accountApi.transactions.create( this.recipient.value, this.amount.raw, this.account.get().passphrase, diff --git a/src/app/components/transactions/transactions.js b/src/app/components/transactions/transactions.js index de967f66e..a7cf378ad 100644 --- a/src/app/components/transactions/transactions.js +++ b/src/app/components/transactions/transactions.js @@ -5,13 +5,14 @@ const UPDATE_INTERVAL = 20000; app.component('transactions', { template: require('./transactions.pug')(), controller: class transactions { - constructor($scope, $rootScope, $timeout, $q, $peers, Account) { + constructor($scope, $rootScope, $timeout, $q, $peers, Account, AccountApi) { this.$scope = $scope; this.$rootScope = $rootScope; this.$timeout = $timeout; this.$q = $q; this.$peers = $peers; this.account = Account; + this.accountApi = AccountApi; this.loaded = false; this.transactions = []; @@ -66,7 +67,7 @@ app.component('transactions', { limit = 10; } - return this.account.listTransactions(this.account.get().address, limit) + return this.accountApi.transactions.get(this.account.get().address, limit) .then(this._processTransactionsResponse.bind(this)) .catch(() => { this.transactions = []; From 47c7962731090a48d3477704d0de7005c587cb7f Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 9 May 2017 13:50:42 +0200 Subject: [PATCH 05/15] Remove unnecessary comment --- src/app/states.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/states.js b/src/app/states.js index 28b91a463..b28a51574 100644 --- a/src/app/states.js +++ b/src/app/states.js @@ -24,5 +24,4 @@ app.config(($stateProvider, $urlRouterProvider) => { component: 'forging', }); $urlRouterProvider.otherwise('/404'); - // $locationProvider.html5Mode(true); }); From 4bd7a9c5c5060b05e14cdd3ac38fcde66de84cc2 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 9 May 2017 13:52:30 +0200 Subject: [PATCH 06/15] Inject AccountApi service to application --- src/app/lisk-nano.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/lisk-nano.js b/src/app/lisk-nano.js index 30744a196..ac79b6054 100644 --- a/src/app/lisk-nano.js +++ b/src/app/lisk-nano.js @@ -30,6 +30,7 @@ import './services/sign-verify'; import './services/account'; import './services/delegateService'; import './services/forgingService'; +import './services/api/accountApi'; import './filters/lsk'; From 3ff3f8bb15a2136197c0e4e295b5ef8f10b11954 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 9 May 2017 13:57:24 +0200 Subject: [PATCH 07/15] - Move Api services to services/api directory. - Remove initial calls for setActive method in peers service --- src/app/lisk-nano.js | 6 +++--- .../{delegateService.js => api/delegateApi.js} | 0 .../services/{forgingService.js => api/forgingApi.js} | 0 src/app/services/{peers => api}/peers.js | 11 +++-------- 4 files changed, 6 insertions(+), 11 deletions(-) rename src/app/services/{delegateService.js => api/delegateApi.js} (100%) rename src/app/services/{forgingService.js => api/forgingApi.js} (100%) rename src/app/services/{peers => api}/peers.js (87%) diff --git a/src/app/lisk-nano.js b/src/app/lisk-nano.js index ac79b6054..9708a8c86 100644 --- a/src/app/lisk-nano.js +++ b/src/app/lisk-nano.js @@ -22,14 +22,14 @@ import './components/sign-verify/sign-message'; import './components/sign-verify/verify-message'; import './components/delegate-registration/delegateRegistration'; -import './services/peers/peers'; +import './services/api/peers'; import './services/lsk'; import './services/dialog'; import './services/passphrase'; import './services/sign-verify'; import './services/account'; -import './services/delegateService'; -import './services/forgingService'; +import './services/api/delegateApi'; +import './services/api/forgingApi'; import './services/api/accountApi'; import './filters/lsk'; diff --git a/src/app/services/delegateService.js b/src/app/services/api/delegateApi.js similarity index 100% rename from src/app/services/delegateService.js rename to src/app/services/api/delegateApi.js diff --git a/src/app/services/forgingService.js b/src/app/services/api/forgingApi.js similarity index 100% rename from src/app/services/forgingService.js rename to src/app/services/api/forgingApi.js diff --git a/src/app/services/peers/peers.js b/src/app/services/api/peers.js similarity index 87% rename from src/app/services/peers/peers.js rename to src/app/services/api/peers.js index 9f0c8302c..2a6856b1c 100644 --- a/src/app/services/peers/peers.js +++ b/src/app/services/api/peers.js @@ -6,10 +6,6 @@ app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope) => { class $peers { constructor() { this.check(); - - $rootScope.$on('onAccountChange', (event, account) => { - this.setActive(account); - }); } reset(active) { @@ -20,9 +16,8 @@ app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope) => { } } - setActive(account) { + setActive(network) { let conf = { }; - const network = account.network; if (network) { conf = network; if (network.address) { @@ -50,7 +45,7 @@ app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope) => { return deferred.promise; } - getStatusPromise() { + getStatus() { return this.sendRequestPromise('loader/status', {}); } @@ -64,7 +59,7 @@ app.factory('$peers', ($timeout, $cookies, $location, $q, $rootScope) => { return; } - this.getStatusPromise() + this.getStatus() .then(() => this.online = true) .catch(() => this.online = false) .finally(() => next()); From 05b7e917018dd4bb008282bf3a5204279bc26fae Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 10 May 2017 10:16:25 +0200 Subject: [PATCH 08/15] - Move peers test to api directivery. - Rename the peers service --- .../components/sign-verify/verify-message.js | 1 + .../services/{peers => api}/peers.spec.js | 32 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) rename src/test/services/{peers => api}/peers.spec.js (59%) diff --git a/src/app/components/sign-verify/verify-message.js b/src/app/components/sign-verify/verify-message.js index da217bd86..9e963b301 100644 --- a/src/app/components/sign-verify/verify-message.js +++ b/src/app/components/sign-verify/verify-message.js @@ -2,6 +2,7 @@ import lisk from 'lisk-js'; app.component('verifyMessage', { template: require('./verify-message.pug')(), + controllerAs: '$ctrl', controller: class verifyMessage { constructor($mdDialog, Account) { this.$mdDialog = $mdDialog; diff --git a/src/test/services/peers/peers.spec.js b/src/test/services/api/peers.spec.js similarity index 59% rename from src/test/services/peers/peers.spec.js rename to src/test/services/api/peers.spec.js index 7ca782b6e..8af407e72 100644 --- a/src/test/services/peers/peers.spec.js +++ b/src/test/services/api/peers.spec.js @@ -5,30 +5,30 @@ const sinonChai = require('sinon-chai'); const expect = chai.expect; chai.use(sinonChai); -describe('Factory: $peers', () => { - let $peers; +describe('Factory: Peers', () => { + let Peers; let $q; let $rootScope; beforeEach(angular.mock.module('app')); - beforeEach(inject((_$peers_, _$q_, _$rootScope_) => { - $peers = _$peers_; + beforeEach(inject((_Peers_, _$q_, _$rootScope_) => { + Peers = _Peers_; $q = _$q_; $rootScope = _$rootScope_; })); describe('setActive(account)', () => { - it('sets $peers.active to a random active official peer', () => { + it('sets Peers.active to a random active official peer', () => { const account = { network: { address: 'http://localhost:8000', }, }; - expect($peers.active).to.equal(undefined); - $peers.setActive(account); - expect($peers.active).not.to.equal(undefined); - expect($peers.active.currentPeer).not.to.equal(undefined); + expect(Peers.active).to.equal(undefined); + Peers.setActive(account); + expect(Peers.active).not.to.equal(undefined); + expect(Peers.active.currentPeer).not.to.equal(undefined); }); }); @@ -38,9 +38,9 @@ describe('Factory: $peers', () => { beforeEach(() => { deffered = $q.defer(); - mock = sinon.mock($peers); - mock.expects('getStatusPromise').returns(deffered.promise); - $peers.active = {}; + mock = sinon.mock(Peers); + mock.expects('getStatus').returns(deffered.promise); + Peers.active = {}; }); afterEach(() => { @@ -49,17 +49,17 @@ describe('Factory: $peers', () => { }); it('checks active peer status and if that succeeds then sets this.online = true', () => { - $peers.check(); + Peers.check(); deffered.resolve(); $rootScope.$apply(); - expect($peers.online).to.equal(true); + expect(Peers.online).to.equal(true); }); it('checks active peer status and if that fails then sets this.online = false', () => { - $peers.check(); + Peers.check(); deffered.reject(); $rootScope.$apply(); - expect($peers.online).to.equal(false); + expect(Peers.online).to.equal(false); }); }); }); From bf38165990002cd24285bd08d3cff823019af4d6 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 10 May 2017 10:19:13 +0200 Subject: [PATCH 09/15] - Separate account tests from accountApi. - Rename delegateService and forginService. - Use new service names --- src/test/services/account.spec.js | 83 ++++++---------- src/test/services/api/accountApi.spec.js | 96 +++++++++++++++++++ .../delegateApi.spec.js} | 18 ++-- .../forgingApi.spec.js} | 14 +-- 4 files changed, 140 insertions(+), 71 deletions(-) create mode 100644 src/test/services/api/accountApi.spec.js rename src/test/services/{delegateService.spec.js => api/delegateApi.spec.js} (83%) rename src/test/services/{forgingService.spec.js => api/forgingApi.spec.js} (78%) diff --git a/src/test/services/account.spec.js b/src/test/services/account.spec.js index a385e46c9..dc4bc6797 100644 --- a/src/test/services/account.spec.js +++ b/src/test/services/account.spec.js @@ -2,81 +2,54 @@ const chai = require('chai'); const sinon = require('sinon'); const sinonChai = require('sinon-chai'); +const VALID_PASSPHRASE = 'illegal symbol search tree deposit youth mixture craft amazing tool soon unit'; + const expect = chai.expect; chai.use(sinonChai); describe('Factory: Account', () => { - let $peers; - let $q; let account; - let mock; - let deffered; + let $rootScope; beforeEach(angular.mock.module('app')); - beforeEach(inject((_$peers_, _$q_, Account) => { - $peers = _$peers_; - $q = _$q_; - account = Account; + beforeEach(inject((_Account_, _$rootScope_) => { + account = _Account_; + $rootScope = _$rootScope_; })); - beforeEach(() => { - deffered = $q.defer(); - mock = sinon.mock($peers); - }); - - afterEach(() => { - mock.verify(); - mock.restore(); - }); - - describe('sendLSK(recipientId, amount, secret, secondSecret)', () => { - it('returns $peers.sendRequestPromise(\'transactions\', options);', () => { - const options = { - recipientId: '537318935439898807L', - amount: 10, - secret: 'wagon stock borrow episode laundry kitten salute link globe zero feed marble', - secondSecret: null, - }; - mock.expects('sendRequestPromise').withArgs('transactions', options).returns(deffered.promise); + describe('set(config)', () => { + it('returns this.account', () => { + const accountInstanse = account.get(); - const promise = account.sendLSK( - options.recipientId, options.amount, options.secret, options.secondSecret); + const setReturnValue = account.set({ passphrase: VALID_PASSPHRASE }); - expect(promise).to.equal(deffered.promise); + expect(setReturnValue).to.equal(accountInstanse); }); - }); - describe('listTransactions(address, limit, offset)', () => { - it('returns $peers.sendRequestPromise(\'transactions\', options);', () => { - const options = { - senderId: '537318935439898807L', - recipientId: '537318935439898807L', - limit: 20, - offset: 0, - }; - mock.expects('sendRequestPromise').withArgs('transactions', options).returns(deffered.promise); + it('should set address and publicKey for a given valid passphrase', () => { + const accountInstanse = account.set({ passphrase: VALID_PASSPHRASE }); - const promise = account.listTransactions( - options.recipientId, options.limit, options.offset); + expect(accountInstanse.address).to.not.equal(undefined); + expect(accountInstanse.publicKey).to.not.equal(undefined); + }); - expect(promise).to.equal(deffered.promise); + it('should broadcast the changes', () => { + const spy = sinon.spy($rootScope, '$broadcast'); + account.set({ passphrase: VALID_PASSPHRASE }); + expect(spy).to.have.been.calledWith(); }); }); - describe('setSecondSecret(secondSecret, publicKey, secret)', () => { - it('returns $peers.sendRequestPromise(\'signatures\', { secondSecret, publicKey, secret });', () => { - const publicKey = '3ff32442bb6da7d60c1b7752b24e6467813c9b698e0f278d48c43580da972135'; - const secret = 'wagon stock borrow episode laundry kitten salute link globe zero feed marble'; - const secondSecret = 'stay undo beyond powder sand laptop grow gloom apology hamster primary arrive'; - mock.expects('sendRequestPromise') - .withArgs('signatures', { secondSecret, publicKey, secret }) - .returns(deffered.promise); + describe('get(config)', () => { + it('returns this.account', () => { + account.set({ passphrase: VALID_PASSPHRASE }); + const accountInstanse = account.get(); - const promise = account.setSecondSecret(secondSecret, publicKey, secret); - - expect(promise).to.equal(deffered.promise); + expect(accountInstanse).to.not.equal(undefined); + expect(accountInstanse.address).to.not.equal(undefined); + expect(accountInstanse.publicKey).to.not.equal(undefined); + expect(accountInstanse.passphrase).to.not.equal(undefined); }); }); }); - diff --git a/src/test/services/api/accountApi.spec.js b/src/test/services/api/accountApi.spec.js new file mode 100644 index 000000000..31142e837 --- /dev/null +++ b/src/test/services/api/accountApi.spec.js @@ -0,0 +1,96 @@ +const chai = require('chai'); +const sinon = require('sinon'); +const sinonChai = require('sinon-chai'); + +const expect = chai.expect; +chai.use(sinonChai); + +describe('Factory: AccountApi', () => { + let peers; + let $q; + let accountApi; + let peersMock; + let deffered; + + beforeEach(angular.mock.module('app')); + + beforeEach(inject((_Peers_, _$q_, _AccountApi_) => { + peers = _Peers_; + $q = _$q_; + accountApi = _AccountApi_; + })); + + beforeEach(() => { + deffered = $q.defer(); + peersMock = sinon.mock(peers); + peers.setActive({ + name: 'Mainnet', + }); + }); + + afterEach(() => { + peersMock.verify(); + peersMock.restore(); + }); + + describe('transaction.create(recipientId, amount, secret, secondSecret)', () => { + it('returns Peers.sendRequest(\'transactions\', options);', () => { + console.log(deffered); + const options = { + recipientId: '537318935439898807L', + amount: 10, + secret: 'wagon stock borrow episode laundry kitten salute link globe zero feed marble', + secondSecret: null, + }; + const spy = sinon.spy(peers, 'sendRequestPromise'); + // peers.expects('sendRequestPromise').withArgs('transactions', + // options).returns(deffered.promise); + + accountApi.transactions.create( + options.recipientId, options.amount, options.secret, options.secondSecret); + + expect(spy).to.have.been.calledWith('transactions', options); + // expect(promise).to.equal(deffered.promise); + }); + }); + + describe('transaction.get(address, limit, offset)', () => { + it('returns Peers.sendRequest(\'transactions\', options);', () => { + const options = { + senderId: '537318935439898807L', + recipientId: '537318935439898807L', + limit: 20, + offset: 0, + }; + + const spy = sinon.spy(peers, 'sendRequestPromise'); + // peersMock.expects('sendRequestPromise').withArgs('transactions', + // options).returns(deffered.promise); + + accountApi.transactions.get( + options.recipientId, options.limit, options.offset); + + expect(spy).to.have.been.calledWith('transactions', options); + // expect(promise).to.equal(deffered.promise); + }); + }); + + describe('setSecondSecret(secondSecret, publicKey, secret)', () => { + it('returns Peers.sendRequestPromise(\'signatures\', { secondSecret, publicKey, secret });', () => { + const publicKey = '3ff32442bb6da7d60c1b7752b24e6467813c9b698e0f278d48c43580da972135'; + const secret = 'wagon stock borrow episode laundry kitten salute link globe zero feed marble'; + const secondSecret = 'stay undo beyond powder sand laptop grow gloom apology hamster primary arrive'; + + const spy = sinon.spy(peers, 'sendRequestPromise'); + // peersMock.expects('sendRequestPromise') + // .withArgs('signatures', { secondSecret, publicKey, secret }) + // .returns(deffered.promise); + + accountApi.setSecondSecret(secondSecret, publicKey, secret); + + expect(spy).to.have.been.calledWith('signatures', { secondSecret, publicKey, secret }); + // expect(promise).to.equal(deffered.promise); + }); + }); +}); + diff --git a/src/test/services/delegateService.spec.js b/src/test/services/api/delegateApi.spec.js similarity index 83% rename from src/test/services/delegateService.spec.js rename to src/test/services/api/delegateApi.spec.js index fa13dc6d2..48a953455 100644 --- a/src/test/services/delegateService.spec.js +++ b/src/test/services/api/delegateApi.spec.js @@ -6,7 +6,7 @@ const expect = chai.expect; chai.use(sinonChai); describe('Factory: delegateService', () => { - let $peers; + let Peers; let $q; let delegateService; let mock; @@ -14,15 +14,15 @@ describe('Factory: delegateService', () => { beforeEach(angular.mock.module('app')); - beforeEach(inject((_$peers_, _$q_, _delegateService_) => { - $peers = _$peers_; + beforeEach(inject((_Peers_, _$q_, _delegateService_) => { + Peers = _Peers_; $q = _$q_; delegateService = _delegateService_; })); beforeEach(() => { deffered = $q.defer(); - mock = sinon.mock($peers); + mock = sinon.mock(Peers); }); afterEach(() => { @@ -31,7 +31,7 @@ describe('Factory: delegateService', () => { }); describe('listAccountDelegates(options)', () => { - it('returns $peers.sendRequestPromise(\'accounts/delegates\', options);', () => { + it('returns Peers.sendRequestPromise(\'accounts/delegates\', options);', () => { const options = { account: {}, }; @@ -44,7 +44,7 @@ describe('Factory: delegateService', () => { }); describe('listDelegates(options)', () => { - it('returns $peers.sendRequestPromise(\'delegates\', options);', () => { + it('returns Peers.sendRequestPromise(\'delegates\', options);', () => { const options = { username: 'genesis_42', }; @@ -57,7 +57,7 @@ describe('Factory: delegateService', () => { }); describe('getDelegate(options)', () => { - it('returns $peers.sendRequestPromise(\'delegates/get\', options);', () => { + it('returns Peers.sendRequestPromise(\'delegates/get\', options);', () => { const options = { username: 'genesis_42', }; @@ -70,7 +70,7 @@ describe('Factory: delegateService', () => { }); describe('vote(options)', () => { - it('returns $peers.sendRequestPromise(\'accounts/delegates\', options);', () => { + it('returns Peers.sendRequestPromise(\'accounts/delegates\', options);', () => { const options = { secret: '', publicKey: '', @@ -91,7 +91,7 @@ describe('Factory: delegateService', () => { }); describe('voteAutocomplete(username, votedDict)', () => { - it('returns $peers.sendRequestPromise(\'delegates/search\', {q: username}) delegates filtered by not in voteDialog);', () => { + it('returns Peers.sendRequestPromise(\'delegates/search\', {q: username}) delegates filtered by not in voteDialog);', () => { const username = 'genesis_4'; const votedDict = { genesis_44: { diff --git a/src/test/services/forgingService.spec.js b/src/test/services/api/forgingApi.spec.js similarity index 78% rename from src/test/services/forgingService.spec.js rename to src/test/services/api/forgingApi.spec.js index 73e69c673..5b49ac5f8 100644 --- a/src/test/services/forgingService.spec.js +++ b/src/test/services/api/forgingApi.spec.js @@ -6,7 +6,7 @@ const expect = chai.expect; chai.use(sinonChai); describe('Factory: forgingService', () => { - let $peers; + let Peers; let $q; let forgingService; let mock; @@ -14,15 +14,15 @@ describe('Factory: forgingService', () => { beforeEach(angular.mock.module('app')); - beforeEach(inject((_$peers_, _$q_, _forgingService_) => { - $peers = _$peers_; + beforeEach(inject((_Peers_, _$q_, _forgingService_) => { + Peers = _Peers_; $q = _$q_; forgingService = _forgingService_; })); beforeEach(() => { deffered = $q.defer(); - mock = sinon.mock($peers); + mock = sinon.mock(Peers); }); afterEach(() => { @@ -31,7 +31,7 @@ describe('Factory: forgingService', () => { }); describe('getDelegate()', () => { - it('returns $peers.sendRequestPromise(\'delegates/get\');', () => { + it('returns Peers.sendRequestPromise(\'delegates/get\');', () => { mock.expects('sendRequestPromise').withArgs('delegates/get').returns(deffered.promise); const promise = forgingService.getDelegate(); @@ -41,7 +41,7 @@ describe('Factory: forgingService', () => { }); describe('getForgedBlocks(limit, offset)', () => { - it('returns $peers.sendRequestPromise(\'blocks\');', () => { + it('returns Peers.sendRequestPromise(\'blocks\');', () => { mock.expects('sendRequestPromise').withArgs('blocks').returns(deffered.promise); const promise = forgingService.getForgedBlocks(); @@ -51,7 +51,7 @@ describe('Factory: forgingService', () => { }); describe('getForgedStats(startMoment)', () => { - it('returns $peers.sendRequestPromise(\'delegates/forging/getForgedByAccount\');', () => { + it('returns Peers.sendRequestPromise(\'delegates/forging/getForgedByAccount\');', () => { mock.expects('sendRequestPromise').withArgs('delegates/forging/getForgedByAccount').returns(deffered.promise); const promise = forgingService.getForgedStats(); From 1dabe821af73511acec61fa94652b72dd4907dee Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 10 May 2017 10:24:37 +0200 Subject: [PATCH 10/15] Inject scripts with new names --- src/test/test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/test/test.js b/src/test/test.js index bae1e8654..fa6e87aa3 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -16,12 +16,15 @@ require('./components/sign-verify/sign-message.spec'); require('./components/sign-verify/verify-message.spec'); require('./components/delegate-registration/delegateRegistration.spec.js'); -require('./services/account.spec'); -require('./services/peers/peers.spec'); require('./services/passphrase.spec'); require('./services/sign-verify.spec'); require('./services/lsk.spec'); -require('./services/delegateService.spec'); -require('./services/forgingService.spec'); +require('./services/api/peers.spec'); +require('./services/api/delegateApi.spec'); +require('./services/api/forgingApi.spec'); +require('./services/api/accountApi.spec'); +require('./services/account.spec'); + +require('./run.spec'); require('./util/animateOnChange/animateOnChange.spec'); From 69b32dfa40dc3ce9aa7ec4af45928d2b36bfe212 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 10 May 2017 10:29:10 +0200 Subject: [PATCH 11/15] - Correct the usages of account/accountApi. - Rename peers service --- .../components/delegates/delegates.spec.js | 20 ++++++------ src/test/components/delegates/vote.spec.js | 8 ++--- src/test/components/main/main.spec.js | 31 +++++++++---------- .../main/setSecondPassDirective.spec.js | 18 +++++------ src/test/components/send/send.spec.js | 20 ++++++------ .../transactions/transactions.spec.js | 22 +++++++------ 6 files changed, 61 insertions(+), 58 deletions(-) diff --git a/src/test/components/delegates/delegates.spec.js b/src/test/components/delegates/delegates.spec.js index 696c83f7f..0b5f2a1b1 100644 --- a/src/test/components/delegates/delegates.spec.js +++ b/src/test/components/delegates/delegates.spec.js @@ -10,21 +10,21 @@ describe('Delegates component', () => { let $rootScope; let element; let $scope; - let $peers; + let Peers; let lsk; beforeEach(angular.mock.module('app')); - beforeEach(inject((_$compile_, _$rootScope_, _$peers_, _lsk_) => { + beforeEach(inject((_$compile_, _$rootScope_, _Peers_, _lsk_) => { $compile = _$compile_; $rootScope = _$rootScope_; - $peers = _$peers_; + Peers = _Peers_; lsk = _lsk_; })); beforeEach(() => { - $peers.active = { sendRequest() {} }; - const mock = sinon.mock($peers.active); + Peers.active = { sendRequest() {} }; + const mock = sinon.mock(Peers.active); mock.expects('sendRequest').withArgs('accounts/delegates').callsArgWith(2, { success: true, delegates: Array.from({ length: 10 }, (v, k) => ({ @@ -62,15 +62,15 @@ describe('delegates component controller', () => { let controller; let $componentController; let activePeerMock; - let $peers; + let Peers; let delegates; let $q; let $timeout; - beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _$peers_, _$timeout_) => { + beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Peers_, _$timeout_) => { $componentController = _$componentController_; $rootScope = _$rootScope_; - $peers = _$peers_; + Peers = _Peers_; $q = _$q_; $timeout = _$timeout_; })); @@ -81,8 +81,8 @@ describe('delegates component controller', () => { status: {}, })); - $peers.active = { sendRequest() {} }; - activePeerMock = sinon.mock($peers.active); + Peers.active = { sendRequest() {} }; + activePeerMock = sinon.mock(Peers.active); $scope = $rootScope.$new(); controller = $componentController('delegates', $scope, { diff --git a/src/test/components/delegates/vote.spec.js b/src/test/components/delegates/vote.spec.js index d0b3499dd..dc835cfc9 100644 --- a/src/test/components/delegates/vote.spec.js +++ b/src/test/components/delegates/vote.spec.js @@ -10,20 +10,20 @@ describe('Vote component', () => { let $rootScope; let element; let $scope; - let $peers; + let Peers; let lsk; beforeEach(angular.mock.module('app')); - beforeEach(inject((_$compile_, _$rootScope_, _$peers_, _lsk_) => { + beforeEach(inject((_$compile_, _$rootScope_, _Peers_, _lsk_) => { $compile = _$compile_; $rootScope = _$rootScope_; - $peers = _$peers_; + Peers = _Peers_; lsk = _lsk_; })); beforeEach(() => { - $peers.active = { sendRequest() {} }; + Peers.active = { sendRequest() {} }; $scope = $rootScope.$new(); $scope.passphrase = 'robust swift grocery peasant forget share enable convince deputy road keep cheap'; diff --git a/src/test/components/main/main.spec.js b/src/test/components/main/main.spec.js index 893d278f5..e3fc2dfd1 100644 --- a/src/test/components/main/main.spec.js +++ b/src/test/components/main/main.spec.js @@ -20,29 +20,28 @@ describe('main component controller', () => { let $componentController; let controller; let account; + let peers; + let accountApi; let delegateService; - beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Account_, _delegateService_) => { + beforeEach(inject((_$componentController_, _$rootScope_, _Peers_, + _$q_, _Account_, _AccountApi_, _delegateService_) => { $componentController = _$componentController_; $rootScope = _$rootScope_; $q = _$q_; account = _Account_; + accountApi = _AccountApi_; delegateService = _delegateService_; + peers = _Peers_; })); beforeEach(() => { $scope = $rootScope.$new(); account.set({ passphrase: delegateAccount.passphrase }); - controller = $componentController('main', $scope, {}); - }); - - describe('reset()', () => { - // There's no reset anymore - it.skip('cancels $timeout', () => { - const spy = sinon.spy(controller.$timeout, 'cancel'); - controller.reset(); - expect(spy).to.have.been.calledWith(controller.timeout); + peers.setActive({ + name: 'Mainnet', }); + controller = $componentController('main', $scope, {}); }); describe('init()', () => { @@ -55,7 +54,7 @@ describe('main component controller', () => { updateMock = sinon.mock(controller); updateMock.expects('update').withArgs().returns(deffered.promise); - peersMock = sinon.mock(controller.$peers); + peersMock = sinon.mock(controller.peers); peersMock.expects('setActive').withArgs(); }); @@ -153,9 +152,9 @@ describe('main component controller', () => { balance: '0', passphrase: 'wagon stock borrow episode laundry kitten salute link globe zero feed marble', }); - const mock = sinon.mock(controller.account); - mock.expects('getAccountPromise').returns(deffered.promise); - controller.$peers = { + const mock = sinon.mock(accountApi); + mock.expects('get').returns(deffered.promise); + controller.Peers = { getStatusPromise() { return $q.defer().promise; }, @@ -164,7 +163,7 @@ describe('main component controller', () => { account.reset(); }); - it('calls this.account.getAccountPromise(this.address) and then sets balance', () => { + it('calls this.accountApi.get(this.address) and then sets balance', () => { expect(account.get().balance).to.equal(undefined); controller.update(); deffered.resolve({ balance: 12345 }); @@ -172,7 +171,7 @@ describe('main component controller', () => { expect(account.get().balance).to.equal(12345); }); - it('calls this.account.getAccountPromise(this.address) and if it fails, then resets this.account.balance and reject the promise that update() returns', () => { + it('calls this.accountApi.get(this.address) and if it fails, then resets this.account.balance and reject the promise that update() returns', () => { const spy = sinon.spy(controller.$q, 'reject'); controller.update(); deffered.reject(); diff --git a/src/test/components/main/setSecondPassDirective.spec.js b/src/test/components/main/setSecondPassDirective.spec.js index 4e552067e..cd91229fd 100644 --- a/src/test/components/main/setSecondPassDirective.spec.js +++ b/src/test/components/main/setSecondPassDirective.spec.js @@ -10,7 +10,7 @@ describe('setSecondPass Directive', () => { let $scope; let $rootScope; let element; - let account; + let accountApi; let setSecondPass; let $q; let dialog; @@ -21,12 +21,12 @@ describe('setSecondPass Directive', () => { // Store references to $rootScope and $compile // so they are available to all tests in this describe block - inject((_$compile_, _$rootScope_, _setSecondPass_, _Account_, _$q_, _dialog_) => { + inject((_$compile_, _$rootScope_, _setSecondPass_, _AccountApi_, _$q_, _dialog_) => { // The injector unwraps the underscores (_) from around the parameter names when matching $compile = _$compile_; $rootScope = _$rootScope_; setSecondPass = _setSecondPass_; - account = _Account_; + accountApi = _AccountApi_; $q = _$q_; dialog = _dialog_; $scope = $rootScope.$new(); @@ -39,7 +39,7 @@ describe('setSecondPass Directive', () => { describe('SetSecondPassLink', () => { it('listens for an onAfterSignup event', () => { - const mock = sinon.mock(account); + const mock = sinon.mock(accountApi); const deffered = $q.defer(); mock.expects('setSecondSecret').returns(deffered.promise); @@ -66,8 +66,8 @@ describe('setSecondPass Directive', () => { }); describe('scope.passConfirmSubmit', () => { - it('should call account.setSecondSecret', () => { - const mock = sinon.mock(account); + it('should call accountApi.setSecondSecret', () => { + const mock = sinon.mock(accountApi); const deffered = $q.defer(); mock.expects('setSecondSecret').returns(deffered.promise); @@ -81,7 +81,7 @@ describe('setSecondPass Directive', () => { }); it('should show error dialog if trying to set second passphrase multiple times', () => { - const mock = sinon.mock(account); + const mock = sinon.mock(accountApi); const deffered = $q.defer(); mock.expects('setSecondSecret').returns(deffered.promise); @@ -102,7 +102,7 @@ describe('setSecondPass Directive', () => { }); it('should show error dialog if account does not have enough LSK', () => { - const mock = sinon.mock(account); + const mock = sinon.mock(accountApi); const deffered = $q.defer(); mock.expects('setSecondSecret').returns(deffered.promise); @@ -115,7 +115,7 @@ describe('setSecondPass Directive', () => { }); it('should show error dialog for all the other errors', () => { - const mock = sinon.mock(account); + const mock = sinon.mock(accountApi); const deffered = $q.defer(); mock.expects('setSecondSecret').returns(deffered.promise); diff --git a/src/test/components/send/send.spec.js b/src/test/components/send/send.spec.js index ddc9441c9..a1f315338 100644 --- a/src/test/components/send/send.spec.js +++ b/src/test/components/send/send.spec.js @@ -12,14 +12,16 @@ describe.skip('Send component', () => { let $scope; let lsk; let account; + let accountApi; beforeEach(angular.mock.module('app')); - beforeEach(inject((_$compile_, _$rootScope_, _lsk_, _Account_) => { + beforeEach(inject((_$compile_, _$rootScope_, _lsk_, _Account_, _AccountApi_) => { $compile = _$compile_; $rootScope = _$rootScope_; lsk = _lsk_; account = _Account_; + accountApi = _AccountApi_; })); beforeEach(() => { @@ -92,9 +94,9 @@ describe.skip('Send component', () => { const RECIPIENT_ADDRESS = '5932438298200837883L'; const AMOUNT = lsk.normalize(account.get().balance - 10000000); - const mock = sinon.mock(account); + const mock = sinon.mock(accountApi); const deffered = $q.defer(); - mock.expects('sendLSK').returns(deffered.promise); + mock.expects('transactions.create').returns(deffered.promise); const spy = sinon.spy(dialog, 'successAlert'); @@ -155,10 +157,10 @@ describe('send component controller', () => { }); describe('sendLSK()', () => { - it('calls this.account.sendLSK() and success.dialog on success', () => { - const mock = sinon.mock(controller.account); + it('calls accountApi.transactions.create and success.dialog on success', () => { + const mock = sinon.mock(controller.accountApi.transactions); const deffered = $q.defer(); - mock.expects('sendLSK').returns(deffered.promise); + mock.expects('create').returns(deffered.promise); controller.sendLSK(); const spy = sinon.spy(controller.dialog, 'successAlert'); @@ -169,10 +171,10 @@ describe('send component controller', () => { }); }); - it('calls this.account.sendLSK() and error.dialog on error', () => { - const mock = sinon.mock(controller.account); + it('calls accountApi.transactions.create and error.dialog on error', () => { + const mock = sinon.mock(controller.accountApi.transactions); const deffered = $q.defer(); - mock.expects('sendLSK').returns(deffered.promise); + mock.expects('create').returns(deffered.promise); controller.sendLSK(); const spy = sinon.spy(controller.dialog, 'errorAlert'); diff --git a/src/test/components/transactions/transactions.spec.js b/src/test/components/transactions/transactions.spec.js index 6780354ea..dd3feea66 100644 --- a/src/test/components/transactions/transactions.spec.js +++ b/src/test/components/transactions/transactions.spec.js @@ -14,21 +14,23 @@ describe('transactions component controller', () => { let controller; let $componentController; let account; + let accountApi; let mock; - beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Account_) => { + beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Account_, _AccountApi_) => { $componentController = _$componentController_; $rootScope = _$rootScope_; $q = _$q_; account = _Account_; + accountApi = _AccountApi_; })); beforeEach(() => { $scope = $rootScope.$new(); - mock = sinon.mock(account); + mock = sinon.mock(accountApi.transactions); const deffered = $q.defer(); - mock.expects('listTransactions').returns(deffered.promise); - mock.expects('listTransactions').returns(deffered.promise); + mock.expects('get').returns(deffered.promise); + mock.expects('get').returns(deffered.promise); controller = $componentController('transactions', $scope, {}); account.set({ passphrase: 'robust swift grocery peasant forget share enable convince deputy road keep cheap', @@ -60,7 +62,7 @@ describe('transactions component controller', () => { describe('showMore()', () => { it('calls this.update(true, true) if this.moreTransactionsExist', () => { controller.moreTransactionsExist = true; - mock.expects('listTransactions').returns($q.defer().promise); + mock.expects('get').returns($q.defer().promise); controller.loaded = true; controller.showMore(); expect(controller.loaded).to.equal(false); @@ -82,28 +84,28 @@ describe('transactions component controller', () => { }); it('sets this.loaded = false if showLoading == true', () => { - mock.expects('listTransactions').returns(transactionsDeferred.promise); + mock.expects('get').returns(transactionsDeferred.promise); controller.loaded = undefined; controller.update(true); expect(controller.loaded).to.equal(false); }); it('doesn\'t change this.loaded if showLoading == false', () => { - mock.expects('listTransactions').returns(transactionsDeferred.promise); + mock.expects('get').returns(transactionsDeferred.promise); controller.loaded = undefined; controller.update(false); expect(controller.loaded).to.equal(undefined); }); it('cancels update timeout', () => { - mock.expects('listTransactions').returns(transactionsDeferred.promise); + mock.expects('get').returns(transactionsDeferred.promise); const spy = sinon.spy(controller.$timeout, 'cancel'); controller.update(); expect(spy).to.have.been.calledWith(controller.timeout); }); - it('calls this.account.listTransactions(account.get().address, limit) with limit = 10 by default', () => { - mock.expects('listTransactions').withArgs(account.get().address, 10).returns(transactionsDeferred.promise); + it('calls accountApi.transactions.get(account.get().address, limit) with limit = 10 by default', () => { + mock.expects('get').withArgs(account.get().address, 10).returns(transactionsDeferred.promise); controller.update(); transactionsDeferred.reject(); From 6aa3c3ef13836168fa3a4d5e57b15e5526f6aaa4 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 10 May 2017 10:29:38 +0200 Subject: [PATCH 12/15] Remove logout since it is now in Run method --- src/test/components/main/main.spec.js | 29 --------------------------- 1 file changed, 29 deletions(-) diff --git a/src/test/components/main/main.spec.js b/src/test/components/main/main.spec.js index e3fc2dfd1..9dd204cfc 100644 --- a/src/test/components/main/main.spec.js +++ b/src/test/components/main/main.spec.js @@ -99,35 +99,6 @@ describe('main component controller', () => { }); }); - describe('logout()', () => { - it('resets main component', () => { - const spy = sinon.spy($rootScope, 'reset'); - $rootScope.logout(); - expect(spy).to.have.been.calledWith(); - }); - - it('resets peers', () => { - const spy = sinon.spy(controller.$peers, 'reset'); - $rootScope.logout(); - expect(spy).to.have.been.calledWith(true); - }); - - it('sets $rootScope.logged = false', () => { - $rootScope.logout(); - expect($rootScope.logged).to.equal(false); - }); - - it('sets $rootScope.prelogged = false', () => { - $rootScope.logout(); - expect($rootScope.prelogged).to.equal(false); - }); - - it('resets account service', () => { - $rootScope.logout(); - expect(account.get()).to.deep.equal({}); - }); - }); - describe('checkIfIsDelegate()', () => { beforeEach(() => { account.set({ From 2006103f4b71d6cabf5c525ef295af07ac5dbe0d Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 10 May 2017 10:30:05 +0200 Subject: [PATCH 13/15] Add test coverage for application run method --- src/test/run.spec.js | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/test/run.spec.js diff --git a/src/test/run.spec.js b/src/test/run.spec.js new file mode 100644 index 000000000..742a51206 --- /dev/null +++ b/src/test/run.spec.js @@ -0,0 +1,72 @@ +const sinon = require('sinon'); +const sinonChai = require('sinon-chai'); +const chai = require('chai'); + +const expect = chai.expect; + +const delegateAccount = { + passphrase: 'recipe bomb asset salon coil symbol tiger engine assist pact pumpkin visit', + address: '537318935439898807L', +}; + +chai.use(sinonChai); + +describe('Application run method', () => { + let $rootScope; + let account; + let peers; + let $timeout; + + beforeEach(angular.mock.module('app')); + + beforeEach(inject((_$rootScope_, _$timeout_, _Peers_, _Account_) => { + $rootScope = _$rootScope_; + $timeout = _$timeout_; + account = _Account_; + peers = _Peers_; + })); + + beforeEach(() => { + account.set({ passphrase: delegateAccount.passphrase }); + peers.setActive({ + name: 'Mainnet', + }); + }); + + describe('reset()', () => { + it('cancels $rootScope.$timeout', () => { + const spy = sinon.spy($timeout, 'cancel'); + $rootScope.reset(); + expect(spy).to.have.been.calledWith($rootScope.$timeout); + }); + }); + + describe('logout()', () => { + it('resets application', () => { + const spy = sinon.spy($rootScope, 'reset'); + $rootScope.logout(); + expect(spy).to.have.been.calledWith(); + }); + + it('resets peers', () => { + const spy = sinon.spy(peers, 'reset'); + $rootScope.logout(); + expect(spy).to.have.been.calledWith(true); + }); + + it('sets $rootScope.logged = false', () => { + $rootScope.logout(); + expect($rootScope.logged).to.equal(false); + }); + + it('sets $rootScope.prelogged = false', () => { + $rootScope.logout(); + expect($rootScope.prelogged).to.equal(false); + }); + + it('resets account service', () => { + $rootScope.logout(); + expect(account.get()).to.deep.equal({}); + }); + }); +}); From ca1fd8519fa04f188181fff8012f48f2d5495672 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 10 May 2017 12:03:29 +0200 Subject: [PATCH 14/15] Renamed "Send" to "Transfer" --- src/app/components/header/header.pug | 4 +- src/app/components/main/main.js | 4 +- src/app/components/send/sendModalDirective.js | 16 -------- .../components/transactions/transactions.pug | 6 +-- .../components/{send => transfer}/second.pug | 0 .../{send/send.js => transfer/transfer.js} | 14 +++---- .../send.less => transfer/transfer.less} | 2 +- .../{send/send.pug => transfer/transfer.pug} | 12 +++--- .../transfer/transferModalDirective.js | 16 ++++++++ .../transferModalService.js} | 4 +- src/app/lisk-nano.js | 6 +-- src/test/components/header/header.spec.js | 6 +-- .../transfer.spec.js} | 38 +++++++++---------- .../transferModalDirective.spec.js} | 18 ++++----- src/test/test.js | 4 +- 15 files changed, 75 insertions(+), 75 deletions(-) delete mode 100644 src/app/components/send/sendModalDirective.js rename src/app/components/{send => transfer}/second.pug (100%) rename src/app/components/{send/send.js => transfer/transfer.js} (88%) rename src/app/components/{send/send.less => transfer/transfer.less} (98%) rename src/app/components/{send/send.pug => transfer/transfer.pug} (80%) create mode 100644 src/app/components/transfer/transferModalDirective.js rename src/app/components/{send/sendModalService.js => transfer/transferModalService.js} (68%) rename src/test/components/{send/send.spec.js => transfer/transfer.spec.js} (82%) rename src/test/components/{send/sendModalDirective.spec.js => transfer/transferModalDirective.spec.js} (56%) diff --git a/src/app/components/header/header.pug b/src/app/components/header/header.pug index f30357258..849b0de6f 100644 --- a/src/app/components/header/header.pug +++ b/src/app/components/header/header.pug @@ -1,7 +1,7 @@ md-content.header(layout='row', layout-align='center center', layout-padding) img.logo(src=require('../../assets/images/LISK-nano.png')) div(flex) - md-button.md-raised.md-primary.send(data-show-send-modal, ng-if='$root.logged') Send + md-button.md-raised.md-primary.transfer(data-show-transfer-modal, ng-if='$root.logged') Transfer md-button.md-raised.md-secondary.logout(ng-click='$root.logout()', ng-if='$root.logged') Logout md-menu.top-menu(ng-if='$root.logged', md-position-mode='target-right target', md-offset='14 0') md-button.md-icon-button(ng-click='$mdOpenMenu()') @@ -22,4 +22,4 @@ md-content.header(layout='row', layout-align='center center', layout-padding) md-menu-item(ng-if='$root.logged && !$ctrl.account.get().isDelegate') md-button(data-delegate-registration) div(layout='row', flex='') - p(flex='') Delegate registration \ No newline at end of file + p(flex='') Delegate registration diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js index 4961b3e52..424e34126 100644 --- a/src/app/components/main/main.js +++ b/src/app/components/main/main.js @@ -7,14 +7,14 @@ app.component('main', { controllerAs: '$ctrl', controller: class main { constructor($scope, $rootScope, $timeout, $q, $state, Peers, - dialog, SendModal, Account, AccountApi) { + dialog, TransferModal, Account, AccountApi) { this.$scope = $scope; this.$rootScope = $rootScope; this.$timeout = $timeout; this.$q = $q; this.peers = Peers; this.dialog = dialog; - this.sendModal = SendModal; + this.transferModal = TransferModal; this.$state = $state; this.account = Account; this.accountApi = AccountApi; diff --git a/src/app/components/send/sendModalDirective.js b/src/app/components/send/sendModalDirective.js deleted file mode 100644 index 0b43dda3e..000000000 --- a/src/app/components/send/sendModalDirective.js +++ /dev/null @@ -1,16 +0,0 @@ -app.directive('showSendModal', (SendModal) => { - const ShowSendModalLink = function (scope, element) { - element.bind('click', () => { - SendModal.show(scope.recipientId, scope.amount); - }); - }; - - return { - restrict: 'A', - scope: { - recipientId: '<', - amount: '<', - }, - link: ShowSendModalLink, - }; -}); diff --git a/src/app/components/transactions/transactions.pug b/src/app/components/transactions/transactions.pug index 70fcdb423..5c3db31f7 100644 --- a/src/app/components/transactions/transactions.pug +++ b/src/app/components/transactions/transactions.pug @@ -12,7 +12,7 @@ md-card.offline-hide th(md-column) Time th(md-column) Transaction ID th(md-column) From / To - th(md-column) Send to this + th(md-column) Transfer to this th(md-column) Amount th(md-column) Fee tbody(md-body, infinite-scroll='$ctrl.showMore()') @@ -35,8 +35,8 @@ md-card.offline-hide span(ng-bind='transaction.senderId', ng-if='transaction.senderId !== $ctrl.account.get().address') span(ng-bind='transaction.recipientId', ng-if='transaction.senderId === $ctrl.account.get().address') td(md-cell) - i.material-icons.expanding-button(ng-if='transaction.senderId !== $ctrl.account.get().address', data-show-send-modal, data-recipient-id='transaction.senderId') arrow_forward - i.material-icons.expanding-button(ng-if='transaction.senderId === $ctrl.account.get().address', data-show-send-modal, data-recipient-id='transaction.recipientId') arrow_forward + i.material-icons.expanding-button(ng-if='transaction.senderId !== $ctrl.account.get().address', data-show-transfer-modal, data-recipient-id='transaction.senderId') arrow_forward + i.material-icons.expanding-button(ng-if='transaction.senderId === $ctrl.account.get().address', data-show-transfer-modal, data-recipient-id='transaction.recipientId') arrow_forward td(md-cell) i.material-icons.in(ng-if='transaction.senderId !== $ctrl.account.get().address') call_received i.material-icons.out(ng-if='transaction.senderId === $ctrl.account.get().address') call_made diff --git a/src/app/components/send/second.pug b/src/app/components/transfer/second.pug similarity index 100% rename from src/app/components/send/second.pug rename to src/app/components/transfer/second.pug diff --git a/src/app/components/send/send.js b/src/app/components/transfer/transfer.js similarity index 88% rename from src/app/components/send/send.js rename to src/app/components/transfer/transfer.js index 13246aa55..32f13940f 100644 --- a/src/app/components/send/send.js +++ b/src/app/components/transfer/transfer.js @@ -1,15 +1,15 @@ -import './send.less'; +import './transfer.less'; const ADDRESS_VALID_RE = '^[0-9]{1,21}[L|l]$'; const AMOUNT_VALID_RE = '^[0-9]+(.[0-9]{1,8})?$'; -app.component('send', { - template: require('./send.pug')(), +app.component('transfer', { + template: require('./transfer.pug')(), bindings: { recipientId: '<', transferAmount: '<', }, - controller: class send { + controller: class transfer { constructor($scope, lsk, dialog, $mdDialog, $q, $rootScope, Account, AccountApi) { this.$scope = $scope; this.dialog = dialog; @@ -47,7 +47,7 @@ app.component('send', { this.amount.value = ''; } - sendLSK() { + transfer() { this.loading = true; this.accountApi.transactions.create( @@ -65,12 +65,12 @@ app.component('send', { fee: 10000000, }; this.$rootScope.$broadcast('transaction-sent', transaction); - return this.dialog.successAlert({ text: `${this.amount.value} sent to ${this.recipient.value}` }) + return this.dialog.successAlert({ text: `${this.amount.value} LSK was successfully transferred to ${this.recipient.value}` }) .then(() => { this.reset(); }); }).catch((res) => { - this.dialog.errorAlert({ text: res && res.message ? res.message : 'An error occurred while sending the transaction.' }); + this.dialog.errorAlert({ text: res && res.message ? res.message : 'An error occurred while creating the transaction.' }); }).finally(() => { this.loading = false; }); diff --git a/src/app/components/send/send.less b/src/app/components/transfer/transfer.less similarity index 98% rename from src/app/components/send/send.less rename to src/app/components/transfer/transfer.less index be540fd7a..0da406726 100644 --- a/src/app/components/send/send.less +++ b/src/app/components/transfer/transfer.less @@ -1,4 +1,4 @@ -send { +transfer { input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; diff --git a/src/app/components/send/send.pug b/src/app/components/transfer/transfer.pug similarity index 80% rename from src/app/components/send/send.pug rename to src/app/components/transfer/transfer.pug index 47cf84172..3382967de 100644 --- a/src/app/components/send/send.pug +++ b/src/app/components/transfer/transfer.pug @@ -1,15 +1,15 @@ -div.dialog-send(aria-label='Send funds') - form(name='$ctrl.sendForm') +div.dialog-transfer(aria-label='Transfer funds') + form(name='$ctrl.transferForm') md-toolbar .md-toolbar-tools - h2 Send + h2 Transfer md-dialog-content .md-dialog-content div md-input-container.md-block label Recipient Address input(type='text', name='recipient', ng-model='$ctrl.recipient.value', required, ng-pattern='$ctrl.recipient.regexp', ng-disabled='$ctrl.loading') - div(ng-messages='$ctrl.sendForm.recipient.$error') + div(ng-messages='$ctrl.transferForm.recipient.$error') div(ng-message='required') Required div(ng-message='pattern') Invalid div(layout="row") @@ -17,7 +17,7 @@ div.dialog-send(aria-label='Send funds') label Transaction Amount input(type='text', name='amount', ng-model='$ctrl.amount.value', required, ng-pattern='$ctrl.amount.regexp', ng-disabled='$ctrl.loading', ng-max='$ctrl.amount.max') div.fee(ng-show='$ctrl.amount.value') Fee: 0.1 LSK - div(ng-messages='$ctrl.sendForm.amount.$error') + div(ng-messages='$ctrl.transferForm.amount.$error') div(ng-message='required') Required div(ng-message='pattern') Invalid div(ng-message='max') Insufficient funds @@ -35,4 +35,4 @@ div.dialog-send(aria-label='Send funds') md-dialog-actions(layout='row') md-button.md-raised.md-secondary(ng-disabled='$ctrl.loading', ng-click='$ctrl.cancel()') {{ 'Cancel' }} span(flex) - md-button.md-raised.md-primary(ng-disabled='!$ctrl.sendForm.$valid || $ctrl.loading', ng-click='$ctrl.sendLSK()') {{ $ctrl.loading ? 'Sending...' : 'Send' }} + md-button.md-raised.md-primary(ng-disabled='!$ctrl.transferForm.$valid || $ctrl.loading', ng-click='$ctrl.transfer()') {{ $ctrl.loading ? 'Transfering...' : 'Transfer' }} diff --git a/src/app/components/transfer/transferModalDirective.js b/src/app/components/transfer/transferModalDirective.js new file mode 100644 index 000000000..613179646 --- /dev/null +++ b/src/app/components/transfer/transferModalDirective.js @@ -0,0 +1,16 @@ +app.directive('showTransferModal', (TransferModal) => { + const ShowTransferModalLink = function (scope, element) { + element.bind('click', () => { + TransferModal.show(scope.recipientId, scope.amount); + }); + }; + + return { + restrict: 'A', + scope: { + recipientId: '<', + amount: '<', + }, + link: ShowTransferModalLink, + }; +}); diff --git a/src/app/components/send/sendModalService.js b/src/app/components/transfer/transferModalService.js similarity index 68% rename from src/app/components/send/sendModalService.js rename to src/app/components/transfer/transferModalService.js index 8ca028340..b4cf86fe1 100644 --- a/src/app/components/send/sendModalService.js +++ b/src/app/components/transfer/transferModalService.js @@ -1,4 +1,4 @@ -app.factory('SendModal', ($mdDialog) => { +app.factory('TransferModal', ($mdDialog) => { const init = () => { }; @@ -6,7 +6,7 @@ app.factory('SendModal', ($mdDialog) => { }; const show = (recipientId, amount) => ($mdDialog.show({ - template: '', + template: '', locals: { recipientId, amount, }, diff --git a/src/app/lisk-nano.js b/src/app/lisk-nano.js index 9708a8c86..c6e28d899 100644 --- a/src/app/lisk-nano.js +++ b/src/app/lisk-nano.js @@ -9,9 +9,9 @@ import './components/login/login'; import './components/login/passphrase'; import './components/top/top'; import './components/header/header'; -import './components/send/send'; -import './components/send/sendModalService'; -import './components/send/sendModalDirective'; +import './components/transfer/transfer'; +import './components/transfer/transferModalService'; +import './components/transfer/transferModalDirective'; import './components/transactions/transactions'; import './components/timestamp/timestamp'; import './components/lsk/lsk'; diff --git a/src/test/components/header/header.spec.js b/src/test/components/header/header.spec.js index 62ddd848b..67881cbe2 100644 --- a/src/test/components/header/header.spec.js +++ b/src/test/components/header/header.spec.js @@ -25,11 +25,11 @@ describe('Header component', () => { $scope.$digest(); }); - const SEND_BUTTON_TEXT = 'Send'; - it(`should contain "${SEND_BUTTON_TEXT}" button if $root.logged`, () => { + const TRANSFER_BUTTON_TEXT = 'Transfer'; + it(`should contain "${TRANSFER_BUTTON_TEXT}" button if $root.logged`, () => { $rootScope.logged = true; $scope.$digest(); - expect(element.find('button.md-primary.send').text()).to.equal(SEND_BUTTON_TEXT); + expect(element.find('button.md-primary.transfer').text()).to.equal(TRANSFER_BUTTON_TEXT); }); const LOGOUT_BUTTON_TEXT = 'Logout'; diff --git a/src/test/components/send/send.spec.js b/src/test/components/transfer/transfer.spec.js similarity index 82% rename from src/test/components/send/send.spec.js rename to src/test/components/transfer/transfer.spec.js index a1f315338..8973f9905 100644 --- a/src/test/components/send/send.spec.js +++ b/src/test/components/transfer/transfer.spec.js @@ -5,7 +5,7 @@ const sinonChai = require('sinon-chai'); const expect = chai.expect; chai.use(sinonChai); -describe.skip('Send component', () => { +describe.skip('Transfer component', () => { let $compile; let $rootScope; let element; @@ -31,11 +31,11 @@ describe.skip('Send component', () => { balance: lsk.from(10535.77379498), }); - element = $compile('')($scope); + element = $compile('')($scope); $scope.$digest(); }); - const HEADER_TEXT = 'Send'; + const HEADER_TEXT = 'Transfer'; it(`should contain header saying "${HEADER_TEXT}"`, () => { expect(element.find('.md-title').text()).to.equal(HEADER_TEXT); }); @@ -50,9 +50,9 @@ describe.skip('Send component', () => { expect(element.find('form label:last').text()).to.equal(AMOUT_LABEL_TEXT); }); - const SEND_BUTTON_TEXT = 'Send'; - it(`should contain a button saying "${SEND_BUTTON_TEXT}"`, () => { - expect(element.find('button.md-raised.md-primary').text()).to.equal(SEND_BUTTON_TEXT); + const TRANSFER_BUTTON_TEXT = 'Transfer'; + it(`should contain a button saying "${TRANSFER_BUTTON_TEXT}"`, () => { + expect(element.find('button.md-raised.md-primary').text()).to.equal(TRANSFER_BUTTON_TEXT); }); const CANCEL_BUTTON_TEXT = 'Cancel'; @@ -60,7 +60,7 @@ describe.skip('Send component', () => { expect(element.find('button.md-raised.md-secondary').text()).to.equal(CANCEL_BUTTON_TEXT); }); - describe('send transaction', () => { + describe('create transaction', () => { let dialog; let $q; @@ -69,13 +69,13 @@ describe.skip('Send component', () => { $q = _$q_; })); - it('should allow to send a transaction', () => { + it('should allow to create a transaction', () => { const RECIPIENT_ADDRESS = '5932438298200837883L'; const AMOUNT = '10'; const mock = sinon.mock(account); const deffered = $q.defer(); - mock.expects('sendLSK').returns(deffered.promise); + mock.expects('transfer').returns(deffered.promise); const spy = sinon.spy(dialog, 'successAlert'); @@ -90,7 +90,7 @@ describe.skip('Send component', () => { mock.verify(); }); - it('should allow to send all funds', () => { + it('should allow to transfer all funds', () => { const RECIPIENT_ADDRESS = '5932438298200837883L'; const AMOUNT = lsk.normalize(account.get().balance - 10000000); @@ -109,13 +109,13 @@ describe.skip('Send component', () => { deffered.resolve({}); $scope.$apply(); expect(spy).to.have.been.calledWith(); - expect(spy).to.have.been.calledWith({ text: `${AMOUNT} sent to ${RECIPIENT_ADDRESS}` }); + expect(spy).to.have.been.calledWith({ text: `${AMOUNT} LSK was successfully transferred to ${RECIPIENT_ADDRESS}` }); mock.verify(); }); }); }); -describe('send component controller', () => { +describe('Transfer component controller', () => { beforeEach(angular.mock.module('app')); let $rootScope; @@ -134,7 +134,7 @@ describe('send component controller', () => { beforeEach(() => { $scope = $rootScope.$new(); - controller = $componentController('send', $scope, {}); + controller = $componentController('transfer', $scope, {}); account.set({ balance: '10000', passphrase: 'robust swift grocery peasant forget share enable convince deputy road keep cheap', @@ -145,8 +145,8 @@ describe('send component controller', () => { it('resets this.recipient.value and this.amount.value', () => { controller.recipient.value = 'TEST'; controller.amount.value = '1000'; - controller.sendForm = { $setUntouched: () => {} }; - const mock = sinon.mock(controller.sendForm); + controller.transferForm = { $setUntouched: () => {} }; + const mock = sinon.mock(controller.transferForm); mock.expects('$setUntouched'); controller.reset(); @@ -156,18 +156,18 @@ describe('send component controller', () => { }); }); - describe('sendLSK()', () => { + describe('transfer()', () => { it('calls accountApi.transactions.create and success.dialog on success', () => { const mock = sinon.mock(controller.accountApi.transactions); const deffered = $q.defer(); mock.expects('create').returns(deffered.promise); - controller.sendLSK(); + controller.transfer(); const spy = sinon.spy(controller.dialog, 'successAlert'); deffered.resolve({}); $scope.$apply(); expect(spy).to.have.been.calledWith({ - text: `${controller.amount.value} sent to ${controller.recipient.value}`, + text: `${controller.amount.value} LSK was successfully transferred to ${controller.recipient.value}`, }); }); @@ -175,7 +175,7 @@ describe('send component controller', () => { const mock = sinon.mock(controller.accountApi.transactions); const deffered = $q.defer(); mock.expects('create').returns(deffered.promise); - controller.sendLSK(); + controller.transfer(); const spy = sinon.spy(controller.dialog, 'errorAlert'); const response = { diff --git a/src/test/components/send/sendModalDirective.spec.js b/src/test/components/transfer/transferModalDirective.spec.js similarity index 56% rename from src/test/components/send/sendModalDirective.spec.js rename to src/test/components/transfer/transferModalDirective.spec.js index fb0078433..03c96208e 100644 --- a/src/test/components/send/sendModalDirective.spec.js +++ b/src/test/components/transfer/transferModalDirective.spec.js @@ -5,25 +5,25 @@ const sinonChai = require('sinon-chai'); const expect = chai.expect; chai.use(sinonChai); -describe('Send modal directive', () => { +describe('Transfer modal directive', () => { let $scope; - let SendModal; + let TransferModal; let compiled; - const template = '
'; + const template = '
'; beforeEach(angular.mock.module('app')); - beforeEach(inject(($compile, $rootScope, _SendModal_) => { + beforeEach(inject(($compile, $rootScope, _TransferModal_) => { $scope = $rootScope.$new(); - SendModal = _SendModal_; + TransferModal = _TransferModal_; compiled = $compile(template)($scope); $scope.$digest(); })); afterEach(() => { - if (typeof SendModal.show.restore === 'function') { - SendModal.show.restore(); + if (typeof TransferModal.show.restore === 'function') { + TransferModal.show.restore(); } }); @@ -32,9 +32,9 @@ describe('Send modal directive', () => { expect(el.length).to.equal(1); }); - it('should run SendModal.show() when clicked', () => { + it('should run TransferModal.show() when clicked', () => { const el = compiled.find('button'); - const spy = sinon.spy(SendModal, 'show'); + const spy = sinon.spy(TransferModal, 'show'); el.triggerHandler('click'); expect(spy).to.have.been.calledWith(); }); diff --git a/src/test/test.js b/src/test/test.js index fa6e87aa3..d2f3a458b 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -7,8 +7,8 @@ require('./components/login/passphrase.spec'); require('./components/main/main.spec'); require('./components/main/setSecondPassDirective.spec'); require('./components/main/setSecondPassService.spec'); -require('./components/send/send.spec'); -require('./components/send/sendModalDirective.spec'); +require('./components/transfer/transfer.spec'); +require('./components/transfer/transferModalDirective.spec'); require('./components/top/top.spec'); require('./components/timestamp/timestamp.spec'); require('./components/transactions/transactions.spec'); From de281aa4372614c722a6cff17088ec336be46154 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 10 May 2017 12:03:50 +0200 Subject: [PATCH 15/15] Remove unnecessary comments --- src/test/services/api/accountApi.spec.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/test/services/api/accountApi.spec.js b/src/test/services/api/accountApi.spec.js index 31142e837..2750f2f11 100644 --- a/src/test/services/api/accountApi.spec.js +++ b/src/test/services/api/accountApi.spec.js @@ -7,21 +7,17 @@ chai.use(sinonChai); describe('Factory: AccountApi', () => { let peers; - let $q; let accountApi; let peersMock; - let deffered; beforeEach(angular.mock.module('app')); - beforeEach(inject((_Peers_, _$q_, _AccountApi_) => { + beforeEach(inject((_Peers_, _AccountApi_) => { peers = _Peers_; - $q = _$q_; accountApi = _AccountApi_; })); beforeEach(() => { - deffered = $q.defer(); peersMock = sinon.mock(peers); peers.setActive({ name: 'Mainnet', @@ -35,7 +31,6 @@ describe('Factory: AccountApi', () => { describe('transaction.create(recipientId, amount, secret, secondSecret)', () => { it('returns Peers.sendRequest(\'transactions\', options);', () => { - console.log(deffered); const options = { recipientId: '537318935439898807L', amount: 10, @@ -43,14 +38,11 @@ describe('Factory: AccountApi', () => { secondSecret: null, }; const spy = sinon.spy(peers, 'sendRequestPromise'); - // peers.expects('sendRequestPromise').withArgs('transactions', - // options).returns(deffered.promise); accountApi.transactions.create( options.recipientId, options.amount, options.secret, options.secondSecret); expect(spy).to.have.been.calledWith('transactions', options); - // expect(promise).to.equal(deffered.promise); }); }); @@ -64,14 +56,11 @@ describe('Factory: AccountApi', () => { }; const spy = sinon.spy(peers, 'sendRequestPromise'); - // peersMock.expects('sendRequestPromise').withArgs('transactions', - // options).returns(deffered.promise); accountApi.transactions.get( options.recipientId, options.limit, options.offset); expect(spy).to.have.been.calledWith('transactions', options); - // expect(promise).to.equal(deffered.promise); }); }); @@ -82,14 +71,10 @@ describe('Factory: AccountApi', () => { const secondSecret = 'stay undo beyond powder sand laptop grow gloom apology hamster primary arrive'; const spy = sinon.spy(peers, 'sendRequestPromise'); - // peersMock.expects('sendRequestPromise') - // .withArgs('signatures', { secondSecret, publicKey, secret }) - // .returns(deffered.promise); accountApi.setSecondSecret(secondSecret, publicKey, secret); expect(spy).to.have.been.calledWith('signatures', { secondSecret, publicKey, secret }); - // expect(promise).to.equal(deffered.promise); }); }); });