fix tests

This commit is contained in:
Phillip Thelen
2024-04-26 13:44:51 +02:00
parent 99a7b90247
commit d6cabeedb4
7 changed files with 32 additions and 15 deletions

View File

@@ -20,15 +20,11 @@ describe('GET /debug/time-travel-time', () => {
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);
const regularUser = await generateUser();
await expect(regularUser.get('/debug/time-travel-time'))
.eventually.be.rejected.and.to.deep.equal({
code: 400,
error: 'BadRequest',
message: 'You do not have permission to time travel.',
});
const result = await regularUser.get('/debug/time-travel-time');
expect(result.time).to.exist;
});
it('returns error when not in time travel mode', async () => {

View File

@@ -17,9 +17,5 @@ describe('GET /shops/backgrounds', () => {
expect(shop.notes).to.eql(t('backgroundShop'));
expect(shop.imageName).to.equal('background_shop');
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');
});
});

View File

@@ -5,9 +5,15 @@ import {
describe('GET /shops/time-travelers', () => {
let user;
let clock;
beforeEach(async () => {
user = await generateUser();
clock = sinon.useFakeTimers(new Date('2024-06-08'));
});
afterEach(() => {
clock.restore();
});
it('returns a valid shop object', async () => {

View File

@@ -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 () => {
const params = { key: 'notExisting', type: 'food' };

View File

@@ -96,6 +96,7 @@ import updateTask from './ops/updateTask';
import * as statHelpers from './statHelpers';
import { unEquipByType } from './ops/unequip';
import getOfficialPinnedItems from './libs/getOfficialPinnedItems';
import cleanupPinnedItems from './libs/cleanupPinnedItems';
import { sleepAsync } from './libs/sleepAsync';
const api = {
@@ -164,6 +165,7 @@ api.onboarding = onboarding;
api.setDebuffPotionItems = setDebuffPotionItems;
api.getDebuffPotionItems = getDebuffPotionItems;
api.getOfficialPinnedItems = getOfficialPinnedItems;
api.cleanupPinnedItems = cleanupPinnedItems;
api.sleepAsync = sleepAsync;
api.fns = {

View File

@@ -102,7 +102,7 @@ export default async function purchase (user, req = {}, analytics) {
if (!matchers.match(item.key)) {
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
}
} else if (item.end && item.event.gear) {
} else if (item.klass === 'special') {
const matchers = getScheduleMatchingGroup('seasonalGear');
if (!matchers.match(item.set)) {
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)) {
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));
}

View File

@@ -7,7 +7,6 @@ import common from '../../common';
import { preenUserHistory } from './preening';
import { sleep } from './sleep';
import { revealMysteryItems } from './payments/subscriptions';
import cleanupPinnedItems from '../../common/script/libs/cleanupPinnedItems';
const CRON_SAFE_MODE = nconf.get('CRON_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) {
user.pinnedItems = cleanupPinnedItems(user);
user.pinnedItems = common.cleanupPinnedItems(user);
}
// Send notification for changes in HP and MP.