habitica/test/api/v3/integration/debug/GET-debug-timeTravelTime.test.js

47 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2024-02-28 16:54:42 +00:00
import nconf from 'nconf';
import {
generateUser,
} from '../../../../helpers/api-integration/v3';
describe('GET /debug/time-travel-time', () => {
let user;
2024-06-19 16:01:27 +00:00
let nconfStub;
2024-02-28 16:54:42 +00:00
before(async () => {
user = await generateUser({ permissions: { fullAccess: true } });
});
2024-06-19 16:01:27 +00:00
beforeEach(() => {
nconfStub = sandbox.stub(nconf, 'get');
});
afterEach(() => {
nconfStub.restore();
2024-02-28 16:54:42 +00:00
});
it('returns the shifted time', async () => {
2024-06-19 16:01:27 +00:00
nconfStub.withArgs('TIME_TRAVEL_ENABLED').returns(true);
2024-02-28 16:54:42 +00:00
const result = await user.get('/debug/time-travel-time');
expect(result.time).to.exist;
await user.post('/debug/jump-time', { disable: true });
});
2024-04-26 11:44:51 +00:00
it('returns shifted when the user is not an admin', async () => {
2024-06-19 16:01:27 +00:00
nconfStub.withArgs('TIME_TRAVEL_ENABLED').returns(true);
2024-02-28 16:54:42 +00:00
const regularUser = await generateUser();
2024-04-26 11:44:51 +00:00
const result = await regularUser.get('/debug/time-travel-time');
expect(result.time).to.exist;
2024-02-28 16:54:42 +00:00
});
it('returns error when not in time travel mode', async () => {
2024-06-19 16:01:27 +00:00
nconfStub.withArgs('TIME_TRAVEL_ENABLED').returns(false);
2024-02-28 16:54:42 +00:00
await expect(user.get('/debug/time-travel-time'))
.eventually.be.rejected.and.to.deep.equal({
code: 404,
error: 'NotFound',
message: 'Not found.',
});
});
});