mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Correct leave call to prevent leaving if quest is in progress
(cherry picked from commit eddea562f4)
This commit is contained in:
@@ -151,6 +151,7 @@ describe('Groups Controller', function() {
|
|||||||
'another-user'
|
'another-user'
|
||||||
],
|
],
|
||||||
save: sinon.stub().yields(),
|
save: sinon.stub().yields(),
|
||||||
|
leave: sinon.stub().yields(),
|
||||||
markModified: sinon.spy()
|
markModified: sinon.spy()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -177,54 +178,54 @@ describe('Groups Controller', function() {
|
|||||||
context('party', function() {
|
context('party', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
group.type = 'party';
|
group.type = 'party';
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prevents user from leaving party if quest is active and part of the active members list', function() {
|
||||||
group.quest = {
|
group.quest = {
|
||||||
leader : 'another-user',
|
|
||||||
active: true,
|
active: true,
|
||||||
members: {
|
members: {
|
||||||
'user-id': true,
|
another_user: true,
|
||||||
'another-user': true
|
yet_another_user: null,
|
||||||
},
|
'user-id': true
|
||||||
key : 'vice1',
|
|
||||||
progress : {
|
|
||||||
hp : 364,
|
|
||||||
collect : {}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
sinon.spy(Group, 'update');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
Group.update.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('prevents user from leaving party if quest is active', function() {
|
|
||||||
user.party = {
|
|
||||||
quest : {
|
|
||||||
key : 'vice1',
|
|
||||||
progress : {
|
|
||||||
up : 50,
|
|
||||||
down : 0,
|
|
||||||
collect : {}
|
|
||||||
},
|
|
||||||
completed : null,
|
|
||||||
RSVPNeeded : false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
groupsController.leave(req, res);
|
groupsController.leave(req, res);
|
||||||
|
|
||||||
expect(Group.update).to.not.be.called;
|
expect(group.leave).to.not.be.called;
|
||||||
expect(res.json).to.be.calledOnce;
|
expect(res.json).to.be.calledOnce;
|
||||||
expect(res.json).to.be.calledWith(403, 'You cannot leave party during an active quest. Please leave the quest first');
|
expect(res.json).to.be.calledWith(403, 'You cannot leave party during an active quest. Please leave the quest first');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('leaves party if quest is not active', function() {
|
it('leaves party if quest is not active', function() {
|
||||||
user.party = { quest: { key: null } };
|
group.quest = {
|
||||||
|
active: false,
|
||||||
|
members: {
|
||||||
|
another_user: true,
|
||||||
|
yet_another_user: null,
|
||||||
|
'user-id': null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
groupsController.leave(req, res);
|
groupsController.leave(req, res);
|
||||||
|
|
||||||
expect(Group.update).to.be.calledOnce;
|
expect(group.leave).to.be.calledOnce;
|
||||||
|
expect(res.json).to.not.be.called;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('leaves party if quest is active, but user is not part of quest', function() {
|
||||||
|
group.quest = {
|
||||||
|
active: true,
|
||||||
|
members: {
|
||||||
|
another_user: true,
|
||||||
|
yet_another_user: null,
|
||||||
|
'user-id': null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
groupsController.leave(req, res);
|
||||||
|
|
||||||
|
expect(group.leave).to.be.calledOnce;
|
||||||
expect(res.json).to.not.be.called;
|
expect(res.json).to.not.be.called;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ api.leave = function(req, res, next) {
|
|||||||
var user = res.locals.user;
|
var user = res.locals.user;
|
||||||
var group = res.locals.group;
|
var group = res.locals.group;
|
||||||
|
|
||||||
if (group.type === 'party' && user.party.quest && user.party.quest.key) {
|
if (group.type === 'party' && group.quest && group.quest.active && group.quest.members && group.quest.members[user._id]) {
|
||||||
return res.json(403, 'You cannot leave party during an active quest. Please leave the quest first');
|
return res.json(403, 'You cannot leave party during an active quest. Please leave the quest first');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user