mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
Add rage button to debug menu (#15291)
* + Rage * tinkering * remove if statement wrapper and modify error message * add test cases * more work on test cases * adding contexts to test cases * test(debug): fix up tests * fix(lint): whisepate --------- Co-authored-by: Sabe Jones <sabe@habitica.com>
This commit is contained in:
73
test/api/v3/integration/debug/POST-debug_boss-rage.test.js
Normal file
73
test/api/v3/integration/debug/POST-debug_boss-rage.test.js
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import nconf from 'nconf';
|
||||||
|
import {
|
||||||
|
generateUser,
|
||||||
|
createAndPopulateGroup,
|
||||||
|
} from '../../../../helpers/api-integration/v3';
|
||||||
|
|
||||||
|
describe('POST /debug/boss-rage', () => {
|
||||||
|
let user;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
user = await generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
nconfStub = sandbox.stub(nconf, 'get');
|
||||||
|
nconfStub.withArgs('DEBUG_ENABLED').returns(true);
|
||||||
|
nconfStub.withArgs('BASE_URL').returns('https://example.com');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
nconfStub.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('errors if user is not in a party', async () => {
|
||||||
|
await expect(user.post('/debug/boss-rage'))
|
||||||
|
.to.eventually.be.rejected.and.deep.equal({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: 'User not in a party.',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns error when not in production mode', async () => {
|
||||||
|
nconfStub.withArgs('DEBUG_ENABLED').returns(false);
|
||||||
|
|
||||||
|
await expect(user.post('/debug/boss-rage'))
|
||||||
|
.to.eventually.be.rejected.and.deep.equal({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: 'Not found.',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
context('user is in a party', async () => {
|
||||||
|
let party;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const { group, groupLeader } = await createAndPopulateGroup({
|
||||||
|
groupDetails: {
|
||||||
|
name: 'Test Party',
|
||||||
|
type: 'party',
|
||||||
|
},
|
||||||
|
members: 2,
|
||||||
|
});
|
||||||
|
party = group;
|
||||||
|
user = groupLeader;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('increases boss rage to 50', async () => {
|
||||||
|
await user.post('/debug/boss-rage');
|
||||||
|
await party.sync();
|
||||||
|
expect(party.quest.progress.rage).to.eql(50);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('increases boss rage to 100', async () => {
|
||||||
|
await user.post('/debug/boss-rage');
|
||||||
|
await user.post('/debug/boss-rage');
|
||||||
|
await party.sync();
|
||||||
|
expect(party.quest.progress.rage).to.eql(100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -402,6 +402,10 @@
|
|||||||
tooltip="+1000 to boss quests. 300 items to collection quests"
|
tooltip="+1000 to boss quests. 300 items to collection quests"
|
||||||
@click="addQuestProgress()"
|
@click="addQuestProgress()"
|
||||||
>Quest Progress Up</a>
|
>Quest Progress Up</a>
|
||||||
|
<a
|
||||||
|
class="btn btn-secondary"
|
||||||
|
@click="bossRage()"
|
||||||
|
>+ Boss Rage 😡</a>
|
||||||
<a
|
<a
|
||||||
class="btn btn-secondary"
|
class="btn btn-secondary"
|
||||||
@click="makeAdmin()"
|
@click="makeAdmin()"
|
||||||
@@ -965,6 +969,10 @@ export default {
|
|||||||
// @TODO: Notification.text('Quest progress increased');
|
// @TODO: Notification.text('Quest progress increased');
|
||||||
// @TODO: User.sync();
|
// @TODO: User.sync();
|
||||||
},
|
},
|
||||||
|
async bossRage () {
|
||||||
|
await axios.post('/api/v4/debug/boss-rage');
|
||||||
|
},
|
||||||
|
|
||||||
async makeAdmin () {
|
async makeAdmin () {
|
||||||
await axios.post('/api/v4/debug/make-admin');
|
await axios.post('/api/v4/debug/make-admin');
|
||||||
// @TODO: Notification.text('You are now an admin!
|
// @TODO: Notification.text('You are now an admin!
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ import ensureDevelopmentMode from '../../middlewares/ensureDevelopmentMode';
|
|||||||
import ensureTimeTravelMode from '../../middlewares/ensureTimeTravelMode';
|
import ensureTimeTravelMode from '../../middlewares/ensureTimeTravelMode';
|
||||||
import { BadRequest } from '../../libs/errors';
|
import { BadRequest } from '../../libs/errors';
|
||||||
import common from '../../../common';
|
import common from '../../../common';
|
||||||
|
import {
|
||||||
|
model as Group,
|
||||||
|
// basicFields as basicGroupFields,
|
||||||
|
} from '../../models/group';
|
||||||
|
|
||||||
const { content } = common;
|
const { content } = common;
|
||||||
|
|
||||||
@@ -204,6 +208,41 @@ api.questProgress = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /api/v3/debug/boss-rage Artificially trigger boss rage bar
|
||||||
|
* @apiName bossRage
|
||||||
|
* @apiGroup Development
|
||||||
|
* @apiPermission Developers
|
||||||
|
*
|
||||||
|
* @apiSuccess {Object} data An empty Object
|
||||||
|
*/
|
||||||
|
|
||||||
|
api.bossRage = {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/debug/boss-rage',
|
||||||
|
middlewares: [ensureDevelopmentMode, authWithHeaders()],
|
||||||
|
async handler (req, res) {
|
||||||
|
const { user } = res.locals;
|
||||||
|
const party = await Group.getGroup({
|
||||||
|
user,
|
||||||
|
groupId: 'party',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!party) {
|
||||||
|
throw new BadRequest('User not in a party.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!party.quest.progress.rage) party.quest.progress.rage = 0;
|
||||||
|
party.quest.progress.rage += 50;
|
||||||
|
|
||||||
|
party.markModified('party.quest.progress.rage');
|
||||||
|
|
||||||
|
await party.save();
|
||||||
|
|
||||||
|
res.respond(200, {});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let clock;
|
let clock;
|
||||||
|
|
||||||
function fakeClock () {
|
function fakeClock () {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
} from '../libs/errors';
|
} from '../libs/errors';
|
||||||
|
|
||||||
export default function ensureDevelopmentMode (req, res, next) {
|
export default function ensureDevelopmentMode (req, res, next) {
|
||||||
console.log(nconf.get('DEBUG_ENABLED'), nconf.get('BASE_URL'));
|
|
||||||
if (nconf.get('DEBUG_ENABLED') && nconf.get('BASE_URL') !== 'https://habitica.com') {
|
if (nconf.get('DEBUG_ENABLED') && nconf.get('BASE_URL') !== 'https://habitica.com') {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user