mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
wip(shared): port sleep op
This commit is contained in:
@@ -99,9 +99,11 @@ api.count = count;
|
||||
|
||||
// TODO As ops and fns are ported, exported them through the api object
|
||||
import scoreTask from './ops/scoreTask';
|
||||
import sleep from './ops/sleep';
|
||||
|
||||
api.ops = {
|
||||
scoreTask,
|
||||
sleep,
|
||||
};
|
||||
api.fns = {};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = function(user, req, cb) {
|
||||
module.exports = function sleep (user) {
|
||||
user.preferences.sleep = !user.preferences.sleep;
|
||||
return typeof cb === "function" ? cb(null, {}) : void 0;
|
||||
return user.preferences.sleep;
|
||||
};
|
||||
|
||||
@@ -106,8 +106,8 @@
|
||||
"test:api-v3:integration": "gulp test:api-v3:integration",
|
||||
"test:api-v3:integration:separate-server": "gulp test:api-v3:integration:separate-server",
|
||||
"test:api-legacy": "istanbul cover -i \"website/src/**\" --dir coverage/api ./node_modules/mocha/bin/_mocha test/api-legacy",
|
||||
"test:common": "mocha test/common",
|
||||
"test:content": "mocha test/content",
|
||||
"test:common": "mocha test/common --recursive",
|
||||
"test:content": "mocha test/content --recursive",
|
||||
"test:karma": "karma start --single-run",
|
||||
"test:karma:watch": "karma start",
|
||||
"test:prepare:webdriver": "webdriver-manager update",
|
||||
|
||||
@@ -51,7 +51,6 @@ const COMMON_FILES = [
|
||||
'!./common/script/ops/reset.js',
|
||||
'!./common/script/ops/revive.js',
|
||||
'!./common/script/ops/sell.js',
|
||||
'!./common/script/ops/sleep.js',
|
||||
'!./common/script/ops/sortTag.js',
|
||||
'!./common/script/ops/sortTask.js',
|
||||
'!./common/script/ops/unlock.js',
|
||||
|
||||
@@ -104,7 +104,7 @@ gulp.task('test:common:clean', (cb) => {
|
||||
});
|
||||
|
||||
gulp.task('test:common:watch', ['test:common:clean'], () => {
|
||||
gulp.watch(['common/script/**', 'test/common/**'], ['test:common:clean']);
|
||||
gulp.watch(['common/script/**/*', 'test/common/**/*'], ['test:common:clean']);
|
||||
});
|
||||
|
||||
gulp.task('test:common:safe', ['test:prepare:build'], (cb) => {
|
||||
|
||||
18
test/common/ops/sleep.js
Normal file
18
test/common/ops/sleep.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import sleep from '../../../common/script/ops/sleep';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
|
||||
describe('shared.ops.sleep', () => {
|
||||
it('changes user.preferences.sleep and returns the new value', () => {
|
||||
let user = generateUser();
|
||||
|
||||
let res = sleep(user);
|
||||
expect(res).to.equal(true);
|
||||
expect(user.preferences.sleep).to.equal(true);
|
||||
|
||||
let res2 = sleep(user);
|
||||
expect(res2).to.equal(false);
|
||||
expect(user.preferences.sleep).to.equal(false);
|
||||
});
|
||||
});
|
||||
@@ -13,6 +13,8 @@ import Q from 'q';
|
||||
import _ from 'lodash';
|
||||
import * as passwordUtils from '../../libs/api-v3/password';
|
||||
|
||||
const sleep = common.ops.sleep;
|
||||
|
||||
let api = {};
|
||||
|
||||
/**
|
||||
@@ -277,4 +279,27 @@ api.castSpell = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {post} /user/sleep Put the user in the inn.
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName UserSleep
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiSuccess {Object} Will return an object with the new `user.preferences.sleep` value. Example `{preferences: {sleep: true}}`
|
||||
*/
|
||||
api.sleep = {
|
||||
method: 'POST',
|
||||
middlewares: [authWithHeaders(), cron],
|
||||
url: '/user/sleep',
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
let sleepVal = sleep(user);
|
||||
return res.respond(200, {
|
||||
preferences: {
|
||||
sleep: sleepVal,
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
|
||||
Reference in New Issue
Block a user