mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 13:17:24 +01:00
fix tests
This commit is contained in:
@@ -20,15 +20,11 @@ describe('GET /debug/time-travel-time', () => {
|
|||||||
await user.post('/debug/jump-time', { disable: true });
|
await user.post('/debug/jump-time', { disable: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when the user is not an admin', async () => {
|
it('returns shifted when the user is not an admin', async () => {
|
||||||
nconf.set('ENABLE_TIME_TRAVEL', true);
|
nconf.set('ENABLE_TIME_TRAVEL', true);
|
||||||
const regularUser = await generateUser();
|
const regularUser = await generateUser();
|
||||||
await expect(regularUser.get('/debug/time-travel-time'))
|
const result = await regularUser.get('/debug/time-travel-time');
|
||||||
.eventually.be.rejected.and.to.deep.equal({
|
expect(result.time).to.exist;
|
||||||
code: 400,
|
|
||||||
error: 'BadRequest',
|
|
||||||
message: 'You do not have permission to time travel.',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when not in time travel mode', async () => {
|
it('returns error when not in time travel mode', async () => {
|
||||||
|
|||||||
@@ -17,9 +17,5 @@ describe('GET /shops/backgrounds', () => {
|
|||||||
expect(shop.notes).to.eql(t('backgroundShop'));
|
expect(shop.notes).to.eql(t('backgroundShop'));
|
||||||
expect(shop.imageName).to.equal('background_shop');
|
expect(shop.imageName).to.equal('background_shop');
|
||||||
expect(shop.sets).to.be.an('array');
|
expect(shop.sets).to.be.an('array');
|
||||||
|
|
||||||
const sets = shop.sets.map(set => set.identifier);
|
|
||||||
expect(sets).to.include('incentiveBackgrounds');
|
|
||||||
expect(sets).to.include('backgrounds062014');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,9 +5,15 @@ import {
|
|||||||
|
|
||||||
describe('GET /shops/time-travelers', () => {
|
describe('GET /shops/time-travelers', () => {
|
||||||
let user;
|
let user;
|
||||||
|
let clock;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
user = await generateUser();
|
user = await generateUser();
|
||||||
|
clock = sinon.useFakeTimers(new Date('2024-06-08'));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
clock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a valid shop object', async () => {
|
it('returns a valid shop object', async () => {
|
||||||
|
|||||||
@@ -92,6 +92,24 @@ describe('shared.ops.purchase', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns error when gear is not available', async () => {
|
||||||
|
try {
|
||||||
|
await purchase(user, { params: { type: 'gear', key: 'shield_special_spring2019Healer' } });
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||||
|
expect(err.message).to.equal(i18n.t('messageNotAvailable'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns error when gear is not gem purchasable', async () => {
|
||||||
|
try {
|
||||||
|
await purchase(user, { params: { type: 'gear', key: 'shield_healer_3' } });
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||||
|
expect(err.message).to.equal(i18n.t('messageNotAvailable'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('returns error when item is not found', async () => {
|
it('returns error when item is not found', async () => {
|
||||||
const params = { key: 'notExisting', type: 'food' };
|
const params = { key: 'notExisting', type: 'food' };
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ import updateTask from './ops/updateTask';
|
|||||||
import * as statHelpers from './statHelpers';
|
import * as statHelpers from './statHelpers';
|
||||||
import { unEquipByType } from './ops/unequip';
|
import { unEquipByType } from './ops/unequip';
|
||||||
import getOfficialPinnedItems from './libs/getOfficialPinnedItems';
|
import getOfficialPinnedItems from './libs/getOfficialPinnedItems';
|
||||||
|
import cleanupPinnedItems from './libs/cleanupPinnedItems';
|
||||||
import { sleepAsync } from './libs/sleepAsync';
|
import { sleepAsync } from './libs/sleepAsync';
|
||||||
|
|
||||||
const api = {
|
const api = {
|
||||||
@@ -164,6 +165,7 @@ api.onboarding = onboarding;
|
|||||||
api.setDebuffPotionItems = setDebuffPotionItems;
|
api.setDebuffPotionItems = setDebuffPotionItems;
|
||||||
api.getDebuffPotionItems = getDebuffPotionItems;
|
api.getDebuffPotionItems = getDebuffPotionItems;
|
||||||
api.getOfficialPinnedItems = getOfficialPinnedItems;
|
api.getOfficialPinnedItems = getOfficialPinnedItems;
|
||||||
|
api.cleanupPinnedItems = cleanupPinnedItems;
|
||||||
api.sleepAsync = sleepAsync;
|
api.sleepAsync = sleepAsync;
|
||||||
|
|
||||||
api.fns = {
|
api.fns = {
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export default async function purchase (user, req = {}, analytics) {
|
|||||||
if (!matchers.match(item.key)) {
|
if (!matchers.match(item.key)) {
|
||||||
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
||||||
}
|
}
|
||||||
} else if (item.end && item.event.gear) {
|
} else if (item.klass === 'special') {
|
||||||
const matchers = getScheduleMatchingGroup('seasonalGear');
|
const matchers = getScheduleMatchingGroup('seasonalGear');
|
||||||
if (!matchers.match(item.set)) {
|
if (!matchers.match(item.set)) {
|
||||||
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
||||||
@@ -112,7 +112,7 @@ export default async function purchase (user, req = {}, analytics) {
|
|||||||
if (!matchers.match(item.key)) {
|
if (!matchers.match(item.key)) {
|
||||||
throw new NotAuthorized(i18n.t('notAvailable', { key: item.key }));
|
throw new NotAuthorized(i18n.t('notAvailable', { key: item.key }));
|
||||||
}
|
}
|
||||||
} else if (!item.canBuy(user)) {
|
} else if (!item.canBuy || !item.canBuy(user)) {
|
||||||
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import common from '../../common';
|
|||||||
import { preenUserHistory } from './preening';
|
import { preenUserHistory } from './preening';
|
||||||
import { sleep } from './sleep';
|
import { sleep } from './sleep';
|
||||||
import { revealMysteryItems } from './payments/subscriptions';
|
import { revealMysteryItems } from './payments/subscriptions';
|
||||||
import cleanupPinnedItems from '../../common/script/libs/cleanupPinnedItems';
|
|
||||||
|
|
||||||
const CRON_SAFE_MODE = nconf.get('CRON_SAFE_MODE') === 'true';
|
const CRON_SAFE_MODE = nconf.get('CRON_SAFE_MODE') === 'true';
|
||||||
const CRON_SEMI_SAFE_MODE = nconf.get('CRON_SEMI_SAFE_MODE') === 'true';
|
const CRON_SEMI_SAFE_MODE = nconf.get('CRON_SEMI_SAFE_MODE') === 'true';
|
||||||
@@ -501,7 +500,7 @@ export async function cron (options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user.pinnedItems && user.pinnedItems.length > 0) {
|
if (user.pinnedItems && user.pinnedItems.length > 0) {
|
||||||
user.pinnedItems = cleanupPinnedItems(user);
|
user.pinnedItems = common.cleanupPinnedItems(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send notification for changes in HP and MP.
|
// Send notification for changes in HP and MP.
|
||||||
|
|||||||
Reference in New Issue
Block a user