mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-22 05:44:16 +00:00
tests: Update updateStats test
This commit is contained in:
parent
1b118d86b2
commit
80ed048d5c
2 changed files with 41 additions and 16 deletions
|
|
@ -2272,13 +2272,12 @@ api.wrap = function(user, main) {
|
|||
})()]++;
|
||||
},
|
||||
updateStats: function(stats, req, analytics) {
|
||||
var tnl;
|
||||
if (stats.hp <= 0) {
|
||||
return user.stats.hp = 0;
|
||||
}
|
||||
user.stats.hp = stats.hp;
|
||||
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) {
|
||||
user.stats.exp = stats.exp;
|
||||
while (stats.exp >= tnl) {
|
||||
|
|
|
|||
|
|
@ -6,40 +6,66 @@ describe('user.fns.updateStats', () => {
|
|||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
stats: {
|
||||
int: 20,
|
||||
str: 20,
|
||||
con: 20,
|
||||
per: 20,
|
||||
lvl: 20,
|
||||
},
|
||||
user = generateUser({});
|
||||
});
|
||||
|
||||
context('no hp', () => {
|
||||
it('returns 0 if user\'s hp is 0', () => {
|
||||
let stats = {
|
||||
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', () => {
|
||||
it('adds an attibute point when user\'s stat points are less than max level', () => {
|
||||
user.stats.exp = 3581;
|
||||
it('Adds an attibute point when user\'s stat points are less than max level', () => {
|
||||
let stats = {
|
||||
exp: 3581,
|
||||
};
|
||||
|
||||
user.stats.lvl = 99;
|
||||
user.stats.str = 25;
|
||||
user.stats.int = 25;
|
||||
user.stats.con = 25;
|
||||
user.stats.per = 24;
|
||||
|
||||
user.fns.updateStats(user.stats);
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.stats.points).to.eql(1);
|
||||
});
|
||||
|
||||
it('does not add an attibute point when user\'s stat points are equal to max level', () => {
|
||||
user.stats.exp = 3581;
|
||||
it('Does not add an attibute point when user\'s stat points are equal to max level', () => {
|
||||
let stats = {
|
||||
exp: 3581,
|
||||
};
|
||||
|
||||
user.stats.lvl = 99;
|
||||
user.stats.str = 25;
|
||||
user.stats.int = 25;
|
||||
user.stats.con = 25;
|
||||
user.stats.per = 25;
|
||||
|
||||
user.fns.updateStats(user.stats);
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.stats.points).to.eql(0);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue