Fix level up webhook (#10347)

* use user._tmp for level up webhook

* use post save hook to send webhook
This commit is contained in:
Matteo Pagliazzi
2018-05-09 19:04:29 +02:00
committed by GitHub
parent bbbd1f9f73
commit a8655d923a
4 changed files with 83 additions and 58 deletions
@@ -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', () => {
+6 -7
View File
@@ -8,7 +8,7 @@ describe('common.fns.updateStats', () => {
beforeEach(() => {
user = generateUser();
// user.addNotification = sinon.spy();
user.addNotification = sinon.spy();
});
context('No Hp', () => {
@@ -110,26 +110,25 @@ describe('common.fns.updateStats', () => {
expect(user.stats.points).to.eql(10);
});
xit('add user notification when drops are enabled', () => {
it('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');
});
xit('add user notification when the user levels up', () => {
it('add user notification when the user levels up', () => {
const initialLvl = user.stats.lvl;
updateStats(user, {
exp: 3000,
});
expect(user.addNotification).to.be.calledTwice; // once is for drops enabled
expect(user.addNotification).to.be.calledWith('LEVELED_UP', {
expect(user._tmp.leveledUp).to.eql([{
initialLvl,
newLvl: user.stats.lvl,
});
}]);
});
xit('add user notification when rebirth is enabled', () => {
it('add user notification when rebirth is enabled', () => {
user.stats.lvl = 51;
updateStats(user, { });
expect(user.addNotification).to.be.calledTwice; // once is for drops enabled