Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #245 from LiskHQ/208-names-of-api-services
Browse files Browse the repository at this point in the history
Fix names of services in delegateApi.js and forgingApi.js - Closes #208
  • Loading branch information
slaweet authored May 19, 2017
2 parents 62034bb + 440590a commit a2adc44
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 92 deletions.
6 changes: 3 additions & 3 deletions src/components/delegateRegistration/delegateRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import './delegateRegistration.less';
* @class app.delegateRegistration
* @memberOf app
*/
app.directive('delegateRegistration', ($mdDialog, delegateService, Account, dialog, $rootScope) => {
app.directive('delegateRegistration', ($mdDialog, delegateApi, Account, dialog, $rootScope) => {
const DelegateRegistrationLink = function ($scope, $element) {
function checkPendingRegistration() {
delegateService.getDelegate({
delegateApi.getDelegate({
username: $scope.username,
}).then((data) => {
Account.set({
Expand All @@ -27,7 +27,7 @@ app.directive('delegateRegistration', ($mdDialog, delegateService, Account, dial
onSubmit: (form) => {
if (form.$valid) {
$scope.username = $scope.form.name.toLowerCase();
delegateService.registerDelegate(
delegateApi.registerDelegate(
$scope.username,
Account.get().passphrase,
$scope.form.secondPassphrase,
Expand Down
14 changes: 7 additions & 7 deletions src/components/delegates/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ app.component('delegates', {
*/
controller: class delegates {
constructor($scope, $rootScope, Peers, $mdDialog, $mdMedia,
dialog, $timeout, delegateService, Account) {
dialog, $timeout, delegateApi, Account) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.peers = Peers;
this.delegateService = delegateService;
this.delegateApi = delegateApi;
this.$mdDialog = $mdDialog;
this.$mdMedia = $mdMedia;
this.dialog = dialog;
Expand Down Expand Up @@ -65,7 +65,7 @@ app.component('delegates', {
this.delegates = [];
this.delegatesDisplayedCount = 20;
if (this.peers.active) {
this.delegateService.listAccountDelegates({
this.delegateApi.listAccountDelegates({
address: this.account.get().address,
}).then((data) => {
this.votedList = data.delegates || [];
Expand All @@ -89,7 +89,7 @@ app.component('delegates', {
*/
loadDelegates(offset, search, replace, limit = 100) {
this.loading = true;
this.delegateService.listDelegates({
this.delegateApi.listDelegates({
offset,
limit: limit.toString(),
q: search,
Expand All @@ -103,7 +103,7 @@ app.component('delegates', {
* Fills the list of delegates, sets their voted and changed status
*
* @method addDelegates
* @param {Object} data - The result of delegateService.listDelegates Api call
* @param {Object} data - The result of delegateApi.listDelegates Api call
* @param {Boolean} replace - defines if the results should replace
* the old delegates list
*/
Expand Down Expand Up @@ -220,7 +220,7 @@ app.component('delegates', {
*/
checkPendingVotes() {
this.$timeout(() => {
this.delegateService.listAccountDelegates(this.account.get().address,
this.delegateApi.listAccountDelegates(this.account.get().address,
).then((data) => {
this.votedList = data.delegates || [];
this.votedDict = {};
Expand Down Expand Up @@ -310,7 +310,7 @@ app.component('delegates', {
this._selectDelegate(delegate, list);
} else {
this.pendingRequests++;
this.delegateService.getDelegate(username,
this.delegateApi.getDelegate(username,
).then((data) => {
this._selectDelegate(data.delegate, list);
}).catch(() => {
Expand Down
10 changes: 5 additions & 5 deletions src/components/delegates/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ app.component('vote', {
* @constructor
*/
controller: class vote {
constructor($scope, $mdDialog, dialog, delegateService, $rootScope, Account) {
constructor($scope, $mdDialog, dialog, delegateApi, $rootScope, Account) {
this.$mdDialog = $mdDialog;
this.dialog = dialog;
this.delegateService = delegateService;
this.delegateApi = delegateApi;
this.$rootScope = $rootScope;
this.account = Account;

Expand All @@ -38,7 +38,7 @@ app.component('vote', {
* @method getDelegates
*/
getDelegates() {
this.delegateService.listAccountDelegates({
this.delegateApi.listAccountDelegates({
address: this.account.get().address,
}).then((data) => {
this.votedList = data.delegates || [];
Expand All @@ -49,14 +49,14 @@ app.component('vote', {
}

/**
* for an existing voteList and unvoteList it calls delegateService.vote
* for an existing voteList and unvoteList it calls delegateApi.vote
* to update vote list. Shows a toast on each state change.
*
* @method vote
*/
vote() {
this.votingInProgress = true;
this.delegateService.vote(
this.delegateApi.vote(
this.account.get().passphrase,
this.account.get().publicKey,
this.voteList,
Expand Down
4 changes: 2 additions & 2 deletions src/components/delegates/vote.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ div.dialog-vote(aria-label='Vote for delegates')
h4 Add vote to
md-chips(ng-model='$ctrl.voteList', md-require-match='true', md-max-chips='33', md-autocomplete-snap)
md-chip-template {{$chip.username}}
md-autocomplete(flex, required, md-input-minlength='2', md-no-cache='false', md-selected-item='$ctrl.selectedVoteDelegate', md-search-text='$ctrl.voteSearchText', md-items='delegate in $ctrl.delegateService.voteAutocomplete($ctrl.voteSearchText, $ctrl.votedDict)', md-item-text='delegate.username', md-require-match, placeholder='Search by username')
md-autocomplete(flex, required, md-input-minlength='2', md-no-cache='false', md-selected-item='$ctrl.selectedVoteDelegate', md-search-text='$ctrl.voteSearchText', md-items='delegate in $ctrl.delegateApi.voteAutocomplete($ctrl.voteSearchText, $ctrl.votedDict)', md-item-text='delegate.username', md-require-match, placeholder='Search by username')
span(md-highlight-text='$ctrl.voteSearchText') {{delegate.username}}
md-divider(ng-if='$ctrl.voteList.length && $ctrl.unvoteList.length')
div
h4 Remove vote from
md-chips(ng-model='$ctrl.unvoteList', md-require-match='true', md-max-chips='33')
md-chip-template {{$chip.username}}
md-autocomplete(flex, required, md-input-minlength='2', md-no-cache='false', md-selected-item='$ctrl.selectedUnvoteDelegate', md-search-text='$ctrl.unvoteSearchText', md-items='delegate in $ctrl.delegateService.unvoteAutocomplete($ctrl.unvoteSearchText, $ctrl.votedList)', md-item-text='delegate.username', md-require-match, placeholder='Search by username')
md-autocomplete(flex, required, md-input-minlength='2', md-no-cache='false', md-selected-item='$ctrl.selectedUnvoteDelegate', md-search-text='$ctrl.unvoteSearchText', md-items='delegate in $ctrl.delegateApi.unvoteAutocomplete($ctrl.unvoteSearchText, $ctrl.votedList)', md-item-text='delegate.username', md-require-match, placeholder='Search by username')
span(md-highlight-text='$ctrl.unvoteSearchText') {{delegate.username}}
md-input-container.md-block(ng-if='$ctrl.account.get().secondSignature')
label Second Passphrase
Expand Down
14 changes: 7 additions & 7 deletions src/components/forging/forging.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ app.component('forging', {
* @constructor
*/
controller: class forging {
constructor($scope, $timeout, forgingService, Account) {
constructor($scope, $timeout, forgingApi, Account) {
this.$scope = $scope;
this.$timeout = $timeout;
this.forgingService = forgingService;
this.forgingApi = forgingApi;

this.statistics = {};
this.blocks = [];
Expand Down Expand Up @@ -59,15 +59,15 @@ app.component('forging', {
* @method updateDelegate
*/
updateDelegate() {
this.forgingService.getDelegate().then((data) => {
this.forgingApi.getDelegate().then((data) => {
this.delegate = data.delegate;
}).catch(() => {
this.delegate = {};
});
}

/**
* Call forgingService to fetch forged blocks considering the given limit and offset
* Call forgingApi to fetch forged blocks considering the given limit and offset
* If offset is not defined and the fetched and existing lists aren't identical,
* it'll unshift assuming we're fetching new forged blocks
*
Expand All @@ -78,7 +78,7 @@ app.component('forging', {
updateForgedBlocks(limit, offset) {
this.$timeout.cancel(this.timeout);

this.forgingService.getForgedBlocks(limit, offset).then((data) => {
this.forgingApi.getForgedBlocks(limit, offset).then((data) => {
if (this.blocks.length === 0) {
this.blocks = data.blocks;
} else if (offset) {
Expand Down Expand Up @@ -109,15 +109,15 @@ app.component('forging', {
}

/**
* Uses forgingService to update forging statistics
* Uses forgingApi to update forging statistics
*
* @method updateForgingStats
* @param {String} key The key to categorize forged blocks stats.
* presently one of today, last24h, last7d, last30d, total.
* @param {Object} startMoment The moment.js date object
*/
updateForgingStats(key, startMoment) {
this.forgingService.getForgedStats(startMoment).then((data) => {
this.forgingApi.getForgedStats(startMoment).then((data) => {
this.statistics[key] = data.forged;
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/api/delegateApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* publicKey and address and it's only used for accounts registered as delegate.
*
* @module app
* @submodule delegateService
* @submodule delegateApi
*/
app.factory('delegateService', Peers => ({
app.factory('delegateApi', Peers => ({
/**
* gets the list of delegates for whom the given address has voted
*
Expand Down
4 changes: 2 additions & 2 deletions src/services/api/forgingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import moment from 'moment';
* publicKey and address and it's only used for accounts registered as delegate.
*
* @module app
* @submodule forgingService
* @submodule forgingApi
*/
app.factory('forgingService', (Peers, Account) => ({
app.factory('forgingApi', (Peers, Account) => ({
/**
* Fetches the list of the delegates
*
Expand Down
26 changes: 13 additions & 13 deletions test/components/delegates/delegates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,25 @@ describe('delegates component controller', () => {
});

describe('checkPendingVotes()', () => {
let delegateServiceMock;
let delegateApiMock;
let accountDelegtatesDeferred;
let delegate41;
let delegate42;

beforeEach(() => {
accountDelegtatesDeferred = $q.defer();
delegateServiceMock = sinon.mock(controller.delegateService);
delegateServiceMock.expects('listAccountDelegates').returns(accountDelegtatesDeferred.promise);
delegateApiMock = sinon.mock(controller.delegateApi);
delegateApiMock.expects('listAccountDelegates').returns(accountDelegtatesDeferred.promise);
delegate41 = { username: 'genesis_41', status: {} };
delegate42 = { username: 'genesis_42', status: {} };
});

afterEach(() => {
delegateServiceMock.verify();
delegateServiceMock.restore();
delegateApiMock.verify();
delegateApiMock.restore();
});

it('calls delegateService.listAccountDelegates and then removes all returned delegates from this.votePendingList', () => {
it('calls delegateApi.listAccountDelegates and then removes all returned delegates from this.votePendingList', () => {
controller.votePendingList = [delegate41, delegate42];
controller.unvotePendingList = [];

Expand All @@ -275,7 +275,7 @@ describe('delegates component controller', () => {
expect(controller.votePendingList[0]).to.deep.equal(delegate41);
});

it('calls delegateService.listAccountDelegates and then removes all NOT returned delegates from this.unvotePendingList', () => {
it('calls delegateApi.listAccountDelegates and then removes all NOT returned delegates from this.unvotePendingList', () => {
controller.votePendingList = [];
controller.unvotePendingList = [delegate41, delegate42];

Expand All @@ -289,7 +289,7 @@ describe('delegates component controller', () => {
expect(controller.unvotePendingList[0]).to.deep.equal(delegate42);
});

it('calls delegateService.listAccountDelegates and if in the end there are still some votes pending calls itself again', () => {
it('calls delegateApi.listAccountDelegates and if in the end there are still some votes pending calls itself again', () => {
controller.votePendingList = [];
controller.unvotePendingList = [delegate41, delegate42];

Expand All @@ -305,10 +305,10 @@ describe('delegates component controller', () => {
});

describe('parseVoteListFromInput(list)', () => {
let delegateServiceMock;
let delegateApiMock;

beforeEach(() => {
delegateServiceMock = sinon.mock(controller.delegateService);
delegateApiMock = sinon.mock(controller.delegateApi);
});

it('parses this.usernameInput to list of delegates and opens vote dialog if all delegates were immediately resolved', () => {
Expand All @@ -321,7 +321,7 @@ describe('delegates component controller', () => {
it('parses this.usernameInput to list of delegates and opens vote dialog if all delegates were resolved immediately or from server', () => {
const username = 'not_fetched_yet';
const deffered = $q.defer();
delegateServiceMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const spy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = `${username}\ngenesis_42\ngenesis_46`;

Expand All @@ -340,7 +340,7 @@ describe('delegates component controller', () => {
it('parses this.usernameInput to list of delegates and opens vote dialog if any delegates were resolved', () => {
const username = 'invalid_name';
const deffered = $q.defer();
delegateServiceMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const spy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = `${username}\ngenesis_42\ngenesis_46`;

Expand All @@ -354,7 +354,7 @@ describe('delegates component controller', () => {
it('parses this.usernameInput to list of delegates and shows error toast if no delegates were resolved', () => {
const username = 'invalid_name';
const deffered = $q.defer();
delegateServiceMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const toastSpy = sinon.spy(controller.dialog, 'errorToast');
const dialogSpy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = username;
Expand Down
22 changes: 11 additions & 11 deletions test/components/delegates/vote.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ describe('Vote component controller', () => {
let $scope;
let controller;
let $componentController;
let delegateServiceMock;
let delegateService;
let delegateApiMock;
let delegateApi;
let $q;
let accountDelegtatesDeferred;

beforeEach(inject((_$componentController_, _$rootScope_, _delegateService_, _$q_) => {
beforeEach(inject((_$componentController_, _$rootScope_, _delegateApi_, _$q_) => {
$componentController = _$componentController_;
$rootScope = _$rootScope_;
delegateService = _delegateService_;
delegateApi = _delegateApi_;
$q = _$q_;
}));

beforeEach(() => {
accountDelegtatesDeferred = $q.defer();
delegateServiceMock = sinon.mock(delegateService);
delegateServiceMock.expects('listAccountDelegates').returns(accountDelegtatesDeferred.promise);
delegateApiMock = sinon.mock(delegateApi);
delegateApiMock.expects('listAccountDelegates').returns(accountDelegtatesDeferred.promise);

$scope = $rootScope.$new();
controller = $componentController('vote', $scope, {
Expand Down Expand Up @@ -98,21 +98,21 @@ describe('Vote component controller', () => {
});

describe('constructor()', () => {
it('calls delegateService.listAccountDelegates and then sets result to this.votedList', () => {
it('calls delegateApi.listAccountDelegates and then sets result to this.votedList', () => {
const delegates = [{ username: 'genesis_42' }];
accountDelegtatesDeferred.resolve({ success: true, delegates });
$scope.$apply();
expect(controller.votedList).to.deep.equal(delegates);
});

it('calls delegateService.listAccountDelegates and if result.delegates is not defined then sets [] to this.votedList', () => {
it('calls delegateApi.listAccountDelegates and if result.delegates is not defined then sets [] to this.votedList', () => {
const delegates = undefined;
accountDelegtatesDeferred.resolve({ success: true, delegates });
$scope.$apply();
expect(controller.votedList).to.deep.equal([]);
});

it('calls delegateService.listAccountDelegates and then sets result to this.votedDict', () => {
it('calls delegateApi.listAccountDelegates and then sets result to this.votedDict', () => {
const delegates = [{ username: 'genesis_42' }];
accountDelegtatesDeferred.resolve({ success: true, delegates });
$scope.$apply();
Expand All @@ -126,13 +126,13 @@ describe('Vote component controller', () => {

beforeEach(() => {
deffered = $q.defer();
delegateServiceMock.expects('vote').returns(deffered.promise);
delegateApiMock.expects('vote').returns(deffered.promise);
dilaogServiceMock = sinon.mock(controller.dialog);
});

afterEach(() => {
dilaogServiceMock.verify();
delegateServiceMock.verify();
delegateApiMock.verify();
});

it('shows an error toast if request fails', () => {
Expand Down
Loading

0 comments on commit a2adc44

Please sign in to comment.