mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix: Corrects stat allocation bug where it was possible to recieve more points than 100
fixes #6434
This commit is contained in:
@@ -9,7 +9,7 @@ describe('user.fns.updateStats', () => {
|
||||
user = generateUser({});
|
||||
});
|
||||
|
||||
context('no hp', () => {
|
||||
context('No Hp', () => {
|
||||
it('returns 0 if user\'s hp is 0', () => {
|
||||
let stats = {
|
||||
hp: 0,
|
||||
@@ -38,7 +38,19 @@ describe('user.fns.updateStats', () => {
|
||||
});
|
||||
|
||||
context('Stat Allocation', () => {
|
||||
it('Adds an attibute point when user\'s stat points are less than max level', () => {
|
||||
it('adds only attribute points up to user\'s level', () => {
|
||||
let stats = {
|
||||
exp: 261,
|
||||
};
|
||||
|
||||
user.stats.lvl = 10;
|
||||
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.stats.points).to.eql(11);
|
||||
});
|
||||
|
||||
it('adds an attibute point when user\'s stat points are less than max level', () => {
|
||||
let stats = {
|
||||
exp: 3581,
|
||||
};
|
||||
@@ -54,7 +66,7 @@ describe('user.fns.updateStats', () => {
|
||||
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', () => {
|
||||
let stats = {
|
||||
exp: 3581,
|
||||
};
|
||||
@@ -69,5 +81,54 @@ describe('user.fns.updateStats', () => {
|
||||
|
||||
expect(user.stats.points).to.eql(0);
|
||||
});
|
||||
|
||||
it('does not add an attibute point when user\'s stat points + unallocated 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 = 15;
|
||||
user.stats.points = 10;
|
||||
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.stats.points).to.eql(10);
|
||||
});
|
||||
|
||||
it('only awards stat points up to level 100 if user is missing unallocated stat points and is over level 100', () => {
|
||||
let stats = {
|
||||
exp: 5581,
|
||||
};
|
||||
|
||||
user.stats.lvl = 104;
|
||||
user.stats.str = 25;
|
||||
user.stats.int = 25;
|
||||
user.stats.con = 25;
|
||||
user.stats.per = 15;
|
||||
user.stats.points = 0;
|
||||
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.stats.points).to.eql(10);
|
||||
});
|
||||
|
||||
// @TODO: Set up sinon sandbox
|
||||
xit('auto allocates stats if automaticAllocation is turned on', () => {
|
||||
sandbox.stub(user.fns, 'autoAllocate');
|
||||
|
||||
let stats = {
|
||||
exp: 261,
|
||||
};
|
||||
|
||||
user.stats.lvl = 10;
|
||||
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.fns.autoAllocate).to.be.calledOnce;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user