mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Removed questKey from url, added quest member support, removed extra tests, and fixed analytics import
This commit is contained in:
@@ -30,7 +30,7 @@ describe('POST /groups/:groupId/quests/invite/:questKey', () => {
|
|||||||
|
|
||||||
context('failure conditions', () => {
|
context('failure conditions', () => {
|
||||||
it('returns an error when group is not found', async () => {
|
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({
|
.to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotFound',
|
||||||
@@ -38,43 +38,10 @@ 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}`))
|
|
||||||
.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'),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns an error when group is not on a quest', async () => {
|
it('returns an error when group is not on a quest', async () => {
|
||||||
await member.update(userQuestUpdate);
|
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({
|
.to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotFound',
|
||||||
@@ -88,11 +55,18 @@ describe('POST /groups/:groupId/quests/invite/:questKey', () => {
|
|||||||
await member.update(userQuestUpdate);
|
await member.update(userQuestUpdate);
|
||||||
await questingGroup.update({'quest.key': PET_QUEST});
|
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 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.key).to.be.null;
|
||||||
expect(userWithRejectInvitation.party.quest.RSVPNeeded).to.be.false;
|
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,8 +17,6 @@ import { removeFromArray } from '../../libs/api-v3/collectionManipulators';
|
|||||||
import * as firebase from '../../libs/api-v3/firebase';
|
import * as firebase from '../../libs/api-v3/firebase';
|
||||||
import { sendTxn as sendTxnEmail } from '../../libs/api-v3/email';
|
import { sendTxn as sendTxnEmail } from '../../libs/api-v3/email';
|
||||||
import { encrypt } from '../../libs/api-v3/encryption';
|
import { encrypt } from '../../libs/api-v3/encryption';
|
||||||
import { quests as questScrolls } from '../../../../common/script/content';
|
|
||||||
import { mockAnalyticsService } from '../../libs/api-v3/analyticsService';
|
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
|
|
||||||
@@ -618,99 +616,4 @@ api.inviteToGroup = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
<<<<<<< e3c7d2834e6e5fa024afb71032c21177ca4124a7
|
|
||||||
=======
|
|
||||||
/**
|
|
||||||
* @api {post} /groups/:groupId/quests/invite Invite users to a quest
|
|
||||||
* @apiVersion 3.0.0
|
|
||||||
* @apiName InviteToQuest
|
|
||||||
* @apiGroup Group
|
|
||||||
*
|
|
||||||
* @apiParam {string} groupId The group _id (or 'party')
|
|
||||||
*
|
|
||||||
* @apiSuccess {Object} Quest Object
|
|
||||||
*/
|
|
||||||
api.inviteToQuest = {
|
|
||||||
method: 'POST',
|
|
||||||
url: '/groups/:groupId/quests/invite/:questKey',
|
|
||||||
middlewares: [authWithHeaders(), cron],
|
|
||||||
async handler (req, res) {
|
|
||||||
let user = res.locals.user;
|
|
||||||
let questKey = req.params.questKey;
|
|
||||||
let quest = questScrolls[questKey];
|
|
||||||
|
|
||||||
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
|
||||||
|
|
||||||
let validationErrors = req.validationErrors();
|
|
||||||
if (validationErrors) throw validationErrors;
|
|
||||||
|
|
||||||
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 (user.stats.lvl < quest.lvl) throw new NotAuthorized(res.t('questLevelTooHigh', { level: quest.lvl }));
|
|
||||||
if (group.quest.key) throw new NotAuthorized(res.t('questAlreadyUnderway'));
|
|
||||||
|
|
||||||
// TODO Logic for quest invite and send back quest object
|
|
||||||
res.respond(200, {});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @api {post} /groups/:groupId/quests/reject Reject a quest
|
|
||||||
* @apiVersion 3.0.0
|
|
||||||
* @apiName RejectQuest
|
|
||||||
* @apiGroup Group
|
|
||||||
*
|
|
||||||
* @apiParam {string} groupId The group _id (or 'party')
|
|
||||||
* @apiParam {string} questKey The quest _id
|
|
||||||
*
|
|
||||||
* @apiSuccess {Object} Quest Object
|
|
||||||
*/
|
|
||||||
api.rejectQuest = {
|
|
||||||
method: 'POST',
|
|
||||||
url: '/groups/:groupId/quests/reject/:questKey',
|
|
||||||
middlewares: [authWithHeaders(), cron],
|
|
||||||
async handler (req, res) {
|
|
||||||
let user = res.locals.user;
|
|
||||||
let questKey = req.params.questKey;
|
|
||||||
let quest = questScrolls[questKey];
|
|
||||||
|
|
||||||
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
|
||||||
|
|
||||||
let validationErrors = req.validationErrors();
|
|
||||||
if (validationErrors) throw validationErrors;
|
|
||||||
|
|
||||||
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 = {
|
|
||||||
category: 'behavior',
|
|
||||||
owner: false,
|
|
||||||
response: 'reject',
|
|
||||||
gaLabel: 'reject',
|
|
||||||
questName: group.quest.key,
|
|
||||||
uuid: user._id,
|
|
||||||
};
|
|
||||||
mockAnalyticsService.track('quest', analyticsData);
|
|
||||||
|
|
||||||
// @TODO: Are we tracking members this way?
|
|
||||||
// group.quest.members[user._id] = false;
|
|
||||||
|
|
||||||
user.party.quest.RSVPNeeded = false;
|
|
||||||
user.party.quest.key = null;
|
|
||||||
await user.save();
|
|
||||||
|
|
||||||
// questStart(req,res,next);
|
|
||||||
|
|
||||||
res.respond(200, {});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
>>>>>>> Added quest reject route and intial tests
|
|
||||||
export default api;
|
export default api;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import {
|
|||||||
NotAuthorized,
|
NotAuthorized,
|
||||||
} from '../../libs/api-v3/errors';
|
} from '../../libs/api-v3/errors';
|
||||||
import { quests as questScrolls } from '../../../../common/script/content';
|
import { quests as questScrolls } from '../../../../common/script/content';
|
||||||
|
import { track } from '../../libs/api-v3/analyticsService';
|
||||||
|
import Q from 'q';
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
|
|
||||||
@@ -65,4 +67,58 @@ api.inviteToQuest = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /groups/:groupId/quests/reject Reject a quest
|
||||||
|
* @apiVersion 3.0.0
|
||||||
|
* @apiName RejectQuest
|
||||||
|
* @apiGroup Group
|
||||||
|
*
|
||||||
|
* @apiParam {string} groupId The group _id (or 'party')
|
||||||
|
* @apiParam {string} questKey The quest _id
|
||||||
|
*
|
||||||
|
* @apiSuccess {Object} Quest Object
|
||||||
|
*/
|
||||||
|
api.rejectQuest = {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/groups/:groupId/quests/reject',
|
||||||
|
middlewares: [authWithHeaders(), cron],
|
||||||
|
async handler (req, res) {
|
||||||
|
let user = res.locals.user;
|
||||||
|
|
||||||
|
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
||||||
|
|
||||||
|
let validationErrors = req.validationErrors();
|
||||||
|
if (validationErrors) throw validationErrors;
|
||||||
|
|
||||||
|
let group = await Group.getGroup({user, groupId: req.params.groupId, fields: 'type quest'});
|
||||||
|
if (!group) throw new NotFound(res.t('groupNotFound'));
|
||||||
|
if (!group.quest.key) throw new NotFound(res.t('questInvitationDoesNotExist'));
|
||||||
|
|
||||||
|
let analyticsData = {
|
||||||
|
category: 'behavior',
|
||||||
|
owner: false,
|
||||||
|
response: 'reject',
|
||||||
|
gaLabel: 'reject',
|
||||||
|
questName: group.quest.key,
|
||||||
|
uuid: user._id,
|
||||||
|
};
|
||||||
|
track('quest', analyticsData);
|
||||||
|
|
||||||
|
group.quest.members[user._id] = false;
|
||||||
|
group.markModified('quest.members');
|
||||||
|
|
||||||
|
user.party.quest.RSVPNeeded = false;
|
||||||
|
user.party.quest.key = null;
|
||||||
|
|
||||||
|
let [savedGroup] = await Q.all([
|
||||||
|
group.save(),
|
||||||
|
user.save(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// questStart(req,res,next);
|
||||||
|
|
||||||
|
res.respond(200, savedGroup.quest);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default api;
|
export default api;
|
||||||
|
|||||||
Reference in New Issue
Block a user