Send a message to the party chat when a quest is aborted, fixes #4879 (#8150)

* Send a message to the party chat when a quest is aborted

* Added test cases for sending a message to party when quest is aborted

* Restore Group.prototype.sendChat after aborted quest test
This commit is contained in:
Alyssa Batula
2016-11-26 02:48:42 -05:00
committed by Alys
parent a5ad9c30f0
commit 7eeeda2aae
2 changed files with 10 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import {
generateUser, generateUser,
} from '../../../../helpers/api-v3-integration.helper'; } from '../../../../helpers/api-v3-integration.helper';
import { v4 as generateUUID } from 'uuid'; import { v4 as generateUUID } from 'uuid';
import { model as Group } from '../../../../../website/server/models/group';
describe('POST /groups/:groupId/quests/abort', () => { describe('POST /groups/:groupId/quests/abort', () => {
let questingGroup; let questingGroup;
@@ -85,6 +86,7 @@ describe('POST /groups/:groupId/quests/abort', () => {
}); });
it('aborts a quest', async () => { it('aborts a quest', async () => {
sandbox.stub(Group.prototype, 'sendChat');
await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`); await leader.post(`/groups/${questingGroup._id}/quests/invite/${PET_QUEST}`);
await partyMembers[0].post(`/groups/${questingGroup._id}/quests/accept`); await partyMembers[0].post(`/groups/${questingGroup._id}/quests/accept`);
await partyMembers[1].post(`/groups/${questingGroup._id}/quests/accept`); await partyMembers[1].post(`/groups/${questingGroup._id}/quests/accept`);
@@ -123,5 +125,8 @@ describe('POST /groups/:groupId/quests/abort', () => {
}, },
members: {}, members: {},
}); });
expect(Group.prototype.sendChat).to.be.calledOnce;
expect(Group.prototype.sendChat).to.be.calledWithMatch(/aborted the party quest Wail of the Whale.`/);
Group.prototype.sendChat.restore();
}); });
}); });

View File

@@ -412,12 +412,16 @@ api.abortQuest = {
let validationErrors = req.validationErrors(); let validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors; if (validationErrors) throw validationErrors;
let group = await Group.getGroup({user, groupId, fields: 'type quest leader'}); let group = await Group.getGroup({user, groupId, fields: 'type quest leader chat'});
if (!group) throw new NotFound(res.t('groupNotFound')); if (!group) throw new NotFound(res.t('groupNotFound'));
if (group.type !== 'party') throw new NotAuthorized(res.t('guildQuestsNotSupported')); if (group.type !== 'party') throw new NotAuthorized(res.t('guildQuestsNotSupported'));
if (!group.quest.active) throw new NotFound(res.t('noActiveQuestToAbort')); if (!group.quest.active) throw new NotFound(res.t('noActiveQuestToAbort'));
if (user._id !== group.leader && user._id !== group.quest.leader) throw new NotAuthorized(res.t('onlyLeaderAbortQuest')); if (user._id !== group.leader && user._id !== group.quest.leader) throw new NotAuthorized(res.t('onlyLeaderAbortQuest'));
let questName = questScrolls[group.quest.key].text('en');
group.sendChat(`\`${user.profile.name} aborted the party quest ${questName}.\``);
let memberUpdates = User.update({ let memberUpdates = User.update({
'party._id': groupId, 'party._id': groupId,
}, { }, {