mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
fix: Fix quest progress button
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
import nconf from 'nconf';
|
||||||
|
import {
|
||||||
|
generateUser,
|
||||||
|
} from '../../../../helpers/api-v3-integration.helper';
|
||||||
|
|
||||||
|
describe('POST /debug/quest-progress', () => {
|
||||||
|
let user;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
user = await generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
nconf.set('IS_PROD', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('errors if user is not on a quest', async () => {
|
||||||
|
await expect(user.post('/debug/quest-progress'))
|
||||||
|
.to.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: 'User is not on a valid quest.',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('increases boss quest progress by 1000', async () => {
|
||||||
|
await user.update({
|
||||||
|
'party.quest.key': 'whale',
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.post('/debug/quest-progress');
|
||||||
|
|
||||||
|
await user.sync();
|
||||||
|
|
||||||
|
expect(user.party.quest.progress.up).to.eql(1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('increases collection quest progress by 300 items', async () => {
|
||||||
|
await user.update({
|
||||||
|
'party.quest.key': 'evilsanta2',
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.post('/debug/quest-progress');
|
||||||
|
|
||||||
|
await user.sync();
|
||||||
|
|
||||||
|
expect(user.party.quest.progress.collect).to.eql({
|
||||||
|
tracks: 300,
|
||||||
|
branches: 300,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns error when not in production mode', async () => {
|
||||||
|
nconf.set('IS_PROD', true);
|
||||||
|
|
||||||
|
await expect(user.post('/debug/quest-progress'))
|
||||||
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: 'Not found.',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -118,11 +118,15 @@ function($scope, $rootScope, User, $http, Notification, ApiUrl, Social) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.addBossQuestProgressUp = function(){
|
$scope.addQuestProgress = function(){
|
||||||
//@TODO: Route?
|
$http({
|
||||||
User.set({
|
method: "POST",
|
||||||
'party.quest.progress.up': User.user.party.quest.progress.up + 1000
|
url: 'api/v3/debug/quest-progress'
|
||||||
});
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
Notification.text('Quest progress increased');
|
||||||
|
User.sync();
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.makeAdmin = function () {
|
$scope.makeAdmin = function () {
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
||||||
import ensureDevelpmentMode from '../../middlewares/api-v3/ensureDevelpmentMode';
|
import ensureDevelpmentMode from '../../middlewares/api-v3/ensureDevelpmentMode';
|
||||||
|
import { BadRequest } from '../../libs/api-v3/errors';
|
||||||
|
import { content } from '../../../../common';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
|
|
||||||
@@ -141,4 +144,47 @@ api.modifyInventory = {
|
|||||||
res.respond(200, {});
|
res.respond(200, {});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /api/v3/debug/quest-progress Artificially accelerate quest progress
|
||||||
|
* @apiDescription Only available in development mode.
|
||||||
|
* @apiVersion 3.0.0
|
||||||
|
* @apiName questProgress
|
||||||
|
* @apiGroup Development
|
||||||
|
*
|
||||||
|
* @apiSuccess {Object} data An empty Object
|
||||||
|
*/
|
||||||
|
api.questProgress = {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/debug/quest-progress',
|
||||||
|
middlewares: [ensureDevelpmentMode, authWithHeaders()],
|
||||||
|
async handler (req, res) {
|
||||||
|
let user = res.locals.user;
|
||||||
|
let key = _.get(user, 'party.quest.key');
|
||||||
|
let quest = content.quests[key];
|
||||||
|
|
||||||
|
if (!quest) {
|
||||||
|
throw new BadRequest('User is not on a valid quest.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quest.boss) {
|
||||||
|
user.party.quest.progress.up += 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quest.collect) {
|
||||||
|
let collect = user.party.quest.progress.collect;
|
||||||
|
_.each(quest.collect, (details, item) => {
|
||||||
|
collect[item] = collect[item] || 0;
|
||||||
|
collect[item] += 300;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
user.markModified('party.quest.progress');
|
||||||
|
|
||||||
|
await user.save();
|
||||||
|
|
||||||
|
res.respond(200, {});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ footer.footer(ng-controller='FooterCtrl')
|
|||||||
a.btn.btn-default(ng-click='addMana()') +MP
|
a.btn.btn-default(ng-click='addMana()') +MP
|
||||||
a.btn.btn-default(ng-click='addLevelsAndGold()') +Exp +GP +MP
|
a.btn.btn-default(ng-click='addLevelsAndGold()') +Exp +GP +MP
|
||||||
a.btn.btn-default(ng-click='addOneLevel()') +1 Level
|
a.btn.btn-default(ng-click='addOneLevel()') +1 Level
|
||||||
a.btn.btn-default(ng-click='addBossQuestProgressUp()') +1000 Boss Quest Progress Up
|
a.btn.btn-default(ng-click='addQuestProgress()' tooltip="+1000 to boss quests. 300 items to collection quests") Quest Progress Up
|
||||||
// TODO Re-enable after v3 prod testing
|
// TODO Re-enable after v3 prod testing
|
||||||
// a.btn.btn-default(ng-click='makeAdmin()') Make Admin
|
// a.btn.btn-default(ng-click='makeAdmin()') Make Admin
|
||||||
a.btn.btn-default(ng-click='openModifyInventoryModal()') Modify Inventory
|
a.btn.btn-default(ng-click='openModifyInventoryModal()') Modify Inventory
|
||||||
|
|||||||
Reference in New Issue
Block a user