mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
feat: Separate out update-user into set-cron and make-admin debug routes
This commit is contained in:
35
test/api/v3/integration/debug/POST-debug_make-admin.test.js
Normal file
35
test/api/v3/integration/debug/POST-debug_make-admin.test.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import nconf from 'nconf';
|
||||||
|
import {
|
||||||
|
generateUser,
|
||||||
|
} from '../../../../helpers/api-v3-integration.helper';
|
||||||
|
|
||||||
|
describe('POST /debug/make-admin', () => {
|
||||||
|
let user;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
user = await generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
nconf.set('IS_PROD', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('makes user an admine', async () => {
|
||||||
|
await user.post('/debug/make-admin');
|
||||||
|
|
||||||
|
await user.sync();
|
||||||
|
|
||||||
|
expect(user.contributor.admin).to.eql(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns error when not in production mode', async () => {
|
||||||
|
nconf.set('IS_PROD', true);
|
||||||
|
|
||||||
|
await expect(user.post('/debug/make-admin'))
|
||||||
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
code: 404,
|
||||||
|
error: 'NotFound',
|
||||||
|
message: 'Not found.',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -3,47 +3,33 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
} from '../../../../helpers/api-v3-integration.helper';
|
} from '../../../../helpers/api-v3-integration.helper';
|
||||||
|
|
||||||
describe('POST /debug/update-user', () => {
|
describe('POST /debug/set-cron', () => {
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
user = await generateUser();
|
user = await generateUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
afterEach(() => {
|
||||||
nconf.set('IS_PROD', false);
|
nconf.set('IS_PROD', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('sets protected values', async () => {
|
it('sets last cron', async () => {
|
||||||
let newCron = new Date(2015, 11, 20);
|
let newCron = new Date(2015, 11, 20);
|
||||||
|
|
||||||
await user.post('/debug/update-user', {
|
await user.post('/debug/set-cron', {
|
||||||
balance: 100,
|
|
||||||
lastCron: newCron,
|
lastCron: newCron,
|
||||||
});
|
});
|
||||||
|
|
||||||
await user.sync();
|
await user.sync();
|
||||||
|
|
||||||
expect(user.lastCron).to.eql(newCron);
|
expect(user.lastCron).to.eql(newCron);
|
||||||
expect(user.balance).to.eql(100);
|
|
||||||
});
|
|
||||||
|
|
||||||
xit('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 () => {
|
it('returns error when not in production mode', async () => {
|
||||||
nconf.set('IS_PROD', true);
|
nconf.set('IS_PROD', true);
|
||||||
|
|
||||||
await expect(user.post('/debug/update-user'))
|
await expect(user.post('/debug/set-cron'))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotFound',
|
||||||
@@ -259,7 +259,7 @@ angular.module('habitrpg')
|
|||||||
|
|
||||||
$http({
|
$http({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: 'api/v3/debug/update-user',
|
url: 'api/v3/debug/set-cron',
|
||||||
data: {
|
data: {
|
||||||
lastCron: date
|
lastCron: date
|
||||||
}
|
}
|
||||||
@@ -272,10 +272,7 @@ angular.module('habitrpg')
|
|||||||
makeAdmin: function () {
|
makeAdmin: function () {
|
||||||
$http({
|
$http({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: 'api/v3/debug/update-user',
|
url: 'api/v3/debug/make-admin'
|
||||||
data: {
|
|
||||||
'contributor.admin': true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
Notification.text('You are now an admin! Go to the Hall of Heroes to change your contributor level.');
|
Notification.text('You are now an admin! Go to the Hall of Heroes to change your contributor level.');
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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 = {};
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ api.addHourglass = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} /api/v3/debug/set-property Sets properties on user, even protected fields
|
* @api {post} /api/v3/debug/set-cron Sets lastCron for user
|
||||||
* @apiDescription Only available in development mode.
|
* @apiDescription Only available in development mode.
|
||||||
* @apiVersion 3.0.0
|
* @apiVersion 3.0.0
|
||||||
* @apiName setCron
|
* @apiName setCron
|
||||||
@@ -61,21 +60,44 @@ api.addHourglass = {
|
|||||||
*
|
*
|
||||||
* @apiSuccess {Object} data An empty Object
|
* @apiSuccess {Object} data An empty Object
|
||||||
*/
|
*/
|
||||||
// api.setCron = {
|
api.setCron = {
|
||||||
// method: 'POST',
|
method: 'POST',
|
||||||
// url: '/debug/update-user',
|
url: '/debug/set-cron',
|
||||||
// middlewares: [ensureDevelpmentMode, authWithHeaders()],
|
middlewares: [ensureDevelpmentMode, authWithHeaders()],
|
||||||
// async handler (req, res) {
|
async handler (req, res) {
|
||||||
// let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
//
|
let cron = req.body.lastCron;
|
||||||
// _.each(req.body, (value, key) => {
|
|
||||||
// _.set(user, key, value);
|
user.lastCron = cron;
|
||||||
// });
|
|
||||||
//
|
await user.save();
|
||||||
// await user.save();
|
|
||||||
//
|
res.respond(200, {});
|
||||||
// res.respond(200, {});
|
},
|
||||||
// },
|
};
|
||||||
// };
|
|
||||||
|
/**
|
||||||
|
* @api {post} /api/v3/debug/make-admin Sets contributor.admin to true
|
||||||
|
* @apiDescription Only available in development mode.
|
||||||
|
* @apiVersion 3.0.0
|
||||||
|
* @apiName setCron
|
||||||
|
* @apiGroup Development
|
||||||
|
*
|
||||||
|
* @apiSuccess {Object} data An empty Object
|
||||||
|
*/
|
||||||
|
api.makeAdmin = {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/debug/make-admin',
|
||||||
|
middlewares: [ensureDevelpmentMode, authWithHeaders()],
|
||||||
|
async handler (req, res) {
|
||||||
|
let user = res.locals.user;
|
||||||
|
|
||||||
|
user.contributor.admin = true;
|
||||||
|
|
||||||
|
await user.save();
|
||||||
|
|
||||||
|
res.respond(200, {});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = api;
|
module.exports = api;
|
||||||
|
|||||||
Reference in New Issue
Block a user