mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
@@ -47,6 +47,7 @@
|
|||||||
"customDayStart": "Custom Day Start",
|
"customDayStart": "Custom Day Start",
|
||||||
"changeCustomDayStart": "Change Custom Day Start?",
|
"changeCustomDayStart": "Change Custom Day Start?",
|
||||||
"sureChangeCustomDayStart": "Are you sure you want to change your custom day start?",
|
"sureChangeCustomDayStart": "Are you sure you want to change your custom day start?",
|
||||||
|
"customDayStartHasChanged": "Your custom day start has changed.",
|
||||||
"nextCron": "Your Dailies will next reset the first time you use Habitica after <%= time %>. Make sure you have completed your Dailies before this time!",
|
"nextCron": "Your Dailies will next reset the first time you use Habitica after <%= time %>. Make sure you have completed your Dailies before this time!",
|
||||||
"customDayStartInfo1": "Habitica defaults to check and reset your Dailies at midnight in your own time zone each day. You can customize that time here.",
|
"customDayStartInfo1": "Habitica defaults to check and reset your Dailies at midnight in your own time zone each day. You can customize that time here.",
|
||||||
"misc": "Misc",
|
"misc": "Misc",
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import {
|
|
||||||
generateUser,
|
|
||||||
} from '../../../../helpers/api-integration/v3';
|
|
||||||
|
|
||||||
let user;
|
|
||||||
let endpoint = '/user/set-custom-day-start';
|
|
||||||
|
|
||||||
describe('POST /user/set-custom-day-start', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
user = await generateUser();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('update user.preferences.dayStart', async () => {
|
|
||||||
expect(user.preferences.dayStart).to.eql(0);
|
|
||||||
await user.post(endpoint, { dayStart: 1 });
|
|
||||||
await user.sync();
|
|
||||||
expect(user.preferences.dayStart).to.eql(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import moment from 'moment';
|
||||||
|
import {
|
||||||
|
generateUser,
|
||||||
|
translate as t,
|
||||||
|
} from '../../../../helpers/api-integration/v3';
|
||||||
|
|
||||||
|
let user;
|
||||||
|
let endpoint = '/user/custom-day-start';
|
||||||
|
|
||||||
|
describe('POST /user/custom-day-start', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
user = await generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates user.preferences.dayStart', async () => {
|
||||||
|
expect(user.preferences.dayStart).to.eql(0);
|
||||||
|
|
||||||
|
await user.post(endpoint, { dayStart: 1 });
|
||||||
|
await user.sync();
|
||||||
|
|
||||||
|
expect(user.preferences.dayStart).to.eql(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets lastCron to the current time to prevent an unexpected cron', async () => {
|
||||||
|
let oldCron = moment().subtract(7, 'hours');
|
||||||
|
|
||||||
|
await user.update({lastCron: oldCron});
|
||||||
|
await user.post(endpoint, { dayStart: 1 });
|
||||||
|
await user.sync();
|
||||||
|
|
||||||
|
expect(user.lastCron.valueOf()).to.be.gt(oldCron.valueOf());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns a confirmation message', async () => {
|
||||||
|
let {message} = await user.post(endpoint, { dayStart: 1 });
|
||||||
|
|
||||||
|
expect(message).to.eql(t('customDayStartHasChanged'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('errors if invalid value is passed', async () => {
|
||||||
|
await expect(user.post(endpoint, { dayStart: 'foo' }))
|
||||||
|
.to.eventually.be.rejected;
|
||||||
|
|
||||||
|
await expect(user.post(endpoint, { dayStart: 24}))
|
||||||
|
.to.eventually.be.rejected;
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -17,7 +17,7 @@ describe('Settings Controller', function () {
|
|||||||
releasePets: sandbox.stub(),
|
releasePets: sandbox.stub(),
|
||||||
releaseMounts: sandbox.stub(),
|
releaseMounts: sandbox.stub(),
|
||||||
releaseBoth: sandbox.stub(),
|
releaseBoth: sandbox.stub(),
|
||||||
setLastCron: sandbox.stub(),
|
setCustomDayStart: sandbox.stub(),
|
||||||
user: user
|
user: user
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,19 +87,11 @@ describe('Settings Controller', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#saveDayStart', function () {
|
describe('#saveDayStart', function () {
|
||||||
|
it('updates user\'s custom day start', function () {
|
||||||
it('updates user\'s custom day start and last cron', function () {
|
|
||||||
var fakeCurrentTime = new Date(2013, 3, 1, 8, 12).getTime();
|
|
||||||
var expectedTime = fakeCurrentTime;
|
|
||||||
sandbox.useFakeTimers(fakeCurrentTime);
|
|
||||||
scope.dayStart = 5;
|
scope.dayStart = 5;
|
||||||
scope.saveDayStart();
|
scope.saveDayStart();
|
||||||
|
|
||||||
expect(User.set).to.be.calledOnce;
|
expect(User.setCustomDayStart).to.be.calledWith(5);
|
||||||
expect(User.set).to.be.calledWith({
|
|
||||||
'preferences.dayStart': 5,
|
|
||||||
});
|
|
||||||
expect(User.setLastCron).to.be.calledWith(expectedTime);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -313,13 +313,14 @@ angular.module('habitrpg')
|
|||||||
setCustomDayStart: function (dayStart) {
|
setCustomDayStart: function (dayStart) {
|
||||||
$http({
|
$http({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: 'api/v3/user/set-custom-day-start',
|
url: 'api/v3/user/custom-day-start',
|
||||||
data: {
|
data: {
|
||||||
dayStart: dayStart
|
dayStart: dayStart
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
Notification.text('Day start updated. Remember to refresh');
|
Notification.text(response.data.data.message);
|
||||||
|
sync();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1311,26 +1311,29 @@ api.userReset = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} /api/v3/user/set-custom-day-start Sets preferences.dayStart for user
|
* @api {post} /api/v3/user/custom-day-start Sets preferences.dayStart for user
|
||||||
* @apiVersion 3.0.0
|
* @apiVersion 3.0.0
|
||||||
* @apiName UserSetCustomDayStart
|
* @apiName setCustomDayStart
|
||||||
* @apiGroup User
|
* @apiGroup User
|
||||||
*
|
*
|
||||||
* @apiSuccess {Object} data An empty Object
|
* @apiSuccess {Object} data An empty Object
|
||||||
*/
|
*/
|
||||||
api.userSetCustomDayStart = {
|
api.setCustomDayStart = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders()],
|
||||||
url: '/user/set-custom-day-start',
|
url: '/user/custom-day-start',
|
||||||
async handler (req, res) {
|
async handler (req, res) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
let dayStart = req.body.dayStart;
|
let dayStart = req.body.dayStart;
|
||||||
|
|
||||||
user.preferences.dayStart = dayStart;
|
user.preferences.dayStart = dayStart;
|
||||||
|
user.lastCron = new Date();
|
||||||
|
|
||||||
await user.save();
|
await user.save();
|
||||||
|
|
||||||
res.respond(200, {});
|
res.respond(200, {
|
||||||
|
message: res.t('customDayStartHasChanged'),
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user