Skip to content

Commit

Permalink
Removed questKey from url, added quest member support, removed extra …
Browse files Browse the repository at this point in the history
…tests, and fixed analytics import
  • Loading branch information
TheHollidayInn committed Feb 2, 2016
1 parent d5148a7 commit 3e1fad0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 41 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);
});
});
});
21 changes: 9 additions & 12 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 @@ -618,8 +618,6 @@ api.inviteToGroup = {
},
};

<<<<<<< e3c7d2834e6e5fa024afb71032c21177ca4124a7
=======
/**
* @api {post} /groups/:groupId/quests/invite Invite users to a quest
* @apiVersion 3.0.0
Expand Down Expand Up @@ -671,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 @@ -685,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 @@ -698,19 +694,20 @@ 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);
},
};
>>>>>>> Added quest reject route and intial tests

export default api;

0 comments on commit 3e1fad0

Please sign in to comment.