mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Remove user wrapping (#9960)
* remove user wrapping, fixes #9146 * update tests * fix tests
This commit is contained in:
@@ -32,10 +32,6 @@ describe('cron', () => {
|
||||
});
|
||||
|
||||
sinon.spy(analytics, 'track');
|
||||
|
||||
user._statsComputed = {
|
||||
mp: 10,
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -444,9 +440,13 @@ describe('cron', () => {
|
||||
tasksByType.dailys = [];
|
||||
tasksByType.dailys.push(task);
|
||||
|
||||
user._statsComputed = {
|
||||
con: 1,
|
||||
};
|
||||
const statsComputedRes = common.statsComputed(user);
|
||||
const stubbedStatsComputed = sinon.stub(common, 'statsComputed');
|
||||
stubbedStatsComputed.returns(Object.assign(statsComputedRes, {con: 1}));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
common.statsComputed.restore();
|
||||
});
|
||||
|
||||
it('computes isDue', () => {
|
||||
@@ -855,9 +855,13 @@ describe('cron', () => {
|
||||
tasksByType.dailys = [];
|
||||
tasksByType.dailys.push(task);
|
||||
|
||||
user._statsComputed = {
|
||||
con: 1,
|
||||
};
|
||||
const statsComputedRes = common.statsComputed(user);
|
||||
const stubbedStatsComputed = sinon.stub(common, 'statsComputed');
|
||||
stubbedStatsComputed.returns(Object.assign(statsComputedRes, {con: 1}));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
common.statsComputed.restore();
|
||||
});
|
||||
|
||||
it('stores a new entry in user.history.exp', () => {
|
||||
@@ -972,18 +976,27 @@ describe('cron', () => {
|
||||
|
||||
describe('adding mp', () => {
|
||||
it('should add mp to user', () => {
|
||||
const statsComputedRes = common.statsComputed(user);
|
||||
const stubbedStatsComputed = sinon.stub(common, 'statsComputed');
|
||||
|
||||
let mpBefore = user.stats.mp;
|
||||
tasksByType.dailys[0].completed = true;
|
||||
user._statsComputed.maxMP = 100;
|
||||
stubbedStatsComputed.returns(Object.assign(statsComputedRes, {maxMP: 100}));
|
||||
cron({user, tasksByType, daysMissed, analytics});
|
||||
expect(user.stats.mp).to.be.greaterThan(mpBefore);
|
||||
|
||||
common.statsComputed.restore();
|
||||
});
|
||||
|
||||
it('set user\'s mp to user._statsComputed.maxMP when user.stats.mp is greater', () => {
|
||||
it('set user\'s mp to statsComputed.maxMP when user.stats.mp is greater', () => {
|
||||
const statsComputedRes = common.statsComputed(user);
|
||||
const stubbedStatsComputed = sinon.stub(common, 'statsComputed');
|
||||
user.stats.mp = 120;
|
||||
user._statsComputed.maxMP = 100;
|
||||
stubbedStatsComputed.returns(Object.assign(statsComputedRes, {maxMP: 100}));
|
||||
cron({user, tasksByType, daysMissed, analytics});
|
||||
expect(user.stats.mp).to.equal(user._statsComputed.maxMP);
|
||||
expect(user.stats.mp).to.equal(common.statsComputed(user).maxMP);
|
||||
|
||||
common.statsComputed.restore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -998,14 +1011,18 @@ describe('cron', () => {
|
||||
tasksByType.dailys = [];
|
||||
tasksByType.dailys.push(task);
|
||||
|
||||
user._statsComputed = {
|
||||
con: 1,
|
||||
};
|
||||
const statsComputedRes = common.statsComputed(user);
|
||||
const stubbedStatsComputed = sinon.stub(common, 'statsComputed');
|
||||
stubbedStatsComputed.returns(Object.assign(statsComputedRes, {con: 1}));
|
||||
|
||||
daysMissed = 1;
|
||||
tasksByType.dailys[0].startDate = moment(new Date()).subtract({days: 1});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
common.statsComputed.restore();
|
||||
});
|
||||
|
||||
it('resets user progress', () => {
|
||||
cron({user, tasksByType, daysMissed, analytics});
|
||||
expect(user.party.quest.progress.up).to.equal(0);
|
||||
@@ -1023,7 +1040,10 @@ describe('cron', () => {
|
||||
it('adds a user notification', () => {
|
||||
let mpBefore = user.stats.mp;
|
||||
tasksByType.dailys[0].completed = true;
|
||||
user._statsComputed.maxMP = 100;
|
||||
|
||||
const statsComputedRes = common.statsComputed(user);
|
||||
const stubbedStatsComputed = sinon.stub(common, 'statsComputed');
|
||||
stubbedStatsComputed.returns(Object.assign(statsComputedRes, {maxMP: 100}));
|
||||
|
||||
daysMissed = 1;
|
||||
let hpBefore = user.stats.hp;
|
||||
@@ -1037,12 +1057,17 @@ describe('cron', () => {
|
||||
hp: user.stats.hp - hpBefore,
|
||||
mp: user.stats.mp - mpBefore,
|
||||
});
|
||||
|
||||
common.statsComputed.restore();
|
||||
});
|
||||
|
||||
it('condenses multiple notifications into one', () => {
|
||||
let mpBefore1 = user.stats.mp;
|
||||
tasksByType.dailys[0].completed = true;
|
||||
user._statsComputed.maxMP = 100;
|
||||
|
||||
const statsComputedRes = common.statsComputed(user);
|
||||
const stubbedStatsComputed = sinon.stub(common, 'statsComputed');
|
||||
stubbedStatsComputed.returns(Object.assign(statsComputedRes, {maxMP: 100}));
|
||||
|
||||
daysMissed = 1;
|
||||
let hpBefore1 = user.stats.hp;
|
||||
@@ -1073,6 +1098,7 @@ describe('cron', () => {
|
||||
mp: user.stats.mp - mpBefore2 - (mpBefore2 - mpBefore1),
|
||||
});
|
||||
expect(user.notifications[0].type).to.not.equal('CRON');
|
||||
common.statsComputed.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user