diff --git a/common/script/public/userServices.js b/common/script/public/userServices.js index f866e133a9..b26a4c531d 100644 --- a/common/script/public/userServices.js +++ b/common/script/public/userServices.js @@ -194,6 +194,11 @@ angular.module('habitrpg') return this.settings.auth.apiId !== ""; }, + getBalanceInGems: function() { + var balance = user.balance || 0; + return balance * 4; + }, + log: function (action, cb) { //push by one buy one if an array passed in. if (_.isArray(action)) { diff --git a/test/spec/services/userServicesSpec.js b/test/spec/services/userServicesSpec.js index 5861f76d8b..2f34507e32 100644 --- a/test/spec/services/userServicesSpec.js +++ b/test/spec/services/userServicesSpec.js @@ -46,4 +46,21 @@ describe('userServices', function() { //TODO where does that null comes from? expect(user.settings.sync.queue).to.eql([null, {}]); }); + + describe('getBalanceInGems', function() { + + it('multiplies balance by 4', function() { + user.user.balance = 5; + var balanceInGems = user.getBalanceInGems(); + + expect(balanceInGems).to.eql(20); + }); + + it('returns zero if balance is not defined', function() { + var balanceInGems = user.getBalanceInGems(); + + expect(user.user.balance).to.not.exist; + expect(balanceInGems).to.eql(0); + }); + }); });