mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Removed update stats notification (#10339)
* Removed update stats notification * Removed level up hook
This commit is contained in:
@@ -82,48 +82,48 @@ describe('POST /tasks/:id/score/:direction', () => {
|
||||
expect(body.delta).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
context('sending user activity webhooks', () => {
|
||||
before(async () => {
|
||||
await server.start();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server.close();
|
||||
});
|
||||
|
||||
it('sends user activity webhook when the user levels up', async () => {
|
||||
let uuid = generateUUID();
|
||||
|
||||
await user.post('/user/webhook', {
|
||||
url: `http://localhost:${server.port}/webhooks/${uuid}`,
|
||||
type: 'userActivity',
|
||||
enabled: true,
|
||||
options: {
|
||||
leveledUp: true,
|
||||
},
|
||||
});
|
||||
|
||||
const initialLvl = user.stats.lvl;
|
||||
|
||||
await user.update({
|
||||
'stats.exp': 3000,
|
||||
});
|
||||
let task = await user.post('/tasks/user', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
});
|
||||
|
||||
await user.post(`/tasks/${task.id}/score/up`);
|
||||
await user.sync();
|
||||
await sleep();
|
||||
|
||||
let body = server.getWebhookData(uuid);
|
||||
|
||||
expect(body.type).to.eql('leveledUp');
|
||||
expect(body.initialLvl).to.eql(initialLvl);
|
||||
expect(body.finalLvl).to.eql(user.stats.lvl);
|
||||
});
|
||||
});
|
||||
// context('sending user activity webhooks', () => {
|
||||
// before(async () => {
|
||||
// await server.start();
|
||||
// });
|
||||
//
|
||||
// after(async () => {
|
||||
// await server.close();
|
||||
// });
|
||||
//
|
||||
// it('sends user activity webhook when the user levels up', async () => {
|
||||
// let uuid = generateUUID();
|
||||
//
|
||||
// await user.post('/user/webhook', {
|
||||
// url: `http://localhost:${server.port}/webhooks/${uuid}`,
|
||||
// type: 'userActivity',
|
||||
// enabled: true,
|
||||
// options: {
|
||||
// leveledUp: true,
|
||||
// },
|
||||
// });
|
||||
//
|
||||
// const initialLvl = user.stats.lvl;
|
||||
//
|
||||
// await user.update({
|
||||
// 'stats.exp': 3000,
|
||||
// });
|
||||
// let task = await user.post('/tasks/user', {
|
||||
// text: 'test habit',
|
||||
// type: 'habit',
|
||||
// });
|
||||
//
|
||||
// await user.post(`/tasks/${task.id}/score/up`);
|
||||
// await user.sync();
|
||||
// await sleep();
|
||||
//
|
||||
// let body = server.getWebhookData(uuid);
|
||||
//
|
||||
// expect(body.type).to.eql('leveledUp');
|
||||
// expect(body.initialLvl).to.eql(initialLvl);
|
||||
// expect(body.finalLvl).to.eql(user.stats.lvl);
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
||||
context('todos', () => {
|
||||
|
||||
@@ -8,7 +8,7 @@ describe('common.fns.updateStats', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser();
|
||||
user.addNotification = sinon.spy();
|
||||
// user.addNotification = sinon.spy();
|
||||
});
|
||||
|
||||
context('No Hp', () => {
|
||||
@@ -110,14 +110,14 @@ describe('common.fns.updateStats', () => {
|
||||
expect(user.stats.points).to.eql(10);
|
||||
});
|
||||
|
||||
it('add user notification when drops are enabled', () => {
|
||||
xit('add user notification when drops are enabled', () => {
|
||||
user.stats.lvl = 3;
|
||||
updateStats(user, { });
|
||||
expect(user.addNotification).to.be.calledOnce;
|
||||
expect(user.addNotification).to.be.calledWith('DROPS_ENABLED');
|
||||
});
|
||||
|
||||
it('add user notification when the user levels up', () => {
|
||||
xit('add user notification when the user levels up', () => {
|
||||
const initialLvl = user.stats.lvl;
|
||||
updateStats(user, {
|
||||
exp: 3000,
|
||||
@@ -129,7 +129,7 @@ describe('common.fns.updateStats', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('add user notification when rebirth is enabled', () => {
|
||||
xit('add user notification when rebirth is enabled', () => {
|
||||
user.stats.lvl = 51;
|
||||
updateStats(user, { });
|
||||
expect(user.addNotification).to.be.calledTwice; // once is for drops enabled
|
||||
|
||||
@@ -20,7 +20,7 @@ module.exports = function updateStats (user, stats, req = {}, analytics) {
|
||||
if (stats.exp >= experienceToNextLevel) {
|
||||
user.stats.exp = stats.exp;
|
||||
|
||||
const initialLvl = user.stats.lvl;
|
||||
// const initialLvl = user.stats.lvl;
|
||||
|
||||
while (stats.exp >= experienceToNextLevel) {
|
||||
stats.exp -= experienceToNextLevel;
|
||||
@@ -50,12 +50,13 @@ module.exports = function updateStats (user, stats, req = {}, analytics) {
|
||||
}
|
||||
}
|
||||
|
||||
const newLvl = user.stats.lvl;
|
||||
|
||||
if (user.addNotification) user.addNotification('LEVELED_UP', {
|
||||
initialLvl,
|
||||
newLvl,
|
||||
});
|
||||
// @TODO: Tmp disable to see if this is causing concurrency
|
||||
// const newLvl = user.stats.lvl;
|
||||
//
|
||||
// if (user.addNotification) user.addNotification('LEVELED_UP', {
|
||||
// initialLvl,
|
||||
// newLvl,
|
||||
// });
|
||||
}
|
||||
|
||||
user.stats.exp = stats.exp;
|
||||
|
||||
Reference in New Issue
Block a user