diff --git a/test/server_side/controllers/groups.test.js b/test/server_side/controllers/groups.test.js index 5146fb8f9b..5d333b4661 100644 --- a/test/server_side/controllers/groups.test.js +++ b/test/server_side/controllers/groups.test.js @@ -151,6 +151,7 @@ describe('Groups Controller', function() { 'another-user' ], save: sinon.stub().yields(), + leave: sinon.stub().yields(), markModified: sinon.spy() }; @@ -177,54 +178,54 @@ describe('Groups Controller', function() { context('party', function() { beforeEach(function() { group.type = 'party'; + }); + + it('prevents user from leaving party if quest is active and part of the active members list', function() { group.quest = { - leader : 'another-user', active: true, members: { - 'user-id': true, - 'another-user': true - }, - key : 'vice1', - progress : { - hp : 364, - collect : {} + another_user: true, + yet_another_user: null, + 'user-id': true } }; - 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); - 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.calledWith(403, 'You cannot leave party during an active quest. Please leave the quest first'); }); 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); - 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; }); }); diff --git a/website/src/controllers/groups.js b/website/src/controllers/groups.js index 64b45da0e8..49c7110c53 100644 --- a/website/src/controllers/groups.js +++ b/website/src/controllers/groups.js @@ -505,7 +505,7 @@ api.leave = function(req, res, next) { var user = res.locals.user; 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'); } diff --git a/website/views/options/social/quests/questNotActive.jade b/website/views/options/social/quests/questNotActive.jade index 6b56e78983..2c0d1d639d 100644 --- a/website/views/options/social/quests/questNotActive.jade +++ b/website/views/options/social/quests/questNotActive.jade @@ -1,4 +1,4 @@ -div(ng-if='group.quest.active==false') +div(ng-if='group.quest.active===false') tabset tab(heading=env.t('invitations')) +participants(false)