Files
habitica/test/api/v3/integration/user/POST-user_custom-day-start.test.js
Phillip Thelen f8d315ff6e Upgrade to mongoose 7 (#14971)
* remove some unused dependencies

* update mongoose version

* make common tests pass

* Make unit tests pass

* make api v3 integration tests pass

* fix lint issues

* fix issue with package-lock

* fix(lint): we don't need no .js

* fix(lint): update to latest config-habitrpg

* chore(npm): update package locks

* fix(test): replace deprecated fn

* chore(package): update eslint-habitrpg again

* fix(lint): server linting

* fix(lint): client linting

* fix(client): correct mangled common imports

* chore(npm): update package-locks

* fix(lint): punctuation, module

---------

Co-authored-by: SabreCat <sabrecat@gmail.com>
Co-authored-by: SabreCat <sabe@habitica.com>
2024-01-16 15:18:47 -06:00

48 lines
1.3 KiB
JavaScript

import moment from 'moment';
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
let user;
const 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 () => {
const oldCron = moment().subtract(7, 'hours');
await user.updateOne({ 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 () => {
const { 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;
});
});