mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
test fixes
This commit is contained in:
@@ -45,7 +45,7 @@ function runInChildProcess (command, options = {}, envVariables = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function integrationTestCommand (testDir) {
|
function integrationTestCommand (testDir) {
|
||||||
return `nyc --no-clean mocha ${testDir} --recursive --require ./test/helpers/start-server`;
|
return `nyc --silent --no-clean mocha ${testDir} --recursive --require ./test/helpers/start-server`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test task definitions */
|
/* Test task definitions */
|
||||||
|
|||||||
@@ -5,30 +5,36 @@ import {
|
|||||||
|
|
||||||
describe('GET /debug/time-travel-time', () => {
|
describe('GET /debug/time-travel-time', () => {
|
||||||
let user;
|
let user;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
user = await generateUser({ permissions: { fullAccess: true } });
|
user = await generateUser({ permissions: { fullAccess: true } });
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
beforeEach(() => {
|
||||||
nconf.set('TIME_TRAVEL_ENABLED', false);
|
nconfStub = sandbox.stub(nconf, 'get');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
nconfStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the shifted time', async () => {
|
it('returns the shifted time', async () => {
|
||||||
nconf.set('TIME_TRAVEL_ENABLED', true);
|
nconfStub.withArgs('TIME_TRAVEL_ENABLED').returns(true);
|
||||||
const result = await user.get('/debug/time-travel-time');
|
const result = await user.get('/debug/time-travel-time');
|
||||||
expect(result.time).to.exist;
|
expect(result.time).to.exist;
|
||||||
await user.post('/debug/jump-time', { disable: true });
|
await user.post('/debug/jump-time', { disable: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns shifted when the user is not an admin', async () => {
|
it('returns shifted when the user is not an admin', async () => {
|
||||||
nconf.set('TIME_TRAVEL_ENABLED', true);
|
nconfStub.withArgs('TIME_TRAVEL_ENABLED').returns(true);
|
||||||
const regularUser = await generateUser();
|
const regularUser = await generateUser();
|
||||||
const result = await regularUser.get('/debug/time-travel-time');
|
const result = await regularUser.get('/debug/time-travel-time');
|
||||||
expect(result.time).to.exist;
|
expect(result.time).to.exist;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in time travel mode', async () => {
|
it('returns error when not in time travel mode', async () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('TIME_TRAVEL_ENABLED').returns(false);
|
nconfStub.withArgs('TIME_TRAVEL_ENABLED').returns(false);
|
||||||
|
|
||||||
await expect(user.get('/debug/time-travel-time'))
|
await expect(user.get('/debug/time-travel-time'))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
|||||||
@@ -5,16 +5,23 @@ import {
|
|||||||
|
|
||||||
describe('POST /debug/add-hourglass', () => {
|
describe('POST /debug/add-hourglass', () => {
|
||||||
let userToGetHourGlass;
|
let userToGetHourGlass;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
userToGetHourGlass = await generateUser();
|
userToGetHourGlass = await generateUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
beforeEach(() => {
|
||||||
nconf.set('IS_PROD', false);
|
nconfStub = sandbox.stub(nconf, 'get');
|
||||||
|
nconfStub.withArgs('BASE_URL').returns('https://example.com');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
nconfStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds Hourglass to the current user', async () => {
|
it('adds Hourglass to the current user', async () => {
|
||||||
|
nconfStub.withArgs('DEBUG_ENABLED').returns(true);
|
||||||
await userToGetHourGlass.post('/debug/add-hourglass');
|
await userToGetHourGlass.post('/debug/add-hourglass');
|
||||||
|
|
||||||
const userWithHourGlass = await userToGetHourGlass.get('/user');
|
const userWithHourGlass = await userToGetHourGlass.get('/user');
|
||||||
@@ -23,7 +30,7 @@ describe('POST /debug/add-hourglass', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in production mode', async () => {
|
it('returns error when not in production mode', async () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
|
nconfStub.withArgs('DEBUG_ENABLED').returns(false);
|
||||||
|
|
||||||
await expect(userToGetHourGlass.post('/debug/add-hourglass'))
|
await expect(userToGetHourGlass.post('/debug/add-hourglass'))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
|||||||
@@ -5,16 +5,23 @@ import {
|
|||||||
|
|
||||||
describe('POST /debug/add-ten-gems', () => {
|
describe('POST /debug/add-ten-gems', () => {
|
||||||
let userToGainTenGems;
|
let userToGainTenGems;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
userToGainTenGems = await generateUser();
|
userToGainTenGems = await generateUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
beforeEach(() => {
|
||||||
nconf.set('IS_PROD', false);
|
nconfStub = sandbox.stub(nconf, 'get');
|
||||||
|
nconfStub.withArgs('BASE_URL').returns('https://example.com');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
nconfStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds ten gems to the current user', async () => {
|
it('adds ten gems to the current user', async () => {
|
||||||
|
nconfStub.withArgs('DEBUG_ENABLED').returns(true);
|
||||||
await userToGainTenGems.post('/debug/add-ten-gems');
|
await userToGainTenGems.post('/debug/add-ten-gems');
|
||||||
|
|
||||||
const userWithTenGems = await userToGainTenGems.get('/user');
|
const userWithTenGems = await userToGainTenGems.get('/user');
|
||||||
@@ -23,7 +30,7 @@ describe('POST /debug/add-ten-gems', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in production mode', async () => {
|
it('returns error when not in production mode', async () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
|
nconfStub.withArgs('DEBUG_ENABLED').returns(false);
|
||||||
|
|
||||||
await expect(userToGainTenGems.post('/debug/add-ten-gems'))
|
await expect(userToGainTenGems.post('/debug/add-ten-gems'))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
describe('POST /debug/jump-time', () => {
|
describe('POST /debug/jump-time', () => {
|
||||||
let user;
|
let user;
|
||||||
let today;
|
let today;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
user = await generateUser({ permissions: { fullAccess: true } });
|
user = await generateUser({ permissions: { fullAccess: true } });
|
||||||
today = new Date();
|
today = new Date();
|
||||||
@@ -63,7 +65,7 @@ describe('POST /debug/jump-time', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in time travel mode', async () => {
|
it('returns error when not in time travel mode', async () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('TIME_TRAVEL_ENABLED').returns(false);
|
nconfStub.withArgs('TIME_TRAVEL_ENABLED').returns(false);
|
||||||
|
|
||||||
await expect(user.post('/debug/jump-time', { offsetDays: 1 }))
|
await expect(user.post('/debug/jump-time', { offsetDays: 1 }))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
|||||||
@@ -5,16 +5,23 @@ import {
|
|||||||
|
|
||||||
describe('POST /debug/make-admin', () => {
|
describe('POST /debug/make-admin', () => {
|
||||||
let user;
|
let user;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
user = await generateUser();
|
user = await generateUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
nconfStub = sandbox.stub(nconf, 'get');
|
||||||
|
nconfStub.withArgs('BASE_URL').returns('https://example.com');
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
nconf.set('IS_PROD', false);
|
nconfStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('makes user an admin', async () => {
|
it('makes user an admin', async () => {
|
||||||
|
nconfStub.withArgs('DEBUG_ENABLED').returns(true);
|
||||||
await user.post('/debug/make-admin');
|
await user.post('/debug/make-admin');
|
||||||
|
|
||||||
await user.sync();
|
await user.sync();
|
||||||
@@ -23,7 +30,7 @@ describe('POST /debug/make-admin', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in production mode', async () => {
|
it('returns error when not in production mode', async () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
|
nconfStub.withArgs('DEBUG_ENABLED').returns(false);
|
||||||
|
|
||||||
await expect(user.post('/debug/make-admin'))
|
await expect(user.post('/debug/make-admin'))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
describe('POST /debug/modify-inventory', () => {
|
describe('POST /debug/modify-inventory', () => {
|
||||||
let user; let
|
let user; let
|
||||||
originalItems;
|
originalItems;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
originalItems = {
|
originalItems = {
|
||||||
@@ -39,8 +40,14 @@ describe('POST /debug/modify-inventory', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
nconfStub = sandbox.stub(nconf, 'get');
|
||||||
|
nconfStub.withArgs('DEBUG_ENABLED').returns(true);
|
||||||
|
nconfStub.withArgs('BASE_URL').returns('https://example.com');
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
nconf.set('IS_PROD', false);
|
nconfStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets equipment', async () => {
|
it('sets equipment', async () => {
|
||||||
@@ -149,7 +156,7 @@ describe('POST /debug/modify-inventory', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in production mode', async () => {
|
it('returns error when not in production mode', async () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
|
nconfStub.withArgs('DEBUG_ENABLED').returns(false);
|
||||||
|
|
||||||
await expect(user.post('/debug/modify-inventory'))
|
await expect(user.post('/debug/modify-inventory'))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
|||||||
@@ -5,13 +5,20 @@ import {
|
|||||||
|
|
||||||
describe('POST /debug/quest-progress', () => {
|
describe('POST /debug/quest-progress', () => {
|
||||||
let user;
|
let user;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
user = await generateUser();
|
user = await generateUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
nconfStub = sandbox.stub(nconf, 'get');
|
||||||
|
nconfStub.withArgs('DEBUG_ENABLED').returns(true);
|
||||||
|
nconfStub.withArgs('BASE_URL').returns('https://example.com');
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
nconf.set('IS_PROD', false);
|
nconfStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('errors if user is not on a quest', async () => {
|
it('errors if user is not on a quest', async () => {
|
||||||
@@ -48,7 +55,7 @@ describe('POST /debug/quest-progress', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in production mode', async () => {
|
it('returns error when not in production mode', async () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
|
nconfStub.withArgs('DEBUG_ENABLED').returns(false);
|
||||||
|
|
||||||
await expect(user.post('/debug/quest-progress'))
|
await expect(user.post('/debug/quest-progress'))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
|||||||
@@ -5,13 +5,20 @@ import {
|
|||||||
|
|
||||||
describe('POST /debug/set-cron', () => {
|
describe('POST /debug/set-cron', () => {
|
||||||
let user;
|
let user;
|
||||||
|
let nconfStub;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
user = await generateUser();
|
user = await generateUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
nconfStub = sandbox.stub(nconf, 'get');
|
||||||
|
nconfStub.withArgs('DEBUG_ENABLED').returns(true);
|
||||||
|
nconfStub.withArgs('BASE_URL').returns('https://example.com');
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
nconf.set('IS_PROD', false);
|
nconfStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets last cron', async () => {
|
it('sets last cron', async () => {
|
||||||
@@ -27,7 +34,7 @@ describe('POST /debug/set-cron', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in production mode', async () => {
|
it('returns error when not in production mode', async () => {
|
||||||
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
|
nconfStub.withArgs('DEBUG_ENABLED').returns(false);
|
||||||
|
|
||||||
await expect(user.post('/debug/set-cron'))
|
await expect(user.post('/debug/set-cron'))
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
.eventually.be.rejected.and.to.deep.equal({
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
} from '../libs/errors';
|
} from '../libs/errors';
|
||||||
|
|
||||||
export default function ensureDevelopmentMode (req, res, next) {
|
export default function ensureDevelopmentMode (req, res, next) {
|
||||||
|
console.log(nconf.get('DEBUG_ENABLED'), nconf.get('BASE_URL'));
|
||||||
if (nconf.get('DEBUG_ENABLED') && nconf.get('BASE_URL') !== 'https://habitica.com') {
|
if (nconf.get('DEBUG_ENABLED') && nconf.get('BASE_URL') !== 'https://habitica.com') {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user