Add method to get user balance in gems

This commit is contained in:
Blade Barringer 2015-07-24 10:03:56 -05:00
parent 061e381abf
commit 791e2f0c16
2 changed files with 22 additions and 0 deletions

View file

@ -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)) {

View file

@ -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);
});
});
});