Skip to content

Commit

Permalink
Remove questKey from url, added quest member support, removed extra t…
Browse files Browse the repository at this point in the history
…ests, and fixed analytics import
  • Loading branch information
TheHollidayInn committed Feb 2, 2016
1 parent 3e2551e commit 869416c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,27 @@ 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',
message: t('groupNotFound'),
});
});

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',
Expand All @@ -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);
});
});
});
17 changes: 8 additions & 9 deletions website/src/controllers/api-v3/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -669,11 +669,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();
Expand All @@ -683,9 +683,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 = {
Expand All @@ -696,18 +694,19 @@ 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;
await user.save();

// questStart(req,res,next);

res.respond(200, {});
res.respond(200, group.quest);
},
};
export default api;

0 comments on commit 869416c

Please sign in to comment.