tests: Update updateStats test

This commit is contained in:
Blade Barringer
2015-12-26 19:52:25 -06:00
parent 1b118d86b2
commit 80ed048d5c
2 changed files with 41 additions and 16 deletions

View File

@@ -2272,13 +2272,12 @@ api.wrap = function(user, main) {
})()]++; })()]++;
}, },
updateStats: function(stats, req, analytics) { updateStats: function(stats, req, analytics) {
var tnl;
if (stats.hp <= 0) { if (stats.hp <= 0) {
return user.stats.hp = 0; return user.stats.hp = 0;
} }
user.stats.hp = stats.hp; user.stats.hp = stats.hp;
user.stats.gp = stats.gp >= 0 ? stats.gp : 0; user.stats.gp = stats.gp >= 0 ? stats.gp : 0;
tnl = api.tnl(user.stats.lvl); var tnl = api.tnl(user.stats.lvl);
if (stats.exp >= tnl) { if (stats.exp >= tnl) {
user.stats.exp = stats.exp; user.stats.exp = stats.exp;
while (stats.exp >= tnl) { while (stats.exp >= tnl) {

View File

@@ -6,40 +6,66 @@ describe('user.fns.updateStats', () => {
let user; let user;
beforeEach(() => { beforeEach(() => {
user = generateUser({ user = generateUser({});
stats: { });
int: 20,
str: 20, context('no hp', () => {
con: 20, it('returns 0 if user\'s hp is 0', () => {
per: 20, let stats = {
lvl: 20, hp: 0,
}, };
expect(user.fns.updateStats(stats)).to.eql(0);
});
it('returns 0 if user\'s hp is less than 0', () => {
let stats = {
hp: -5,
};
expect(user.fns.updateStats(stats)).to.eql(0);
});
it('sets user\'s hp to 0 if it is less than 0', () => {
let stats = {
hp: -5,
};
user.fns.updateStats(stats)
expect(user.stats.hp).to.eql(0);
}); });
}); });
context('Stat Allocation', () => { context('Stat Allocation', () => {
it('adds an attibute point when user\'s stat points are less than max level', () => { it('Adds an attibute point when user\'s stat points are less than max level', () => {
user.stats.exp = 3581; let stats = {
exp: 3581,
};
user.stats.lvl = 99; user.stats.lvl = 99;
user.stats.str = 25; user.stats.str = 25;
user.stats.int = 25; user.stats.int = 25;
user.stats.con = 25; user.stats.con = 25;
user.stats.per = 24; user.stats.per = 24;
user.fns.updateStats(user.stats); user.fns.updateStats(stats);
expect(user.stats.points).to.eql(1); expect(user.stats.points).to.eql(1);
}); });
it('does not add an attibute point when user\'s stat points are equal to max level', () => { it('Does not add an attibute point when user\'s stat points are equal to max level', () => {
user.stats.exp = 3581; let stats = {
exp: 3581,
};
user.stats.lvl = 99; user.stats.lvl = 99;
user.stats.str = 25; user.stats.str = 25;
user.stats.int = 25; user.stats.int = 25;
user.stats.con = 25; user.stats.con = 25;
user.stats.per = 25; user.stats.per = 25;
user.fns.updateStats(user.stats); user.fns.updateStats(stats);
expect(user.stats.points).to.eql(0); expect(user.stats.points).to.eql(0);
}); });