From 06c88b14b23e0ce27696f54339b45666e28f6c6a Mon Sep 17 00:00:00 2001 From: Keith Holliday Date: Tue, 2 Feb 2016 16:36:08 -0600 Subject: [PATCH] Remove questKey from url, added quest member support, removed extra tests, and fixed analytics import --- .../POST-groups_groupid_quests_reject.test.js | 41 ++++++------------- website/src/controllers/api-v3/groups.js | 17 ++++---- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/test/api/v3/integration/quests/POST-groups_groupid_quests_reject.test.js b/test/api/v3/integration/quests/POST-groups_groupid_quests_reject.test.js index e5f7517eff9f..dbdc44d88785 100644 --- a/test/api/v3/integration/quests/POST-groups_groupid_quests_reject.test.js +++ b/test/api/v3/integration/quests/POST-groups_groupid_quests_reject.test.js @@ -30,7 +30,7 @@ describe('POST /groups/:groupId/quests/invite/:questKey', () => { context('failure conditions', () => { it('returns an error when group is not found', async () => { - await expect(member.post(`/groups/${generateUUID()}/quests/reject/${PET_QUEST}`)) + await expect(member.post(`/groups/${generateUUID()}/quests/reject`)) .to.eventually.be.rejected.and.eql({ code: 404, error: 'NotFound', @@ -38,43 +38,19 @@ describe('POST /groups/:groupId/quests/invite/:questKey', () => { }); }); - it('returns an error when group is not a party', async () => { - let { group, groupLeader } = await createAndPopulateGroup({ - groupDetails: { type: 'guild', privacy: 'private' }, - }); - - await expect(groupLeader.post(`/groups/${group._id}/quests/reject/${PET_QUEST}`)) - .to.eventually.be.rejected.and.eql({ - code: 401, - error: 'NotAuthorized', - message: t('guildQuestsNotSupported'), - }); - }); - it('returns an error when quest is not found', async () => { - let questKey = 'fakeQuestName'; - - await expect(member.post(`/groups/${questingGroup._id}/quests/reject/${questKey}`)) + await expect(member.post(`/groups/${questingGroup._id}/quests/reject`)) .to.eventually.be.rejected.and.eql({ code: 404, error: 'NotFound', - message: t('questNotFound', { key: questKey }), - }); - }); - - it('returns an error when user is not on the quest', async () => { - await expect(member.post(`/groups/${questingGroup._id}/quests/reject/${PET_QUEST}`)) - .to.eventually.be.rejected.and.eql({ - code: 401, - error: 'NotAuthorized', - message: t('questNotOwned'), + message: t('questNotFound', { key: '' }), }); }); it('returns an error when group is not on a quest', async () => { await member.update(userQuestUpdate); - await expect(member.post(`/groups/${questingGroup._id}/quests/reject/${PET_QUEST}`)) + await expect(member.post(`/groups/${questingGroup._id}/quests/reject`)) .to.eventually.be.rejected.and.eql({ code: 404, error: 'NotFound', @@ -88,11 +64,18 @@ describe('POST /groups/:groupId/quests/invite/:questKey', () => { await member.update(userQuestUpdate); await questingGroup.update({'quest.key': PET_QUEST}); - await member.post(`/groups/${questingGroup._id}/quests/reject/${PET_QUEST}`); + let questMembers = {}; + questMembers[member._id] = true; + await questingGroup.update({'quest.members': questMembers}); + let rejectResult = await member.post(`/groups/${questingGroup._id}/quests/reject`); let userWithRejectInvitation = await member.get('/user'); + let updatedGroup = await member.get(`/groups/${questingGroup._id}`); + expect(userWithRejectInvitation.party.quest.key).to.be.null; expect(userWithRejectInvitation.party.quest.RSVPNeeded).to.be.false; + expect(updatedGroup.quest.members[member._id]).to.be.false; + expect(updatedGroup.quest).to.deep.equal(rejectResult); }); }); }); diff --git a/website/src/controllers/api-v3/groups.js b/website/src/controllers/api-v3/groups.js index 785ea564ba9e..f4fce4176fa9 100644 --- a/website/src/controllers/api-v3/groups.js +++ b/website/src/controllers/api-v3/groups.js @@ -18,7 +18,7 @@ import * as firebase from '../../libs/api-v3/firebase'; import { sendTxn as sendTxnEmail } from '../../libs/api-v3/email'; import { encrypt } from '../../libs/api-v3/encryption'; import { quests as questScrolls } from '../../../../common/script/content'; -import { mockAnalyticsService } from '../../libs/api-v3/analyticsService'; +import { track } from '../../libs/api-v3/analyticsService'; let api = {}; @@ -671,11 +671,11 @@ api.inviteToQuest = { */ api.rejectQuest = { method: 'POST', - url: '/groups/:groupId/quests/reject/:questKey', + url: '/groups/:groupId/quests/reject', middlewares: [authWithHeaders(), cron], async handler (req, res) { let user = res.locals.user; - let questKey = req.params.questKey; + let questKey = user.party.quest.key; let quest = questScrolls[questKey]; req.checkParams('groupId', res.t('groupIdRequired')).notEmpty(); @@ -685,9 +685,7 @@ api.rejectQuest = { let group = await Group.getGroup({user, groupId: req.params.groupId, fields: 'type quest'}); if (!group) throw new NotFound(res.t('groupNotFound')); - if (group.type !== 'party') throw new NotAuthorized(res.t('guildQuestsNotSupported')); if (!quest) throw new NotFound(res.t('questNotFound', { key: questKey })); - if (!user.items.quests[questKey]) throw new NotAuthorized(res.t('questNotOwned')); if (!group.quest.key) throw new NotFound(res.t('questInvitationDoesNotExist')); let analyticsData = { @@ -698,10 +696,11 @@ api.rejectQuest = { questName: group.quest.key, uuid: user._id, }; - mockAnalyticsService.track('quest', analyticsData); + track('quest', analyticsData); - // @TODO: Are we tracking members this way? - // group.quest.members[user._id] = false; + group.quest.members[user._id] = false; + group.markModified('quest.members'); + await group.save(); user.party.quest.RSVPNeeded = false; user.party.quest.key = null; @@ -709,7 +708,7 @@ api.rejectQuest = { // questStart(req,res,next); - res.respond(200, {}); + res.respond(200, group.quest); }, }; >>>>>>> Added quest reject route and intial tests