voluntarily leaving a party removes the user from the quest the party is involved in (#7845)

* voluntarily leaving a party removes the user from the quest the party is involved in. part of #7653

* addressing pr comments, removing lodash dependency and unecessary comment

* using the existing update object instead of group.save to avoid duplicate behavior

* finalizing tests
This commit is contained in:
Travis
2016-07-30 04:53:29 -07:00
committed by Blade Barringer
parent 6e55be033b
commit 6804125068
2 changed files with 46 additions and 4 deletions
+41
View File
@@ -434,6 +434,47 @@ describe('Group Model', () => {
});
});
describe('#leaveGroup', () => {
it('removes user from group quest', async () => {
party.quest.members = {
[participatingMember._id]: true,
[questLeader._id]: true,
[nonParticipatingMember._id]: false,
[undecidedMember._id]: null,
};
party.memberCount = 4;
await party.save();
await party.leave(participatingMember);
party = await Group.findOne({_id: party._id});
expect(party.quest.members).to.eql({
[questLeader._id]: true,
[nonParticipatingMember._id]: false,
[undecidedMember._id]: null,
});
});
it('deletes a private group when the last member leaves', async () => {
party.memberCount = 1;
await party.leave(participatingMember);
party = await Group.findOne({_id: party._id});
expect(party).to.not.exist;
});
it('does not delete a public group when the last member leaves', async () => {
party.memberCount = 1;
party.privacy = 'public';
await party.leave(participatingMember);
party = await Group.findOne({_id: party._id});
expect(party).to.exist;
});
});
describe('#sendChat', () => {
beforeEach(() => {
sandbox.spy(User, 'update');