mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
feat: Create debug update user route
This commit is contained in:
53
test/api/v3/integration/debug/POST-debug_update-user.test.js
Normal file
53
test/api/v3/integration/debug/POST-debug_update-user.test.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import nconf from 'nconf';
|
||||||
|
import {
|
||||||
|
generateUser,
|
||||||
|
} from '../../../../helpers/api-v3-integration.helper';
|
||||||
|
|
||||||
|
describe('POST /debug/update-user', () => {
|
||||||
|
let user;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
user = await generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
nconf.set('IS_PROD', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets protected values', async () => {
|
||||||
|
let newCron = new Date(2015, 11, 20);
|
||||||
|
|
||||||
|
await user.post('/debug/update-user', {
|
||||||
|
balance: 100,
|
||||||
|
lastCron: newCron,
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.sync()
|
||||||
|
|
||||||
|
expect(user.lastCron).to.eql(newCron);
|
||||||
|
expect(user.balance).to.eql(100);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets nested values', async () => {
|
||||||
|
await user.post('/debug/update-user', {
|
||||||
|
'contributor.level': 9,
|
||||||
|
'purchased.txnCount': 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.sync()
|
||||||
|
|
||||||
|
expect(user.contributor.level).to.eql(9);
|
||||||
|
expect(user.purchased.txnCount).to.eql(100);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns error when not in production mode', async () => {
|
||||||
|
nconf.set('IS_PROD', true);
|
||||||
|
|
||||||
|
await expect(user.post('/debug/update-user'))
|
||||||
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: 'Not found.',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
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 _ from 'lodash';
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
|
|
||||||
@@ -51,4 +52,30 @@ api.addHourglass = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /api/v3/debug/set-property Sets properties on user, even protected fields
|
||||||
|
* @apiDescription Only available in development mode.
|
||||||
|
* @apiVersion 3.0.0
|
||||||
|
* @apiName setCron
|
||||||
|
* @apiGroup Development
|
||||||
|
*
|
||||||
|
* @apiSuccess {Object} data An empty Object
|
||||||
|
*/
|
||||||
|
api.setCron = {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/debug/update-user',
|
||||||
|
middlewares: [ensureDevelpmentMode, authWithHeaders()],
|
||||||
|
async handler (req, res) {
|
||||||
|
let user = res.locals.user;
|
||||||
|
|
||||||
|
_.each(req.body, (value, key) => {
|
||||||
|
_.set(user, key, value);
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.save();
|
||||||
|
|
||||||
|
res.respond(200, {});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = api;
|
module.exports = api;
|
||||||
|
|||||||
Reference in New Issue
Block a user